Simplify assembling of tierStats from data-usage (#14504)

This commit is contained in:
Krishnan Parthasarathi 2022-03-08 12:08:29 -08:00 committed by GitHub
parent 4d0715d226
commit 80ef1ae51c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 40 deletions

View File

@ -92,32 +92,37 @@ type DataUsageInfo struct {
} }
func (dui DataUsageInfo) tierStats() []madmin.TierInfo { func (dui DataUsageInfo) tierStats() []madmin.TierInfo {
if globalTierConfigMgr.Empty() { if dui.TierStats == nil {
return nil return nil
} }
ts := make(map[string]madmin.TierStats) cfgs := globalTierConfigMgr.ListTiers()
// Add configured remote tiers if len(cfgs) == 0 {
for tier := range globalTierConfigMgr.Tiers { return nil
ts[tier] = madmin.TierStats{}
} }
ts := make(map[string]madmin.TierStats, len(cfgs)+1)
infos := make([]madmin.TierInfo, 0, len(ts))
// Add STANDARD (hot-tier) // Add STANDARD (hot-tier)
ts[minioHotTier] = madmin.TierStats{} 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) ts = dui.TierStats.adminStats(ts)
infos := make([]madmin.TierInfo, 0, len(ts)) for i := range infos {
for tier, st := range ts { info := infos[i]
var tierType string infos[i].Stats = ts[info.Name]
if tier == minioHotTier {
tierType = "internal"
} else {
tierType = globalTierConfigMgr.Tiers[tier].Type.String()
}
infos = append(infos, madmin.TierInfo{
Name: tier,
Type: tierType,
Stats: st,
})
} }
sort.Slice(infos, func(i, j int) bool { sort.Slice(infos, func(i, j int) bool {
@ -131,3 +136,31 @@ func (dui DataUsageInfo) tierStats() []madmin.TierInfo {
}) })
return infos 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
}

View File

@ -1668,28 +1668,7 @@ func getClusterTierMetrics() *MetricsGroup {
return return
} }
// e.g minio_cluster_ilm_transitioned_bytes{tier="S3TIER-1"}=136314880 return dui.tierMetrics()
// 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 mg return mg
} }