-
Notifications
You must be signed in to change notification settings - Fork 1.2k
✨Expose metrics http server for extra endpoints #824
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -412,7 +412,7 @@ var _ = Describe("manger.Manager", func() { | |
Expect(resp.StatusCode).To(Equal(200)) | ||
}) | ||
|
||
It("should not serve anything other than metrics endpoint", func(done Done) { | ||
It("should not serve anything other than metrics endpoint by default", func(done Done) { | ||
opts.MetricsBindAddress = ":0" | ||
m, err := New(cfg, opts) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
@@ -469,6 +469,40 @@ var _ = Describe("manger.Manager", func() { | |
ok := metrics.Registry.Unregister(one) | ||
Expect(ok).To(BeTrue()) | ||
}) | ||
|
||
It("should serve extra endpoints", func(done Done) { | ||
opts.MetricsBindAddress = ":0" | ||
m, err := New(cfg, opts) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = m.AddMetricsExtraHandler("/debug", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
_, _ = w.Write([]byte("Some debug info")) | ||
})) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Should error when we add another extra endpoint on the already registered path. | ||
err = m.AddMetricsExtraHandler("/debug", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
_, _ = w.Write([]byte("Another debug info")) | ||
})) | ||
Expect(err).To(HaveOccurred()) | ||
|
||
s := make(chan struct{}) | ||
defer close(s) | ||
go func() { | ||
defer GinkgoRecover() | ||
Expect(m.Start(s)).NotTo(HaveOccurred()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the start race with the the Get request we do later on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've done this in a similar way as in other tests where HTTP requests are involved. It seems to work, but I see no strong argument why this could not race potentially, maybe I'm missing something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm okay, interesting. Well, we can still look at it if we actually see it flake. |
||
close(done) | ||
}() | ||
|
||
endpoint := fmt.Sprintf("http://%s/debug", listener.Addr().String()) | ||
resp, err := http.Get(endpoint) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(body)).To(Equal("Some debug info")) | ||
}) | ||
}) | ||
}) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.