Skip to content

Commit

Permalink
feat(httpclient): Updated metrics base name (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekkinox authored Mar 15, 2024
1 parent 67034e5 commit 0b91487
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions httpclient/transport/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

const (
HttpClientMetricsRequestsCount = "httpclient_requests_total"
HttpClientMetricsRequestsDuration = "httpclient_requests_duration_seconds"
HttpClientMetricsRequestsCount = "http_client_requests_total"
HttpClientMetricsRequestsDuration = "http_client_requests_duration_seconds"
)

// MetricsTransport is a wrapper around [http.RoundTripper] with some [MetricsTransportConfig] configuration.
Expand Down
28 changes: 14 additions & 14 deletions httpclient/transport/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ func TestMetricsTransportRoundTrip(t *testing.T) {
// requests counter assertions
expectedCounterMetric := fmt.Sprintf(
`
# HELP httpclient_requests_total Number of performed HTTP requests
# TYPE httpclient_requests_total counter
httpclient_requests_total{host="%s",method="GET",path="",status="5xx"} 1
# HELP http_client_requests_total Number of performed HTTP requests
# TYPE http_client_requests_total counter
http_client_requests_total{host="%s",method="GET",path="",status="5xx"} 1
`,
server.URL,
)

err = testutil.GatherAndCompare(
prometheus.DefaultGatherer,
strings.NewReader(expectedCounterMetric),
"httpclient_requests_total",
"http_client_requests_total",
)
assert.NoError(t, err)
}
Expand Down Expand Up @@ -107,11 +107,11 @@ func TestMetricsTransportRoundTripWithBaseAndConfig(t *testing.T) {
// requests counter assertions
expectedCounterMetric := fmt.Sprintf(
`
# HELP foo_bar_httpclient_requests_total Number of performed HTTP requests
# TYPE foo_bar_httpclient_requests_total counter
foo_bar_httpclient_requests_total{host="%s",method="GET",path="",status="204"} 1
foo_bar_httpclient_requests_total{host="%s",method="GET",path="/foo/4/baz",status="204"} 1
foo_bar_httpclient_requests_total{host="%s",method="GET",path="/foo/{fooId}/bar?page={pageId}",status="204"} 3
# HELP foo_bar_http_client_requests_total Number of performed HTTP requests
# TYPE foo_bar_http_client_requests_total counter
foo_bar_http_client_requests_total{host="%s",method="GET",path="",status="204"} 1
foo_bar_http_client_requests_total{host="%s",method="GET",path="/foo/4/baz",status="204"} 1
foo_bar_http_client_requests_total{host="%s",method="GET",path="/foo/{fooId}/bar?page={pageId}",status="204"} 3
`,
server.URL,
server.URL,
Expand All @@ -121,7 +121,7 @@ func TestMetricsTransportRoundTripWithBaseAndConfig(t *testing.T) {
err := testutil.GatherAndCompare(
registry,
strings.NewReader(expectedCounterMetric),
"foo_bar_httpclient_requests_total",
"foo_bar_http_client_requests_total",
)
assert.NoError(t, err)
}
Expand Down Expand Up @@ -161,17 +161,17 @@ func TestMetricsTransportRoundTripWithFailure(t *testing.T) {
// requests counter assertions
expectedCounterMetric := fmt.Sprintf(
`
# HELP foo_bar_httpclient_requests_total Number of performed HTTP requests
# TYPE foo_bar_httpclient_requests_total counter
foo_bar_httpclient_requests_total{host="%s",method="GET",path="",status="error"} 1
# HELP foo_bar_http_client_requests_total Number of performed HTTP requests
# TYPE foo_bar_http_client_requests_total counter
foo_bar_http_client_requests_total{host="%s",method="GET",path="",status="error"} 1
`,
server.URL,
)

err = testutil.GatherAndCompare(
registry,
strings.NewReader(expectedCounterMetric),
"foo_bar_httpclient_requests_total",
"foo_bar_http_client_requests_total",
)
assert.NoError(t, err)
}

0 comments on commit 0b91487

Please sign in to comment.