Skip to content

Commit

Permalink
remove apdex target gauge, increase histogram buckets
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
  • Loading branch information
everettraven committed Sep 5, 2023
1 parent d9a2903 commit dbb9540
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func main() {
}

if features.CatalogdFeatureGate.Enabled(features.HTTPServer) {
metrics.Registry.MustRegister(server.ApdexTargetMetric, server.RequestDurationMetric)
metrics.Registry.MustRegister(server.RequestDurationMetric)
srv := server.Instance{StorageDir: storageDir}
mgr.AddMetricsExtraHandler("/catalogs/", server.AddMetricsToHandler(srv.CatalogServerHandler()))

Check failure on line 131 in cmd/manager/main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `mgr.AddMetricsExtraHandler` is not checked (errcheck)
}
Expand Down
30 changes: 11 additions & 19 deletions pkg/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,33 @@ import (
)

const (
// target response time in seconds
ApdexTarget = 0.5

ApdexTargetMetricName = "catalogd_http_request_apdex_target_seconds"
RequestDurationMetricName = "catalogd_http_request_duration_seconds"
)

// Sets up the necessary metrics for calculating the Apdex Score
// If using Grafana for visualization connected to a Prometheus data
// source that is scraping these metrics, you can create a panel that
// uses the following queries + expressions for calculating the Apdex Score:
// uses the following queries + expressions for calculating the Apdex Score where T = 0.5:
// Query A: sum(catalogd_http_request_duration_seconds_bucket{code!~"5..",le="0.5"})
// Query B: (sum(catalogd_http_request_duration_seconds_bucket{code!~"5..",le="2"}) - on(code) sum(catalogd_http_request_duration_seconds_bucket{code!~"5..",le="0.5"}))
// Query B: sum(catalogd_http_request_duration_seconds_bucket{code!~"5..",le="2"})
// Query C: sum(catalogd_http_request_duration_seconds_count)
// Expression for Apdex Score: ($A - ($B / 2) / $C
// Expression for Apdex Score: ($A + (($B - $A) / 2)) / $C
var (
ApdexTargetMetric = prometheus.NewGauge(prometheus.GaugeOpts{
Name: ApdexTargetMetricName,
Help: "The apdex target in seconds",
})

RequestDurationMetric = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: RequestDurationMetricName,
Help: "Histogram of request duration in seconds",
Buckets: []float64{ApdexTarget, ApdexTarget * 4, ApdexTarget * 8},
Name: RequestDurationMetricName,
Help: "Histogram of request duration in seconds",
// create a bucket for each 100 ms up to 1s and ensure it multiplied by 4 also exists.
// Include a 10s bucket to capture very long running requests. This allows us to easily
// calculate Apdex Scores up to a T of 1 second, but using various mathmatical formulas we
// should be able to estimate Apdex Scores up to a T of 2.5. Having a larger range of buckets
// will allow us to more easily calculate health indicators other than the Apdex Score.
Buckets: []float64{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.2, 1.6, 2, 2.4, 2.8, 3.2, 3.6, 4, 10},
},
[]string{"code"},
)
)

func init() {
ApdexTargetMetric.Set(ApdexTarget)
}

func AddMetricsToHandler(handler http.Handler) http.Handler {
return promhttp.InstrumentHandlerDuration(RequestDurationMetric, handler)
}

0 comments on commit dbb9540

Please sign in to comment.