Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
majewsky committed Jun 20, 2022
1 parent c5781e7 commit 20373a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion httpapi/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func Compose(apis ...API) http.Handler {
return h
}

const OOB_KEY = "gobits-httpapi-oob"
type oobKey string

const OOB_KEY oobKey = "gobits-httpapi-oob"

//An out-of-band message that can be sent from the middleware to the request
//through one of the functions below.
Expand Down
14 changes: 9 additions & 5 deletions httpapi/httpapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,23 @@ func promhttpNormalizer(inner http.Handler) http.Handler {
//does one very specific rewrite for test reproducability.
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
//slurp the response from `GET /metrics`
resp := httptest.NewRecorder()
inner.ServeHTTP(resp, r)
rec := httptest.NewRecorder()
inner.ServeHTTP(rec, r)
resp := rec.Result()

//remove the undeterministic values for the `..._seconds_sum` metrics
buf := resp.Body.Bytes()
buf, err := io.ReadAll(resp.Body)
if respondwith.ErrorText(w, err) {
return
}
rx := regexp.MustCompile(`(seconds_sum{[^{}]*}) \d*\.\d*(?m:$)`)
buf = rx.ReplaceAll(buf, []byte("$1 VARYING"))

//replay the edited response into the actual ResponseWriter
for k, v := range resp.HeaderMap {
for k, v := range resp.Header {
w.Header()[k] = v
}
w.WriteHeader(resp.Code)
w.WriteHeader(resp.StatusCode)
w.Write(buf) //nolint:errcheck
})
}

0 comments on commit 20373a5

Please sign in to comment.