Skip to content

Commit 2ada6ff

Browse files
Linus WallgrenLinus Wallgren
authored andcommitted
Register with FQDN in URL
This replaces having the FQDN in the body in order to make client certificate validation easier. The proxy will continue to work with older clients as we still keep the old endpoint. However any calls to `/poll/*` will use the FQDN provided in the URL for registration. Signed-off-by: Linus Wallgren <[email protected]>
1 parent 753361c commit 2ada6ff

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cmd/client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func loop(c Coordinator, client *http.Client) error {
174174
level.Error(c.logger).Log("msg", "Error parsing url:", "err", err)
175175
return errors.Wrap(err, "error parsing url")
176176
}
177-
u, err := url.Parse("poll")
177+
u, err := url.Parse("poll/" + *myFqdn)
178178
if err != nil {
179179
level.Error(c.logger).Log("msg", "Error parsing url:", "err", err)
180180
return errors.Wrap(err, "error parsing url poll")

cmd/proxy/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func newHTTPHandler(logger log.Logger, coordinator *Coordinator, mux *http.Serve
9999
handlers := map[string]http.HandlerFunc{
100100
"/push": h.handlePush,
101101
"/poll": h.handlePoll,
102+
"/poll/": h.handlePollWithPath,
102103
"/clients": h.handleListClients,
103104
"/metrics": promhttp.Handler().ServeHTTP,
104105
}
@@ -144,7 +145,17 @@ func (h *httpHandler) handlePush(w http.ResponseWriter, r *http.Request) {
144145
// handlePoll handles clients registering and asking for scrapes.
145146
func (h *httpHandler) handlePoll(w http.ResponseWriter, r *http.Request) {
146147
fqdn, _ := ioutil.ReadAll(r.Body)
147-
request, err := h.coordinator.WaitForScrapeInstruction(strings.TrimSpace(string(fqdn)))
148+
h.pollWithFQDN(string(fqdn), w)
149+
}
150+
151+
// handlePoll handles clients registering and asking for scrapes.
152+
func (h *httpHandler) handlePollWithPath(w http.ResponseWriter, r *http.Request) {
153+
fqdn := r.URL.Path[len("/poll/"):]
154+
h.pollWithFQDN(fqdn, w)
155+
}
156+
157+
func (h *httpHandler) pollWithFQDN(fqdn string, w http.ResponseWriter) {
158+
request, err := h.coordinator.WaitForScrapeInstruction(strings.TrimSpace(fqdn))
148159
if err != nil {
149160
level.Info(h.logger).Log("msg", "Error WaitForScrapeInstruction:", "err", err)
150161
http.Error(w, fmt.Sprintf("Error WaitForScrapeInstruction: %s", err.Error()), 408)

0 commit comments

Comments
 (0)