Skip to content

Commit 191cd85

Browse files
committed
Export worker invocation status on metrics
This change adds `status` to the CloudFlare worker metrics being exported. This fixes an issue where, similar to `datetime` previously, we are getting multiple metric series from the combinations of unique dimensions. This resulted in only the last datapoint series being exported from the `cloudflare-exporter` for the CloudFlare workers. Additionally this provides more information as the `status` can be used to differentiate the internal errors seen in CloudFlare workers.
1 parent f8fe7b0 commit 191cd85

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

prometheus.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,25 +213,25 @@ var (
213213
workerRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
214214
Name: workerRequestsMetricName.String(),
215215
Help: "Number of requests sent to worker by script name",
216-
}, []string{"script_name", "account"},
216+
}, []string{"script_name", "account", "status"},
217217
)
218218

219219
workerErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
220220
Name: workerErrorsMetricName.String(),
221221
Help: "Number of errors by script name",
222-
}, []string{"script_name", "account"},
222+
}, []string{"script_name", "account", "status"},
223223
)
224224

225225
workerCPUTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
226226
Name: workerCPUTimeMetricName.String(),
227227
Help: "CPU time quantiles by script name",
228-
}, []string{"script_name", "account", "quantile"},
228+
}, []string{"script_name", "account", "status", "quantile"},
229229
)
230230

231231
workerDuration = prometheus.NewGaugeVec(prometheus.GaugeOpts{
232232
Name: workerDurationMetricName.String(),
233233
Help: "Duration quantiles by script name (GB*s)",
234-
}, []string{"script_name", "account", "quantile"},
234+
}, []string{"script_name", "account", "status", "quantile"},
235235
)
236236

237237
poolHealthStatus = prometheus.NewGaugeVec(prometheus.GaugeOpts{
@@ -426,16 +426,16 @@ func fetchWorkerAnalytics(account cloudflare.Account, wg *sync.WaitGroup) {
426426

427427
for _, a := range r.Viewer.Accounts {
428428
for _, w := range a.WorkersInvocationsAdaptive {
429-
workerRequests.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName}).Add(float64(w.Sum.Requests))
430-
workerErrors.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName}).Add(float64(w.Sum.Errors))
431-
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "quantile": "P50"}).Set(float64(w.Quantiles.CPUTimeP50))
432-
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "quantile": "P75"}).Set(float64(w.Quantiles.CPUTimeP75))
433-
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "quantile": "P99"}).Set(float64(w.Quantiles.CPUTimeP99))
434-
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "quantile": "P999"}).Set(float64(w.Quantiles.CPUTimeP999))
435-
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "quantile": "P50"}).Set(float64(w.Quantiles.DurationP50))
436-
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "quantile": "P75"}).Set(float64(w.Quantiles.DurationP75))
437-
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "quantile": "P99"}).Set(float64(w.Quantiles.DurationP99))
438-
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "quantile": "P999"}).Set(float64(w.Quantiles.DurationP999))
429+
workerRequests.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status}).Add(float64(w.Sum.Requests))
430+
workerErrors.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status}).Add(float64(w.Sum.Errors))
431+
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P50"}).Set(float64(w.Quantiles.CPUTimeP50))
432+
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P75"}).Set(float64(w.Quantiles.CPUTimeP75))
433+
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P99"}).Set(float64(w.Quantiles.CPUTimeP99))
434+
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P999"}).Set(float64(w.Quantiles.CPUTimeP999))
435+
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P50"}).Set(float64(w.Quantiles.DurationP50))
436+
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P75"}).Set(float64(w.Quantiles.DurationP75))
437+
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P99"}).Set(float64(w.Quantiles.DurationP99))
438+
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P999"}).Set(float64(w.Quantiles.DurationP999))
439439
}
440440
}
441441
}

0 commit comments

Comments
 (0)