Skip to content

Commit 98577e5

Browse files
committed
chore: deprecate gauge metrics with _total suffix (#12744)
Deprecated metrics: - coderd_oauth2_external_requests_rate_limit_total - coderd_api_workspace_latest_build_total
1 parent f96ce80 commit 98577e5

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

coderd/prometheusmetrics/prometheusmetrics.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,22 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
7979
duration = defaultRefreshRate
8080
}
8181

82-
workspaceLatestBuildTotals := prometheus.NewGaugeVec(prometheus.GaugeOpts{
82+
// TODO: deprecated: remove in the future
83+
// Deprecation reason: gauge metrics should avoid suffix `_total``
84+
workspaceLatestBuildTotalsDeprecated := prometheus.NewGaugeVec(prometheus.GaugeOpts{
8385
Namespace: "coderd",
8486
Subsystem: "api",
8587
Name: "workspace_latest_build_total",
88+
Help: "DEPRECATED: use coderd_api_workspace_latest_build instead",
89+
}, []string{"status"})
90+
if err := registerer.Register(workspaceLatestBuildTotalsDeprecated); err != nil {
91+
return nil, err
92+
}
93+
94+
workspaceLatestBuildTotals := prometheus.NewGaugeVec(prometheus.GaugeOpts{
95+
Namespace: "coderd",
96+
Subsystem: "api",
97+
Name: "workspace_latest_build",
8698
Help: "The current number of workspace builds by status.",
8799
}, []string{"status"})
88100
if err := registerer.Register(workspaceLatestBuildTotals); err != nil {
@@ -131,6 +143,8 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
131143
for _, job := range jobs {
132144
status := codersdk.ProvisionerJobStatus(job.JobStatus)
133145
workspaceLatestBuildTotals.WithLabelValues(string(status)).Add(1)
146+
// TODO: deprecated: remove in the future
147+
workspaceLatestBuildTotalsDeprecated.WithLabelValues(string(status)).Add(1)
134148
}
135149
}
136150

coderd/prometheusmetrics/prometheusmetrics_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestWorkspaceLatestBuildTotals(t *testing.T) {
159159
assert.NoError(t, err)
160160
sum := 0
161161
for _, m := range metrics {
162-
if m.GetName() != "coderd_api_workspace_latest_build_total" {
162+
if m.GetName() != "coderd_api_workspace_latest_build" {
163163
continue
164164
}
165165

coderd/promoauth/oauth2.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ type metrics struct {
6262

6363
// if the oauth supports it, rate limit metrics.
6464
// rateLimit is the defined limit per interval
65-
rateLimit *prometheus.GaugeVec
66-
rateLimitRemaining *prometheus.GaugeVec
67-
rateLimitUsed *prometheus.GaugeVec
65+
rateLimit *prometheus.GaugeVec
66+
// TODO: remove deprecated metrics in the future release
67+
rateLimitDeprecated *prometheus.GaugeVec
68+
rateLimitRemaining *prometheus.GaugeVec
69+
rateLimitUsed *prometheus.GaugeVec
6870
// rateLimitReset is unix time of the next interval (when the rate limit resets).
6971
rateLimitReset *prometheus.GaugeVec
7072
// rateLimitResetIn is the time in seconds until the rate limit resets.
@@ -91,14 +93,25 @@ func NewFactory(registry prometheus.Registerer) *Factory {
9193
rateLimit: factory.NewGaugeVec(prometheus.GaugeOpts{
9294
Namespace: "coderd",
9395
Subsystem: "oauth2",
94-
Name: "external_requests_rate_limit_total",
96+
Name: "external_requests_rate_limit",
9597
Help: "The total number of allowed requests per interval.",
9698
}, []string{
9799
"name",
98100
// Resource allows different rate limits for the same oauth2 provider.
99101
// Some IDPs have different buckets for different rate limits.
100102
"resource",
101103
}),
104+
// TODO: deprecated: remove in the future
105+
// Deprecation reason: gauge metrics should avoid suffix `_total``
106+
rateLimitDeprecated: factory.NewGaugeVec(prometheus.GaugeOpts{
107+
Namespace: "coderd",
108+
Subsystem: "oauth2",
109+
Name: "external_requests_rate_limit_total",
110+
Help: "DEPRECATED: use coderd_oauth2_external_requests_rate_limit instead",
111+
}, []string{
112+
"name",
113+
"resource",
114+
}),
102115
rateLimitRemaining: factory.NewGaugeVec(prometheus.GaugeOpts{
103116
Namespace: "coderd",
104117
Subsystem: "oauth2",
@@ -176,6 +189,8 @@ func (f *Factory) NewGithub(name string, under OAuth2Config) *Config {
176189
}
177190
}
178191

192+
// TODO: remove this metric in v3
193+
f.metrics.rateLimitDeprecated.With(labels).Set(float64(limits.Limit))
179194
f.metrics.rateLimit.With(labels).Set(float64(limits.Limit))
180195
f.metrics.rateLimitRemaining.With(labels).Set(float64(limits.Remaining))
181196
f.metrics.rateLimitUsed.With(labels).Set(float64(limits.Used))

docs/admin/prometheus.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,20 @@ spec:
120120
| `coderd_api_request_latencies_seconds` | histogram | Latency distribution of requests in seconds. | `method` `path` |
121121
| `coderd_api_requests_processed_total` | counter | The total number of processed API requests | `code` `method` `path` |
122122
| `coderd_api_websocket_durations_seconds` | histogram | Websocket duration distribution of requests in seconds. | `path` |
123-
| `coderd_api_workspace_latest_build_total` | gauge | The latest workspace builds with a status. | `status` |
123+
| `coderd_api_workspace_latest_build` | gauge | The latest workspace builds with a status. | `status` |
124+
| `coderd_api_workspace_latest_build_total` | gauge | DEPRECATED: use coderd_api_workspace_latest_build instead | `status` |
124125
| `coderd_insights_applications_usage_seconds` | gauge | The application usage per template. | `application_name` `slug` `template_name` |
125126
| `coderd_insights_parameters` | gauge | The parameter usage per template. | `parameter_name` `parameter_type` `parameter_value` `template_name` |
126127
| `coderd_insights_templates_active_users` | gauge | The number of active users of the template. | `template_name` |
127128
| `coderd_license_active_users` | gauge | The number of active users. | |
128129
| `coderd_license_limit_users` | gauge | The user seats limit based on the active Coder license. | |
129130
| `coderd_license_user_limit_enabled` | gauge | Returns 1 if the current license enforces the user limit. | |
130131
| `coderd_metrics_collector_agents_execution_seconds` | histogram | Histogram for duration of agents metrics collection in seconds. | |
132+
| `coderd_oauth2_external_requests_rate_limit` | gauge | The total number of allowed requests per interval. | `name` `resource` |
131133
| `coderd_oauth2_external_requests_rate_limit_next_reset_unix` | gauge | Unix timestamp of the next interval | `name` `resource` |
132134
| `coderd_oauth2_external_requests_rate_limit_remaining` | gauge | The remaining number of allowed requests in this interval. | `name` `resource` |
133135
| `coderd_oauth2_external_requests_rate_limit_reset_in_seconds` | gauge | Seconds until the next interval | `name` `resource` |
134-
| `coderd_oauth2_external_requests_rate_limit_total` | gauge | The total number of allowed requests per interval. | `name` `resource` |
136+
| `coderd_oauth2_external_requests_rate_limit_total` | gauge | DEPRECATED: use coderd_oauth2_external_requests_rate_limit instead | `name` `resource` |
135137
| `coderd_oauth2_external_requests_rate_limit_used` | gauge | The number of requests made in this interval. | `name` `resource` |
136138
| `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` |
137139
| `coderd_provisionerd_job_timings_seconds` | histogram | The provisioner job time duration in seconds. | `provisioner` `status` |

scripts/metricsdocgen/metrics

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ coderd_oauth2_external_requests_rate_limit_remaining{name="secondary-github",res
1010
# TYPE coderd_oauth2_external_requests_rate_limit_reset_in_seconds gauge
1111
coderd_oauth2_external_requests_rate_limit_reset_in_seconds{name="primary-github",resource="core"} 63.617162731
1212
coderd_oauth2_external_requests_rate_limit_reset_in_seconds{name="secondary-github",resource="core"} 121.82186601
13-
# HELP coderd_oauth2_external_requests_rate_limit_total The total number of allowed requests per interval.
13+
# HELP coderd_oauth2_external_requests_rate_limit The total number of allowed requests per interval.
14+
# TYPE coderd_oauth2_external_requests_rate_limit gauge
15+
coderd_oauth2_external_requests_rate_limit{name="primary-github",resource="core-unauthorized"} 5000
16+
coderd_oauth2_external_requests_rate_limit{name="secondary-github",resource="core-unauthorized"} 5000
17+
# HELP coderd_oauth2_external_requests_rate_limit_total DEPRECATED: use coderd_oauth2_external_requests_rate_limit instead
1418
# TYPE coderd_oauth2_external_requests_rate_limit_total gauge
1519
coderd_oauth2_external_requests_rate_limit_total{name="primary-github",resource="core-unauthorized"} 5000
1620
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/
644648
coderd_api_requests_processed_total{code="401",method="GET",path="/api/v2/users/{user}/*"} 2
645649
coderd_api_requests_processed_total{code="401",method="GET",path="/api/v2/workspaces"} 1
646650
coderd_api_requests_processed_total{code="401",method="POST",path="/api/v2/files"} 1
647-
# HELP coderd_api_workspace_latest_build_total The latest workspace builds with a status.
651+
# HELP coderd_api_workspace_latest_build The latest workspace builds with a status.
652+
# TYPE coderd_api_workspace_latest_build gauge
653+
coderd_api_workspace_latest_build{status="succeeded"} 1
654+
# HELP coderd_api_workspace_latest_build_total DEPRECATED: use coderd_api_workspace_latest_build instead
648655
# TYPE coderd_api_workspace_latest_build_total gauge
649656
coderd_api_workspace_latest_build_total{status="succeeded"} 1
650657
# HELP coderd_insights_applications_usage_seconds The application usage per template.

0 commit comments

Comments
 (0)