Skip to content

Commit 207e9bd

Browse files
authored
Restore legacy dapr_http_server_response_count HTTP metric (dapr#7656)
The legacy `dapr_http_server_response_count` metric had been removed from being served. This metric was relied upon by users. Adds metric back to be served when in legacy metric mode. Should be backported and patch released in 1.13. Signed-off-by: joshvanl <[email protected]>
1 parent 1281e02 commit 207e9bd

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

pkg/diagnostics/http_monitoring.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type httpMetrics struct {
4949
serverResponseBytes *stats.Int64Measure
5050
serverLatency *stats.Float64Measure
5151
serverRequestCount *stats.Int64Measure
52+
serverResponseCount *stats.Int64Measure
5253

5354
clientSentBytes *stats.Int64Measure
5455
clientReceivedBytes *stats.Int64Measure
@@ -83,6 +84,10 @@ func newHTTPMetrics() *httpMetrics {
8384
"http/server/request_count",
8485
"Count of HTTP requests processed by the server.",
8586
stats.UnitDimensionless),
87+
serverResponseCount: stats.Int64(
88+
"http/server/response_count",
89+
"The number of HTTP responses",
90+
stats.UnitDimensionless),
8691
clientSentBytes: stats.Int64(
8792
"http/client/sent_bytes",
8893
"Total bytes sent in request body (not including headers)",
@@ -130,6 +135,10 @@ func (h *httpMetrics) ServerRequestCompleted(ctx context.Context, method, path,
130135
ctx,
131136
diagUtils.WithTags(h.serverLatency.Name(), appIDKey, h.appID, httpMethodKey, method, httpPathKey, path, httpStatusCodeKey, status),
132137
h.serverLatency.M(elapsed))
138+
stats.RecordWithTags(
139+
ctx,
140+
diagUtils.WithTags(h.serverResponseCount.Name(), appIDKey, h.appID, httpPathKey, path, httpMethodKey, method, httpStatusCodeKey, status),
141+
h.serverResponseCount.M(1))
133142
} else {
134143
stats.RecordWithTags(
135144
ctx,
@@ -234,7 +243,8 @@ func (h *httpMetrics) Init(appID string, legacy bool) error {
234243
serverTags = []tag.Key{appIDKey, httpMethodKey, httpStatusCodeKey}
235244
clientTags = []tag.Key{appIDKey, httpStatusCodeKey}
236245
}
237-
return view.Register(
246+
247+
views := []*view.View{
238248
diagUtils.NewMeasureView(h.serverRequestBytes, tags, defaultSizeDistribution),
239249
diagUtils.NewMeasureView(h.serverResponseBytes, tags, defaultSizeDistribution),
240250
diagUtils.NewMeasureView(h.serverLatency, serverTags, defaultLatencyDistribution),
@@ -245,7 +255,13 @@ func (h *httpMetrics) Init(appID string, legacy bool) error {
245255
diagUtils.NewMeasureView(h.clientCompletedCount, clientTags, view.Count()),
246256
diagUtils.NewMeasureView(h.healthProbeRoundripLatency, []tag.Key{appIDKey, httpStatusCodeKey}, defaultLatencyDistribution),
247257
diagUtils.NewMeasureView(h.healthProbeCompletedCount, []tag.Key{appIDKey, httpStatusCodeKey}, view.Count()),
248-
)
258+
}
259+
260+
if h.legacy {
261+
views = append(views, diagUtils.NewMeasureView(h.serverResponseCount, serverTags, view.Count()))
262+
}
263+
264+
return view.Register(views...)
249265
}
250266

251267
// HTTPMiddleware is the middleware to track HTTP server-side requests.

tests/integration/suite/daprd/metrics/http/cardinality/high.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ func (h *high) Run(t *testing.T, ctx context.Context) {
7373
h.daprd.HTTPGet2xx(t, ctx, "/v1.0/invoke/myapp/method/hi")
7474
metrics := h.daprd.Metrics(t, ctx)
7575
assert.Equal(t, 1, int(metrics["dapr_http_server_request_count|app_id:myapp|method:GET|path:/v1.0/invoke/myapp/method/hi|status:200"]))
76+
assert.Equal(t, 1, int(metrics["dapr_http_server_response_count|app_id:myapp|method:GET|path:/v1.0/healthz|status:204"]))
77+
assert.Equal(t, 1, int(metrics["dapr_http_server_response_count|app_id:myapp|method:GET|path:/v1.0/invoke/myapp/method/hi|status:200"]))
7678
})
7779

7880
t.Run("state stores", func(t *testing.T) {

tests/integration/suite/daprd/metrics/http/cardinality/low.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ func (l *low) Run(t *testing.T, ctx context.Context) {
7373
l.daprd.HTTPGet2xx(t, ctx, "/v1.0/invoke/myapp/method/hi")
7474
metrics := l.daprd.Metrics(t, ctx)
7575
assert.Equal(t, 1, int(metrics["dapr_http_server_request_count|app_id:myapp|method:InvokeService/myapp|status:200"]))
76+
assert.NotContains(t, metrics, "dapr_http_server_response_count|app_id:myapp|method:GET|path:/v1.0/invoke/myapp/method/hi|status:200")
77+
assert.NotContains(t, metrics, "dapr_http_server_response_count|app_id:myapp|method:GET|path:/v1.0/healthz|status:204 1.000000")
7678
})
7779

7880
t.Run("state stores", func(t *testing.T) {

0 commit comments

Comments
 (0)