Skip to content

Commit

Permalink
#11 generate metric full name with prometheus.BuildFQName()
Browse files Browse the repository at this point in the history
  • Loading branch information
sevennt committed Oct 28, 2019
1 parent 989b455 commit 3257f60
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions prom_test.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ func TestInstrument(t *testing.T) {
g := gofight.New() g := gofight.New()
g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
assert.NotContains(t, r.Body.String(), fmt.Sprintf("%s_requests_total", p.Subsystem)) assert.NotContains(t, r.Body.String(), prometheus.BuildFQName(p.Namespace, p.Subsystem, "requests_total"))
assert.NotContains(t, r.Body.String(), lpath, "path must not be present in the response") assert.NotContains(t, r.Body.String(), lpath, "path must not be present in the response")
}) })


g.GET("/user/10").Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { assert.Equal(t, http.StatusOK, r.Code) }) g.GET("/user/10").Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { assert.Equal(t, http.StatusOK, r.Code) })


g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
assert.Contains(t, r.Body.String(), fmt.Sprintf("%s_requests_total", p.Subsystem)) assert.Contains(t, r.Body.String(), prometheus.BuildFQName(p.Namespace, p.Subsystem, "requests_total"))
assert.Contains(t, r.Body.String(), lpath, "path must be present in the response") assert.Contains(t, r.Body.String(), lpath, "path must be present in the response")
assert.NotContains(t, r.Body.String(), `path="/user/10"`, "raw path must not be present") assert.NotContains(t, r.Body.String(), `path="/user/10"`, "raw path must not be present")
}) })
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestThreadedInstrument(t *testing.T) {


g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
assert.Contains(t, r.Body.String(), fmt.Sprintf("%s_requests_total", p.Subsystem)) assert.Contains(t, r.Body.String(), prometheus.BuildFQName(p.Namespace, p.Subsystem, "requests_total"))
assert.Contains(t, r.Body.String(), lpath, "path must be present in the response") assert.Contains(t, r.Body.String(), lpath, "path must be present in the response")
assert.NotContains(t, r.Body.String(), `path="/user/10"`, "raw path must not be present") assert.NotContains(t, r.Body.String(), `path="/user/10"`, "raw path must not be present")
}) })
Expand Down Expand Up @@ -222,14 +222,14 @@ func TestIgnore(t *testing.T) {
g := gofight.New() g := gofight.New()
g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
assert.NotContains(t, r.Body.String(), fmt.Sprintf("%s_requests_total", p.Subsystem)) assert.NotContains(t, r.Body.String(), prometheus.BuildFQName(p.Namespace, p.Subsystem, "requests_total"))
}) })


g.GET("/ping").Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { assert.Equal(t, http.StatusOK, r.Code) }) g.GET("/ping").Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { assert.Equal(t, http.StatusOK, r.Code) })


g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
assert.NotContains(t, r.Body.String(), fmt.Sprintf("%s_requests_total", p.Subsystem)) assert.NotContains(t, r.Body.String(), prometheus.BuildFQName(p.Namespace, p.Subsystem, "requests_total"))
assert.NotContains(t, r.Body.String(), lipath, "ignored path must not be present") assert.NotContains(t, r.Body.String(), lipath, "ignored path must not be present")
}) })
unregister(p) unregister(p)
Expand All @@ -243,7 +243,7 @@ func TestMetricsPathIgnored(t *testing.T) {
g := gofight.New() g := gofight.New()
g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { g.GET(p.MetricsPath).Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
assert.NotContains(t, r.Body.String(), fmt.Sprintf("%s_requests_total", p.Subsystem)) assert.NotContains(t, r.Body.String(), prometheus.BuildFQName(p.Namespace, p.Subsystem, "requests_total"))
}) })
unregister(p) unregister(p)
} }
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestMetricsBearerToken(t *testing.T) {
}). }).
Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { Run(r, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
assert.NotContains(t, r.Body.String(), fmt.Sprintf("%s_requests_total", p.Subsystem)) assert.NotContains(t, r.Body.String(), prometheus.BuildFQName(p.Namespace, p.Subsystem, "requests_total"))
}) })
unregister(p) unregister(p)
} }

0 comments on commit 3257f60

Please sign in to comment.