From 5659cddc842f3e1e749989241f0c17836ee34f0b Mon Sep 17 00:00:00 2001 From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com> Date: Fri, 24 May 2024 18:20:46 +0530 Subject: [PATCH] Add cluster config metrics in metrics-v3 (#19507) endpoint: /minio/metrics/v3/cluster/config metrics: - write_quorum - rrs_parity - standard_parity --- cmd/metrics-v3-cluster-config.go | 46 ++++++++++++++++++++++++++++++++ cmd/metrics-v3.go | 10 +++++++ docs/metrics/v3.md | 7 +++++ internal/cachevalue/cache.go | 2 +- 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 cmd/metrics-v3-cluster-config.go diff --git a/cmd/metrics-v3-cluster-config.go b/cmd/metrics-v3-cluster-config.go new file mode 100644 index 000000000..9d96c6bb1 --- /dev/null +++ b/cmd/metrics-v3-cluster-config.go @@ -0,0 +1,46 @@ +// Copyright (c) 2015-2024 MinIO, Inc. +// +// This file is part of MinIO Object Storage stack +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package cmd + +import "context" + +const ( + configRRSParity = "rrs_parity" + configStandardParity = "standard_parity" +) + +var ( + configRRSParityMD = NewGaugeMD(configRRSParity, + "Reduced redundancy storage class parity") + configStandardParityMD = NewGaugeMD(configStandardParity, + "Standard storage class parity") +) + +// loadClusterConfigMetrics - `MetricsLoaderFn` for cluster config +// such as standard and RRS parity. +func loadClusterConfigMetrics(ctx context.Context, m MetricValues, c *metricsCache) error { + clusterDriveMetrics, err := c.clusterDriveMetrics.Get() + if err != nil { + metricsLogIf(ctx, err) + } else { + m.Set(configStandardParity, float64(clusterDriveMetrics.storageInfo.Backend.StandardSCParity)) + m.Set(configRRSParity, float64(clusterDriveMetrics.storageInfo.Backend.RRSCParity)) + } + + return nil +} diff --git a/cmd/metrics-v3.go b/cmd/metrics-v3.go index ac254452a..f048dbad8 100644 --- a/cmd/metrics-v3.go +++ b/cmd/metrics-v3.go @@ -52,6 +52,7 @@ const ( clusterUsageBucketsCollectorPath collectorPath = "/cluster/usage/buckets" clusterErasureSetCollectorPath collectorPath = "/cluster/erasure-set" clusterIAMCollectorPath collectorPath = "/cluster/iam" + clusterConfigCollectorPath collectorPath = "/cluster/config" auditCollectorPath collectorPath = "/audit" loggerWebhookCollectorPath collectorPath = "/logger/webhook" @@ -342,6 +343,14 @@ func newMetricGroups(r *prometheus.Registry) *metricsV3Collection { loadClusterReplicationMetrics, ) + clusterConfigMG := NewMetricsGroup(clusterConfigCollectorPath, + []MetricDescriptor{ + configRRSParityMD, + configStandardParityMD, + }, + loadClusterConfigMetrics, + ) + loggerWebhookMG := NewMetricsGroup(loggerWebhookCollectorPath, []MetricDescriptor{ webhookFailedMessagesMD, @@ -378,6 +387,7 @@ func newMetricGroups(r *prometheus.Registry) *metricsV3Collection { clusterNotificationMG, clusterIAMMG, clusterReplicationMG, + clusterConfigMG, auditMG, loggerWebhookMG, diff --git a/docs/metrics/v3.md b/docs/metrics/v3.md index 3efbf8ab8..756857fb4 100644 --- a/docs/metrics/v3.md +++ b/docs/metrics/v3.md @@ -261,6 +261,13 @@ The standard metrics group for GoCollector is not shown below. | `minio_cluster_health_capacity_usable_total_bytes` | `gauge` | Total cluster usable storage capacity in bytes | | | `minio_cluster_health_capacity_usable_free_bytes` | `gauge` | Total cluster usable storage free in bytes | | +### `/cluster/config` + +| Name | Type | Help | Labels | +|----------------------------------------|---------|------------------------------------------------|--------| +| `minio_cluster_config_rrs_parity` | `gauge` | Reduced redundancy storage class parity | | +| `minio_cluster_config_standard_parity` | `gauge` | Standard storage class parity | | + ### `/cluster/usage/objects` | Name | Type | Help | Labels | diff --git a/internal/cachevalue/cache.go b/internal/cachevalue/cache.go index 064d9dce6..346e0a5f2 100644 --- a/internal/cachevalue/cache.go +++ b/internal/cachevalue/cache.go @@ -92,7 +92,7 @@ func (t *Cache[T]) InitOnce(ttl time.Duration, opts Opts, update func(ctx contex // GetWithCtx will return a cached value or fetch a new one. // passes a caller context, if caller context cancels nothing // is cached. -// Tf the Update function returns an error the value is forwarded as is and not cached. +// If the Update function returns an error the value is forwarded as is and not cached. func (t *Cache[T]) GetWithCtx(ctx context.Context) (T, error) { v := t.val.Load() ttl := t.ttl