Skip to content

Commit d3b421f

Browse files
committed
Add dispatch_namespace label to worker invocation metrics
Adds dispatchNamespaceName as a dimension in the workersInvocationsAdaptive GraphQL query and exposes it as a dispatch_namespace label on all cloudflare_worker_* metrics. This allows grouping worker metrics by dispatch namespace, which is useful for Workers for Platforms deployments where multiple user workers share a namespace.
1 parent 9233e89 commit d3b421f

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

cloudflare.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ type logpushResponse struct {
104104
type accountResp struct {
105105
WorkersInvocationsAdaptive []struct {
106106
Dimensions struct {
107-
ScriptName string `json:"scriptName"`
108-
Status string `json:"status"`
107+
ScriptName string `json:"scriptName"`
108+
DispatchNamespaceName string `json:"dispatchNamespaceName"`
109+
Status string `json:"status"`
109110
}
110111

111112
Sum struct {
@@ -812,6 +813,7 @@ func fetchWorkerTotals(accountID string) (*cloudflareResponseAccts, error) {
812813
workersInvocationsAdaptive(limit: $limit, filter: { datetime_geq: $mintime, datetime_lt: $maxtime}) {
813814
dimensions {
814815
scriptName
816+
dispatchNamespaceName
815817
status
816818
}
817819

prometheus.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,31 +252,31 @@ var (
252252
workerRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
253253
Name: workerRequestsMetricName.String(),
254254
Help: "Number of requests sent to worker by script name",
255-
}, []string{"script_name", "account", "status"},
255+
}, []string{"script_name", "dispatch_namespace", "account", "status"},
256256
)
257257

258258
workerErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
259259
Name: workerErrorsMetricName.String(),
260260
Help: "Number of errors by script name",
261-
}, []string{"script_name", "account", "status"},
261+
}, []string{"script_name", "dispatch_namespace", "account", "status"},
262262
)
263263

264264
workerCPUTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
265265
Name: workerCPUTimeMetricName.String(),
266266
Help: "CPU time quantiles by script name",
267-
}, []string{"script_name", "account", "status", "quantile"},
267+
}, []string{"script_name", "dispatch_namespace", "account", "status", "quantile"},
268268
)
269269

270270
workerDuration = prometheus.NewGaugeVec(prometheus.GaugeOpts{
271271
Name: workerDurationMetricName.String(),
272272
Help: "Duration quantiles by script name (GB*s)",
273-
}, []string{"script_name", "account", "status", "quantile"},
273+
}, []string{"script_name", "dispatch_namespace", "account", "status", "quantile"},
274274
)
275275

276276
workerWallTime = prometheus.NewGaugeVec(prometheus.GaugeOpts{
277277
Name: workerWallTimeMetricName.String(),
278278
Help: "Wall time quantiles by script name (microseconds)",
279-
}, []string{"script_name", "account", "status", "quantile"},
279+
}, []string{"script_name", "dispatch_namespace", "account", "status", "quantile"},
280280
)
281281

282282
poolHealthStatus = prometheus.NewGaugeVec(prometheus.GaugeOpts{
@@ -720,20 +720,20 @@ func fetchWorkerAnalytics(account cfaccounts.Account, wg *sync.WaitGroup) {
720720

721721
for _, a := range r.Viewer.Accounts {
722722
for _, w := range a.WorkersInvocationsAdaptive {
723-
workerRequests.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status}).Add(float64(w.Sum.Requests))
724-
workerErrors.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status}).Add(float64(w.Sum.Errors))
725-
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P50"}).Set(float64(w.Quantiles.CPUTimeP50))
726-
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P75"}).Set(float64(w.Quantiles.CPUTimeP75))
727-
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P99"}).Set(float64(w.Quantiles.CPUTimeP99))
728-
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P999"}).Set(float64(w.Quantiles.CPUTimeP999))
729-
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P50"}).Set(float64(w.Quantiles.DurationP50))
730-
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P75"}).Set(float64(w.Quantiles.DurationP75))
731-
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P99"}).Set(float64(w.Quantiles.DurationP99))
732-
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P999"}).Set(float64(w.Quantiles.DurationP999))
733-
workerWallTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P50"}).Set(float64(w.Quantiles.WallTimeP50))
734-
workerWallTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P75"}).Set(float64(w.Quantiles.WallTimeP75))
735-
workerWallTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P99"}).Set(float64(w.Quantiles.WallTimeP99))
736-
workerWallTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P999"}).Set(float64(w.Quantiles.WallTimeP999))
723+
workerRequests.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status}).Add(float64(w.Sum.Requests))
724+
workerErrors.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status}).Add(float64(w.Sum.Errors))
725+
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P50"}).Set(float64(w.Quantiles.CPUTimeP50))
726+
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P75"}).Set(float64(w.Quantiles.CPUTimeP75))
727+
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P99"}).Set(float64(w.Quantiles.CPUTimeP99))
728+
workerCPUTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P999"}).Set(float64(w.Quantiles.CPUTimeP999))
729+
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P50"}).Set(float64(w.Quantiles.DurationP50))
730+
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P75"}).Set(float64(w.Quantiles.DurationP75))
731+
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P99"}).Set(float64(w.Quantiles.DurationP99))
732+
workerDuration.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P999"}).Set(float64(w.Quantiles.DurationP999))
733+
workerWallTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P50"}).Set(float64(w.Quantiles.WallTimeP50))
734+
workerWallTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P75"}).Set(float64(w.Quantiles.WallTimeP75))
735+
workerWallTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P99"}).Set(float64(w.Quantiles.WallTimeP99))
736+
workerWallTime.With(prometheus.Labels{"script_name": w.Dimensions.ScriptName, "dispatch_namespace": w.Dimensions.DispatchNamespaceName, "account": accountName, "status": w.Dimensions.Status, "quantile": "P999"}).Set(float64(w.Quantiles.WallTimeP999))
737737
}
738738
}
739739
}

0 commit comments

Comments
 (0)