Esempio n. 1
0
// newStatusServer allocates and returns a statusServer.
func newStatusServer(
	db *client.DB,
	gossip *gossip.Gossip,
	metricSource json.Marshaler,
	ctx *base.Context,
	rpcCtx *rpc.Context,
	stores *storage.Stores,
) *statusServer {
	// Create an http client with a timeout
	httpClient, err := ctx.GetHTTPClient()
	if err != nil {
		log.Error(err)
		return nil
	}

	server := &statusServer{
		db:           db,
		gossip:       gossip,
		metricSource: metricSource,
		router:       httprouter.New(),
		rpcCtx:       rpcCtx,
		proxyClient:  httpClient,
		stores:       stores,
	}

	server.router.GET(statusLogFilesListPattern, server.handleLogFilesList)
	server.router.GET(statusLogFilePattern, server.handleLogFile)
	server.router.GET(statusLogsPattern, server.handleLogs)
	// TODO(tschottdorf): significant overlap with /debug/pprof/goroutine,
	// except that this one allows querying by NodeID.
	server.router.GET(statusStacksPattern, server.handleStacks)
	server.router.GET(statusMetricsPattern, server.handleMetrics)

	return server
}
Esempio n. 2
0
func main() {
	flag.Parse()

	ctx := base.Context{Insecure: *insecure, Certs: *certs, User: *user}
	httpClient, err := ctx.GetHTTPClient()
	if err != nil {
		panic(err)
	}

	startTime := time.Now()
	file := filepath.Join(*outputDir, fmt.Sprintf("monitor.%s", strings.Replace(
		startTime.Format(time.RFC3339), ":", "_", -1)))
	log.Infof("Logging cluster status to: %s.\n", file)
	w, err := os.Create(file)
	if err != nil {
		panic(err)
	}
	defer w.Close()

	url := fmt.Sprintf("%s://%s/%s", ctx.HTTPRequestScheme(), *addr, *endpoint)
	log.Infof("Cluster Status URL: %s\n", url)

	for range time.Tick(*interval) {
		resp, found := request(url, httpClient)
		if !found {
			log.Warningf("Could not get cluster status. Time since monitor started %s.", time.Since(startTime))
			break
		}
		log.Infof("Got cluster status.")
		fmt.Fprintf(w, "%s\n", resp)
	}
}
Esempio n. 3
0
// makeTestHTTPSession constructs a new testHTTPSession. The session will
// instantiate a client using the based base context. All HTTP requests from the
// session will be sent to the given baseUrl.
//
// baseUrl should be specified *without* a request scheme (i.e. "http://"); the
// request scheme will be used from the context.
//
// If an error occurs in HTTP layer during any session operation, a Fatal method
// will be called on the supplied t.Tester.
func makeTestHTTPSession(t *testing.T, ctx *base.Context, baseURL string) testHTTPSession {
	client, err := ctx.GetHTTPClient()
	if err != nil {
		t.Fatalf("error creating client: %s", err)
	}
	return testHTTPSession{
		client:  client,
		baseURL: ctx.HTTPRequestScheme() + "://" + baseURL,
	}
}
Esempio n. 4
0
// NewTestHTTPSession constructs a new TestHTTPSession. The session will
// instantiate a client using the based base context. All HTTP requests from the
// session will be sent to the given baseUrl.
//
// baseUrl should be specified *without* a request scheme (i.e. "http://"); the
// request scheme will be used from the context.
//
// If an error occurs in HTTP layer during any session operation, a Fatal method
// will be called on the supplied t.Tester.
func NewTestHTTPSession(t util.Tester, ctx *base.Context, baseURL string) *TestHTTPSession {
	client, err := ctx.GetHTTPClient()
	if err != nil {
		t.Fatalf("error creating client: %s", err)
	}
	return &TestHTTPSession{
		t:       t,
		client:  client,
		baseURL: ctx.RequestScheme() + "://" + baseURL,
	}
}
Esempio n. 5
0
func newStatusMonitor(context *base.Context, addr string) (*statusMonitor, error) {
	monitor := &statusMonitor{
		addr: addr,
	}
	var err error
	monitor.httpClient, err = context.GetHTTPClient()
	if err != nil {
		return nil, err
	}
	monitor.url = fmt.Sprintf("%s://%s/%s", context.HTTPRequestScheme(), monitor.addr, urlPath)
	return monitor, nil
}
Esempio n. 6
0
// newHTTPSender returns a new instance of httpSender.
func newHTTPSender(server string, ctx *base.Context, retryOpts retry.Options) (*httpSender, error) {
	sender := &httpSender{
		server:    server,
		context:   ctx,
		retryOpts: retryOpts,
	}
	var err error
	sender.client, err = ctx.GetHTTPClient()
	if err != nil {
		return nil, err
	}
	return sender, nil
}
Esempio n. 7
0
// newHTTPSender returns a new instance of httpSender.
func newHTTPSender(server string, ctx *base.Context, retryOpts retry.Options) (*httpSender, error) {
	// Ensure that the context returns an HTTPClient.
	if _, err := ctx.GetHTTPClient(); err != nil {
		return nil, err
	}

	return &httpSender{
		ctx: client.PostContext{
			Server:    server,
			Endpoint:  Endpoint,
			Context:   ctx,
			RetryOpts: retryOpts,
		},
	}, nil
}