Skip to content

Commit c6634f5

Browse files
SuperQhzeller
authored andcommitted
Fix http API metric observation (#47)
Wrap defer in anonymous func to avoid evaluating time.Since() early.
1 parent 32e60e9 commit c6634f5

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

software/earl/http-api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ func (event *JsonAppEvent) writeJSONEvent(out http.ResponseWriter, jsonp_callbac
133133

134134
func (a *ApiServer) ServeHTTP(out http.ResponseWriter, req *http.Request) {
135135
begin := time.Now()
136-
defer httpRequestDurationSeconds.With(prometheus.Labels{"method": req.Method}).Observe(time.Since(begin).Seconds())
136+
defer func() {
137+
httpRequestDurationSeconds.With(prometheus.Labels{"method": req.Method}).Observe(time.Since(begin).Seconds())
138+
}()
137139

138140
if req.Method != "GET" && req.Method != "POST" {
139141
out.WriteHeader(http.StatusMethodNotAllowed)

0 commit comments

Comments
 (0)