From 80ef1ae51ca8c7d7fdba9a28e94574e65527c01e Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Tue, 8 Mar 2022 12:08:29 -0800 Subject: [PATCH] Simplify assembling of tierStats from data-usage (#14504) --- cmd/data-usage-utils.go | 69 ++++++++++++++++++++++++++++++----------- cmd/metrics-v2.go | 23 +------------- 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/cmd/data-usage-utils.go b/cmd/data-usage-utils.go index de77a240d..5865a0154 100644 --- a/cmd/data-usage-utils.go +++ b/cmd/data-usage-utils.go @@ -92,32 +92,37 @@ type DataUsageInfo struct { } func (dui DataUsageInfo) tierStats() []madmin.TierInfo { - if globalTierConfigMgr.Empty() { + if dui.TierStats == nil { return nil } - ts := make(map[string]madmin.TierStats) - // Add configured remote tiers - for tier := range globalTierConfigMgr.Tiers { - ts[tier] = madmin.TierStats{} + cfgs := globalTierConfigMgr.ListTiers() + if len(cfgs) == 0 { + return nil } + + ts := make(map[string]madmin.TierStats, len(cfgs)+1) + infos := make([]madmin.TierInfo, 0, len(ts)) + // Add STANDARD (hot-tier) ts[minioHotTier] = madmin.TierStats{} + infos = append(infos, madmin.TierInfo{ + Name: minioHotTier, + Type: "internal", + }) + // Add configured remote tiers + for _, cfg := range cfgs { + ts[cfg.Name] = madmin.TierStats{} + infos = append(infos, madmin.TierInfo{ + Name: cfg.Name, + Type: cfg.Type.String(), + }) + } ts = dui.TierStats.adminStats(ts) - infos := make([]madmin.TierInfo, 0, len(ts)) - for tier, st := range ts { - var tierType string - if tier == minioHotTier { - tierType = "internal" - } else { - tierType = globalTierConfigMgr.Tiers[tier].Type.String() - } - infos = append(infos, madmin.TierInfo{ - Name: tier, - Type: tierType, - Stats: st, - }) + for i := range infos { + info := infos[i] + infos[i].Stats = ts[info.Name] } sort.Slice(infos, func(i, j int) bool { @@ -131,3 +136,31 @@ func (dui DataUsageInfo) tierStats() []madmin.TierInfo { }) return infos } + +func (dui DataUsageInfo) tierMetrics() (metrics []Metric) { + if dui.TierStats == nil { + return nil + } + // e.g minio_cluster_ilm_transitioned_bytes{tier="S3TIER-1"}=136314880 + // minio_cluster_ilm_transitioned_objects{tier="S3TIER-1"}=1 + // minio_cluster_ilm_transitioned_versions{tier="S3TIER-1"}=3 + for tier, st := range dui.TierStats.Tiers { + metrics = append(metrics, Metric{ + Description: getClusterTransitionedBytesMD(), + Value: float64(st.TotalSize), + VariableLabels: map[string]string{"tier": tier}, + }) + metrics = append(metrics, Metric{ + Description: getClusterTransitionedObjectsMD(), + Value: float64(st.NumObjects), + VariableLabels: map[string]string{"tier": tier}, + }) + metrics = append(metrics, Metric{ + Description: getClusterTransitionedVersionsMD(), + Value: float64(st.NumVersions), + VariableLabels: map[string]string{"tier": tier}, + }) + } + + return metrics +} diff --git a/cmd/metrics-v2.go b/cmd/metrics-v2.go index 70ec1fc1b..15c789b3f 100644 --- a/cmd/metrics-v2.go +++ b/cmd/metrics-v2.go @@ -1668,28 +1668,7 @@ func getClusterTierMetrics() *MetricsGroup { return } - // e.g minio_cluster_ilm_transitioned_bytes{tier="S3TIER-1"}=136314880 - // minio_cluster_ilm_transitioned_objects{tier="S3TIER-1"}=1 - // minio_cluster_ilm_transitioned_versions{tier="S3TIER-1"}=3 - for tier, st := range dui.TierStats.Tiers { - metrics = append(metrics, Metric{ - Description: getClusterTransitionedBytesMD(), - Value: float64(st.TotalSize), - VariableLabels: map[string]string{"tier": tier}, - }) - metrics = append(metrics, Metric{ - Description: getClusterTransitionedObjectsMD(), - Value: float64(st.NumObjects), - VariableLabels: map[string]string{"tier": tier}, - }) - metrics = append(metrics, Metric{ - Description: getClusterTransitionedVersionsMD(), - Value: float64(st.NumVersions), - VariableLabels: map[string]string{"tier": tier}, - }) - } - - return metrics + return dui.tierMetrics() }) return mg }