From dcaf01f5bf769a5ec974605707c963cb2242d37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=B8=BF=E6=96=8C?= Date: Fri, 1 Dec 2023 17:00:34 +0800 Subject: [PATCH] feat(sysadvisor): emit bound type code for knob status --- .../plugin/metric-emitter/syncer/node/advisor.go | 11 ++++++----- pkg/agent/sysadvisor/types/consts.go | 7 +++++++ pkg/agent/sysadvisor/types/cpu.go | 12 ++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/pkg/agent/sysadvisor/plugin/metric-emitter/syncer/node/advisor.go b/pkg/agent/sysadvisor/plugin/metric-emitter/syncer/node/advisor.go index e7f6848c60..6c072bf32d 100644 --- a/pkg/agent/sysadvisor/plugin/metric-emitter/syncer/node/advisor.go +++ b/pkg/agent/sysadvisor/plugin/metric-emitter/syncer/node/advisor.go @@ -54,10 +54,6 @@ func (n *MetricSyncerNode) advisorMetric(ctx context.Context) { Key: fmt.Sprintf("%s%s", data.CustomMetricLabelSelectorPrefixKey, "region"), Val: fmt.Sprintf("%v", regionName), }, - { - Key: fmt.Sprintf("%s%s", data.CustomMetricLabelSelectorPrefixKey, "bound"), - Val: fmt.Sprintf("%v", regionInfo.RegionStatus.BoundType), - }, }...) for indicator, overshot := range regionInfo.RegionStatus.OvershootStatus { regionTag = append(regionTag, metrics.MetricTag{ @@ -66,7 +62,12 @@ func (n *MetricSyncerNode) advisorMetric(ctx context.Context) { }) } - _ = n.dataEmitter.StoreFloat64(apimetricnode.CustomMetricNodeAdvisorKnobStatus, 1, metrics.MetricTypeNameRaw, regionTag...) + if code, ok := types.BoundTypeCodeMap[regionInfo.RegionStatus.BoundType]; ok { + _ = n.dataEmitter.StoreFloat64(apimetricnode.CustomMetricNodeAdvisorKnobStatus, float64(code), metrics.MetricTypeNameRaw, regionTag...) + } else { + general.Errorf("invalid bound type %v for ") + } + return true }) diff --git a/pkg/agent/sysadvisor/types/consts.go b/pkg/agent/sysadvisor/types/consts.go index d590b76c14..ac979fc92c 100644 --- a/pkg/agent/sysadvisor/types/consts.go +++ b/pkg/agent/sysadvisor/types/consts.go @@ -18,6 +18,13 @@ package types import "time" +var BoundTypeCodeMap = map[BoundType]int{ + BoundUpper: BoundUpperCode, + BoundLower: BoundLowerCode, + BoundNone: BoundNoneCode, + BoundUnknown: BoundUnknownCode, +} + const ( RegionNameSeparator = "-" ) diff --git a/pkg/agent/sysadvisor/types/cpu.go b/pkg/agent/sysadvisor/types/cpu.go index cad9c17dd2..935e6acc6d 100644 --- a/pkg/agent/sysadvisor/types/cpu.go +++ b/pkg/agent/sysadvisor/types/cpu.go @@ -137,16 +137,20 @@ type BoundType string const ( // BoundUpper indicates reaching resource upper bound, with highest priority - BoundUpper BoundType = "upper" + BoundUpper BoundType = "upper" + BoundUpperCode int = 0 // BoundLower indicates reaching resource lower bound - BoundLower BoundType = "lower" + BoundLower BoundType = "lower" + BoundLowerCode int = 1 // BoundNone indicates between resource upper and lower bound - BoundNone BoundType = "none" + BoundNone BoundType = "none" + BoundNoneCode int = 2 // BoundUnknown indicates unknown bound status - BoundUnknown BoundType = "unknown" + BoundUnknown BoundType = "unknown" + BoundUnknownCode int = 3 ) // RegionStatus holds stability accounting info of region