Skip to content

Commit 75fc114

Browse files
Linus WallgrenLinus Wallgren
Linus Wallgren
authored and
Linus Wallgren
committed
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 a68733f commit 75fc114

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Diff for: cmd/client/main.go

+1-1
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")

Diff for: cmd/proxy/coordinator.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"github.com/go-kit/kit/log"
2626
"github.com/go-kit/kit/log/level"
2727
"github.com/google/uuid"
28+
"github.com/prometheus-community/pushprox/util"
2829
"github.com/prometheus/client_golang/prometheus"
2930
"github.com/prometheus/client_golang/prometheus/promauto"
30-
"github.com/prometheus-community/pushprox/util"
3131
)
3232

3333
var (
@@ -114,6 +114,8 @@ func (c *Coordinator) DoScrape(ctx context.Context, r *http.Request) (*http.Resp
114114
return nil, err
115115
}
116116
level.Info(c.logger).Log("msg", "DoScrape", "scrape_id", id, "url", r.URL.String())
117+
// It is important this id is cryptographically generated as it is relied
118+
// upon to match the request and the response.
117119
r.Header.Add("Id", id)
118120
select {
119121
case <-ctx.Done():

Diff for: cmd/proxy/main.go

+12-1
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)