@@ -412,8 +412,8 @@ var (
412412
413413 workerOperationDuration = prometheus .NewGaugeVec (prometheus.GaugeOpts {
414414 Name : workerOperationDurationMetricName .String (),
415- Help : "Average duration of a worker operation in seconds, sliced by metric_type (worker-defined event type) and label (worker-defined slice)" ,
416- }, []string {"script_name" , "account" , "metric_type" , "label" })
415+ Help : "Worker operation duration quantiles in seconds, sliced by metric_type (worker-defined event type), label (worker-defined slice), and quantile (P50, P75, P99, P999 )" ,
416+ }, []string {"script_name" , "account" , "metric_type" , "label" , "quantile" })
417417)
418418
419419func buildAllMetricsSet () MetricsSet {
@@ -1407,8 +1407,10 @@ func fetchWorkerWAEAnalytics(account cfaccounts.Account, wg *sync.WaitGroup, den
14071407 SELECT
14081408 index1 AS metric_type,
14091409 blob1 AS label,
1410- SUM(_sample_interval * double1) / SUM(_sample_interval) AS avg_duration_ms,
1411- SUM(_sample_interval) AS total_requests
1410+ quantileWeighted(0.50, double1, _sample_interval) AS p50_ms,
1411+ quantileWeighted(0.75, double1, _sample_interval) AS p75_ms,
1412+ quantileWeighted(0.99, double1, _sample_interval) AS p99_ms,
1413+ quantileWeighted(0.999, double1, _sample_interval) AS p999_ms
14121414 FROM %s
14131415 WHERE timestamp > NOW() - INTERVAL '5' MINUTE
14141416 GROUP BY index1, blob1
@@ -1424,20 +1426,33 @@ func fetchWorkerWAEAnalytics(account cfaccounts.Account, wg *sync.WaitGroup, den
14241426 continue
14251427 }
14261428
1429+ quantiles := []struct {
1430+ column string
1431+ label string
1432+ }{
1433+ {"p50_ms" , "P50" },
1434+ {"p75_ms" , "P75" },
1435+ {"p99_ms" , "P99" },
1436+ {"p999_ms" , "P999" },
1437+ }
1438+
14271439 for _ , row := range resp .Data {
14281440 metricType , _ := row ["metric_type" ].(string )
14291441 label , _ := row ["label" ].(string )
1430- avgDurationMs , _ := row ["avg_duration_ms" ].(float64 )
14311442 if metricType == "" {
14321443 continue
14331444 }
14341445
1435- workerOperationDuration .With (prometheus.Labels {
1436- "script_name" : scriptName ,
1437- "account" : accountName ,
1438- "metric_type" : metricType ,
1439- "label" : label ,
1440- }).Set (avgDurationMs / 1000.0 )
1446+ for _ , q := range quantiles {
1447+ val , _ := row [q .column ].(float64 )
1448+ workerOperationDuration .With (prometheus.Labels {
1449+ "script_name" : scriptName ,
1450+ "account" : accountName ,
1451+ "metric_type" : metricType ,
1452+ "label" : label ,
1453+ "quantile" : q .label ,
1454+ }).Set (val / 1000.0 )
1455+ }
14411456 }
14421457 }
14431458}
0 commit comments