From 4682355eed1331bf30ccf2c56daf309e21943685 Mon Sep 17 00:00:00 2001 From: Pavel Aseev Date: Wed, 24 Apr 2024 10:23:24 +0200 Subject: [PATCH] chore: deprecate gauge metrics with _total suffix (#12744) (#12976) * chore: deprecate gauge metrics with _total suffix (#12744) Deprecated metrics: - coderd_oauth2_external_requests_rate_limit_total - coderd_api_workspace_latest_build_total * Apply suggestions from code review add link to follow-up issue Co-authored-by: Cian Johnston --------- Co-authored-by: Cian Johnston --- coderd/prometheusmetrics/prometheusmetrics.go | 17 ++++++++++++- .../prometheusmetrics_test.go | 2 +- coderd/promoauth/oauth2.go | 24 +++++++++++++++---- docs/admin/prometheus.md | 6 +++-- scripts/metricsdocgen/metrics | 11 +++++++-- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/coderd/prometheusmetrics/prometheusmetrics.go b/coderd/prometheusmetrics/prometheusmetrics.go index 4d3f1d1a04..fcc6958f39 100644 --- a/coderd/prometheusmetrics/prometheusmetrics.go +++ b/coderd/prometheusmetrics/prometheusmetrics.go @@ -79,10 +79,23 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R duration = defaultRefreshRate } - workspaceLatestBuildTotals := prometheus.NewGaugeVec(prometheus.GaugeOpts{ + // TODO: deprecated: remove in the future + // See: https://github.com/coder/coder/issues/12999 + // Deprecation reason: gauge metrics should avoid suffix `_total`` + workspaceLatestBuildTotalsDeprecated := prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: "coderd", Subsystem: "api", Name: "workspace_latest_build_total", + Help: "DEPRECATED: use coderd_api_workspace_latest_build instead", + }, []string{"status"}) + if err := registerer.Register(workspaceLatestBuildTotalsDeprecated); err != nil { + return nil, err + } + + workspaceLatestBuildTotals := prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "coderd", + Subsystem: "api", + Name: "workspace_latest_build", Help: "The current number of workspace builds by status.", }, []string{"status"}) if err := registerer.Register(workspaceLatestBuildTotals); err != nil { @@ -131,6 +144,8 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R for _, job := range jobs { status := codersdk.ProvisionerJobStatus(job.JobStatus) workspaceLatestBuildTotals.WithLabelValues(string(status)).Add(1) + // TODO: deprecated: remove in the future + workspaceLatestBuildTotalsDeprecated.WithLabelValues(string(status)).Add(1) } } diff --git a/coderd/prometheusmetrics/prometheusmetrics_test.go b/coderd/prometheusmetrics/prometheusmetrics_test.go index 2322982a65..ddb599abef 100644 --- a/coderd/prometheusmetrics/prometheusmetrics_test.go +++ b/coderd/prometheusmetrics/prometheusmetrics_test.go @@ -159,7 +159,7 @@ func TestWorkspaceLatestBuildTotals(t *testing.T) { assert.NoError(t, err) sum := 0 for _, m := range metrics { - if m.GetName() != "coderd_api_workspace_latest_build_total" { + if m.GetName() != "coderd_api_workspace_latest_build" { continue } diff --git a/coderd/promoauth/oauth2.go b/coderd/promoauth/oauth2.go index b3d4d6df30..18813bbbc6 100644 --- a/coderd/promoauth/oauth2.go +++ b/coderd/promoauth/oauth2.go @@ -62,9 +62,11 @@ type metrics struct { // if the oauth supports it, rate limit metrics. // rateLimit is the defined limit per interval - rateLimit *prometheus.GaugeVec - rateLimitRemaining *prometheus.GaugeVec - rateLimitUsed *prometheus.GaugeVec + rateLimit *prometheus.GaugeVec + // TODO: remove deprecated metrics in the future release + rateLimitDeprecated *prometheus.GaugeVec + rateLimitRemaining *prometheus.GaugeVec + rateLimitUsed *prometheus.GaugeVec // rateLimitReset is unix time of the next interval (when the rate limit resets). rateLimitReset *prometheus.GaugeVec // rateLimitResetIn is the time in seconds until the rate limit resets. @@ -91,7 +93,7 @@ func NewFactory(registry prometheus.Registerer) *Factory { rateLimit: factory.NewGaugeVec(prometheus.GaugeOpts{ Namespace: "coderd", Subsystem: "oauth2", - Name: "external_requests_rate_limit_total", + Name: "external_requests_rate_limit", Help: "The total number of allowed requests per interval.", }, []string{ "name", @@ -99,6 +101,18 @@ func NewFactory(registry prometheus.Registerer) *Factory { // Some IDPs have different buckets for different rate limits. "resource", }), + // TODO: deprecated: remove in the future + // See: https://github.com/coder/coder/issues/12999 + // Deprecation reason: gauge metrics should avoid suffix `_total`` + rateLimitDeprecated: factory.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "coderd", + Subsystem: "oauth2", + Name: "external_requests_rate_limit_total", + Help: "DEPRECATED: use coderd_oauth2_external_requests_rate_limit instead", + }, []string{ + "name", + "resource", + }), rateLimitRemaining: factory.NewGaugeVec(prometheus.GaugeOpts{ Namespace: "coderd", Subsystem: "oauth2", @@ -176,6 +190,8 @@ func (f *Factory) NewGithub(name string, under OAuth2Config) *Config { } } + // TODO: remove this metric in v3 + f.metrics.rateLimitDeprecated.With(labels).Set(float64(limits.Limit)) f.metrics.rateLimit.With(labels).Set(float64(limits.Limit)) f.metrics.rateLimitRemaining.With(labels).Set(float64(limits.Remaining)) f.metrics.rateLimitUsed.With(labels).Set(float64(limits.Used)) diff --git a/docs/admin/prometheus.md b/docs/admin/prometheus.md index 3f525a2e7d..99d36b5b15 100644 --- a/docs/admin/prometheus.md +++ b/docs/admin/prometheus.md @@ -120,7 +120,8 @@ spec: | `coderd_api_request_latencies_seconds` | histogram | Latency distribution of requests in seconds. | `method` `path` | | `coderd_api_requests_processed_total` | counter | The total number of processed API requests | `code` `method` `path` | | `coderd_api_websocket_durations_seconds` | histogram | Websocket duration distribution of requests in seconds. | `path` | -| `coderd_api_workspace_latest_build_total` | gauge | The latest workspace builds with a status. | `status` | +| `coderd_api_workspace_latest_build` | gauge | The latest workspace builds with a status. | `status` | +| `coderd_api_workspace_latest_build_total` | gauge | DEPRECATED: use coderd_api_workspace_latest_build instead | `status` | | `coderd_insights_applications_usage_seconds` | gauge | The application usage per template. | `application_name` `slug` `template_name` | | `coderd_insights_parameters` | gauge | The parameter usage per template. | `parameter_name` `parameter_type` `parameter_value` `template_name` | | `coderd_insights_templates_active_users` | gauge | The number of active users of the template. | `template_name` | @@ -128,10 +129,11 @@ spec: | `coderd_license_limit_users` | gauge | The user seats limit based on the active Coder license. | | | `coderd_license_user_limit_enabled` | gauge | Returns 1 if the current license enforces the user limit. | | | `coderd_metrics_collector_agents_execution_seconds` | histogram | Histogram for duration of agents metrics collection in seconds. | | +| `coderd_oauth2_external_requests_rate_limit` | gauge | The total number of allowed requests per interval. | `name` `resource` | | `coderd_oauth2_external_requests_rate_limit_next_reset_unix` | gauge | Unix timestamp of the next interval | `name` `resource` | | `coderd_oauth2_external_requests_rate_limit_remaining` | gauge | The remaining number of allowed requests in this interval. | `name` `resource` | | `coderd_oauth2_external_requests_rate_limit_reset_in_seconds` | gauge | Seconds until the next interval | `name` `resource` | -| `coderd_oauth2_external_requests_rate_limit_total` | gauge | The total number of allowed requests per interval. | `name` `resource` | +| `coderd_oauth2_external_requests_rate_limit_total` | gauge | DEPRECATED: use coderd_oauth2_external_requests_rate_limit instead | `name` `resource` | | `coderd_oauth2_external_requests_rate_limit_used` | gauge | The number of requests made in this interval. | `name` `resource` | | `coderd_oauth2_external_requests_total` | counter | The total number of api calls made to external oauth2 providers. 'status_code' will be 0 if the request failed with no response. | `name` `source` `status_code` | | `coderd_provisionerd_job_timings_seconds` | histogram | The provisioner job time duration in seconds. | `provisioner` `status` | diff --git a/scripts/metricsdocgen/metrics b/scripts/metricsdocgen/metrics index f51b0b1856..fda7cebd19 100644 --- a/scripts/metricsdocgen/metrics +++ b/scripts/metricsdocgen/metrics @@ -10,7 +10,11 @@ coderd_oauth2_external_requests_rate_limit_remaining{name="secondary-github",res # TYPE coderd_oauth2_external_requests_rate_limit_reset_in_seconds gauge coderd_oauth2_external_requests_rate_limit_reset_in_seconds{name="primary-github",resource="core"} 63.617162731 coderd_oauth2_external_requests_rate_limit_reset_in_seconds{name="secondary-github",resource="core"} 121.82186601 -# HELP coderd_oauth2_external_requests_rate_limit_total The total number of allowed requests per interval. +# HELP coderd_oauth2_external_requests_rate_limit The total number of allowed requests per interval. +# TYPE coderd_oauth2_external_requests_rate_limit gauge +coderd_oauth2_external_requests_rate_limit{name="primary-github",resource="core-unauthorized"} 5000 +coderd_oauth2_external_requests_rate_limit{name="secondary-github",resource="core-unauthorized"} 5000 +# HELP coderd_oauth2_external_requests_rate_limit_total DEPRECATED: use coderd_oauth2_external_requests_rate_limit instead # TYPE coderd_oauth2_external_requests_rate_limit_total gauge coderd_oauth2_external_requests_rate_limit_total{name="primary-github",resource="core-unauthorized"} 5000 coderd_oauth2_external_requests_rate_limit_total{name="secondary-github",resource="core-unauthorized"} 5000 @@ -644,7 +648,10 @@ coderd_api_requests_processed_total{code="401",method="GET",path="/api/v2/users/ coderd_api_requests_processed_total{code="401",method="GET",path="/api/v2/users/{user}/*"} 2 coderd_api_requests_processed_total{code="401",method="GET",path="/api/v2/workspaces"} 1 coderd_api_requests_processed_total{code="401",method="POST",path="/api/v2/files"} 1 -# HELP coderd_api_workspace_latest_build_total The latest workspace builds with a status. +# HELP coderd_api_workspace_latest_build The latest workspace builds with a status. +# TYPE coderd_api_workspace_latest_build gauge +coderd_api_workspace_latest_build{status="succeeded"} 1 +# HELP coderd_api_workspace_latest_build_total DEPRECATED: use coderd_api_workspace_latest_build instead # TYPE coderd_api_workspace_latest_build_total gauge coderd_api_workspace_latest_build_total{status="succeeded"} 1 # HELP coderd_insights_applications_usage_seconds The application usage per template.