Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: use -server.path-prefix for metrics and debug endpoints #150

Merged
merged 1 commit into from
Apr 3, 2019
Merged

server: use -server.path-prefix for metrics and debug endpoints #150

merged 1 commit into from
Apr 3, 2019

Conversation

adamdecaf
Copy link
Contributor

@adamdecaf adamdecaf commented Feb 25, 2019

Previously calling Subrouter() would overwrite the instrumentation handlers and they'd be ignored when PathPrefix was specified. This meant one could never get back metrics or debug endpoints.

I verified metrics and api endpoints respond with this change locally, but writing a test didn't work as creating a new Server (via New(..)) mutates global state and prometheus panics on duplicate metric registrations. We could pass in a prometheus registry, but that breaks the public constructor.

func TestInstrumentationPathPrefix(t *testing.T) {
	var cfg Config
	cfg.PathPrefix = "/loki/"
	cfg.HTTPListenPort = 10101
	cfg.RegisterInstrumentation = true
	server, err := New(cfg)
	require.NoError(t, err)

	go server.Run()
	defer server.Shutdown()

	resp, err := http.DefaultClient.Get("http://localhost:10101/loki/metrics")
	if resp != nil && resp.Body != nil {
		resp.Body.Close()
	}
	require.NoError(t, err)
	if resp.StatusCode != http.StatusOK {
		t.Errorf("bogus HTTP status: %v", resp.Status)
	}
}

Related: #144

Previously calling .Subrouter() would overwrite the instrumentation
handlers and they'd be ignored when PathPrefix was specified. This
meant one could never get back metrics or debug endpoints.
@adamdecaf
Copy link
Contributor Author

adamdecaf commented Feb 25, 2019

This does break the idea that /metrics always responds as it's /${prefix}/metrics now.

Copy link
Collaborator

@bboreham bboreham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit.

@bboreham bboreham merged commit 51eb0fb into weaveworks:master Apr 3, 2019
@adamdecaf adamdecaf deleted the path-prefix-for-metrics branch April 3, 2019 16:29
adamdecaf added a commit to moov-io/infra that referenced this pull request May 1, 2019
yeya24 pushed a commit to yeya24/common that referenced this pull request Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants