From 04f92f12916ae498d98cd275c0e93680c1ac89a5 Mon Sep 17 00:00:00 2001 From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com> Date: Thu, 2 May 2024 23:07:57 +0530 Subject: [PATCH] Change endpoint format for per-bucket metrics (#19655) Per-bucket metrics endpoints always start with /bucket and the bucket name is appended to the path. e.g. if the collector path is /bucket/api, the endpoint for the bucket "mybucket" would be /minio/metrics/v3/bucket/api/mybucket Change the existing bucket api endpoint accordingly from /api/bucket to /bucket/api --- cmd/metrics-v3-handler.go | 21 +++++++++------------ cmd/metrics-v3.go | 6 +++++- docs/metrics/v3.md | 18 +++++++++--------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/cmd/metrics-v3-handler.go b/cmd/metrics-v3-handler.go index a2876a82d..b7c8c2ba4 100644 --- a/cmd/metrics-v3-handler.go +++ b/cmd/metrics-v3-handler.go @@ -221,18 +221,15 @@ func (h *metricsV3Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { pathComponents := mux.Vars(r)["pathComps"] isListingRequest := r.Form.Has("list") - // Parse optional buckets query parameter. - bucketsParam := r.Form["buckets"] - buckets := make([]string, 0, len(bucketsParam)) - for _, bp := range bucketsParam { - bp = strings.TrimSpace(bp) - if bp == "" { - continue - } - splits := strings.Split(bp, ",") - for _, split := range splits { - buckets = append(buckets, strings.TrimSpace(split)) - } + buckets := []string{} + if strings.HasPrefix(pathComponents, "/bucket/") { + // bucket specific metrics, extract the bucket name from the path. + // it's the last part of the path. e.g. /bucket/api/ + bucketIdx := strings.LastIndex(pathComponents, "/") + buckets = append(buckets, pathComponents[bucketIdx+1:]) + // remove bucket from pathComponents as it is dyanamic and + // hence not included in the collector path. + pathComponents = pathComponents[:bucketIdx] } innerHandler := h.handle(pathComponents, isListingRequest, buckets) diff --git a/cmd/metrics-v3.go b/cmd/metrics-v3.go index 3711c0f73..11a1f9d5c 100644 --- a/cmd/metrics-v3.go +++ b/cmd/metrics-v3.go @@ -29,9 +29,13 @@ import ( // // These are paths under the top-level /minio/metrics/v3 metrics endpoint. Each // of these paths returns a set of V3 metrics. +// +// Per-bucket metrics endpoints always start with /bucket and the bucket name is +// appended to the path. e.g. if the collector path is /bucket/api, the endpoint +// for the bucket "mybucket" would be /minio/metrics/v3/bucket/api/mybucket const ( apiRequestsCollectorPath collectorPath = "/api/requests" - apiBucketCollectorPath collectorPath = "/api/bucket" + apiBucketCollectorPath collectorPath = "/bucket/api" systemNetworkInternodeCollectorPath collectorPath = "/system/network/internode" systemDriveCollectorPath collectorPath = "/system/drive" diff --git a/docs/metrics/v3.md b/docs/metrics/v3.md index 8d442d4bf..653feaf4a 100644 --- a/docs/metrics/v3.md +++ b/docs/metrics/v3.md @@ -86,18 +86,18 @@ The standard metrics group for GoCollector is not shown below. | `minio_api_requests_traffic_sent_bytes` | `counter` | Total number of bytes sent | `type,pool_index,server` | | `minio_api_requests_traffic_received_bytes` | `counter` | Total number of bytes received | `type,pool_index,server` | -### `/api/bucket` +### `/bucket/api` | Name | Type | Help | Labels | |----------------------------------------------|-----------|------------------------------------------------------------------|-----------------------------------------| -| `minio_api_bucket_traffic_received_bytes` | `counter` | Total number of bytes sent for a bucket | `bucket,type,server,pool_index` | -| `minio_api_bucket_traffic_sent_bytes` | `counter` | Total number of bytes received for a bucket | `bucket,type,server,pool_index` | -| `minio_api_bucket_inflight_total` | `gauge` | Total number of requests currently in flight for a bucket | `bucket,name,type,server,pool_index` | -| `minio_api_bucket_total` | `counter` | Total number of requests for a bucket | `bucket,name,type,server,pool_index` | -| `minio_api_bucket_canceled_total` | `counter` | Total number of requests canceled by the client for a bucket | `bucket,name,type,server,pool_index` | -| `minio_api_bucket_4xx_errors_total` | `counter` | Total number of requests with 4xx errors for a bucket | `bucket,name,type,server,pool_index` | -| `minio_api_bucket_5xx_errors_total` | `counter` | Total number of requests with 5xx errors for a bucket | `bucket,name,type,server,pool_index` | -| `minio_api_bucket_ttfb_seconds_distribution` | `counter` | Distribution of time to first byte across API calls for a bucket | `bucket,name,le,type,server,pool_index` | +| `minio_bucket_api_traffic_received_bytes` | `counter` | Total number of bytes sent for a bucket | `bucket,type,server,pool_index` | +| `minio_bucket_api_traffic_sent_bytes` | `counter` | Total number of bytes received for a bucket | `bucket,type,server,pool_index` | +| `minio_bucket_api_inflight_total` | `gauge` | Total number of requests currently in flight for a bucket | `bucket,name,type,server,pool_index` | +| `minio_bucket_api_total` | `counter` | Total number of requests for a bucket | `bucket,name,type,server,pool_index` | +| `minio_bucket_api_canceled_total` | `counter` | Total number of requests canceled by the client for a bucket | `bucket,name,type,server,pool_index` | +| `minio_bucket_api_4xx_errors_total` | `counter` | Total number of requests with 4xx errors for a bucket | `bucket,name,type,server,pool_index` | +| `minio_bucket_api_5xx_errors_total` | `counter` | Total number of requests with 5xx errors for a bucket | `bucket,name,type,server,pool_index` | +| `minio_bucket_api_ttfb_seconds_distribution` | `counter` | Distribution of time to first byte across API calls for a bucket | `bucket,name,le,type,server,pool_index` | ### `/system/drive`