From 3f1183251420cbc6dea5d45929dacad227bf9924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=B8=BF=E6=96=8C?= Date: Mon, 31 Jul 2023 17:38:43 +0800 Subject: [PATCH] enhancement(eviction): dry-run condition count --- .../evictionmanager/eviction_resp_collector.go | 13 +++++++++++-- pkg/agent/evictionmanager/manager.go | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/agent/evictionmanager/eviction_resp_collector.go b/pkg/agent/evictionmanager/eviction_resp_collector.go index 85e77898f8..aa54202301 100644 --- a/pkg/agent/evictionmanager/eviction_resp_collector.go +++ b/pkg/agent/evictionmanager/eviction_resp_collector.go @@ -18,6 +18,7 @@ package evictionmanager import ( "fmt" + "strings" //nolint "github.com/golang/protobuf/proto" @@ -30,6 +31,8 @@ import ( "github.com/kubewharf/katalyst-core/pkg/util/general" ) +const effectTagValueSeparator = "_" + // evictionRespCollector is used to collect eviction result from plugins, it also handles some logic such as dry run. type evictionRespCollector struct { conf *pkgconfig.Configuration @@ -91,7 +94,7 @@ func (e *evictionRespCollector) collectEvictPods(dryRunPlugins []string, pluginN e.getLogPrefix(dryRun), pluginName, evictPod.Pod.Namespace, evictPod.Pod.Name, evictPod.Reason, evictPod.ForceEvict) if dryRun { - _ = e.emitter.StoreInt64(MetricsNameDryrunVictimPodCNT, 1, metrics.MetricTypeNameRaw, + _ = e.emitter.StoreInt64(MetricsNameDryRunVictimPodCNT, 1, metrics.MetricTypeNameRaw, metrics.MetricTag{Key: "name", Val: pluginName}, metrics.MetricTag{Key: "victim_ns", Val: evictPod.Pod.Namespace}, metrics.MetricTag{Key: "victim_name", Val: evictPod.Pod.Name}) @@ -143,6 +146,12 @@ func (e *evictionRespCollector) collectMetThreshold(dryRunPlugins []string, plug if resp.Condition != nil && resp.Condition.MetCondition { general.Infof("%v plugin: %s requests to set condition: %s of type: %s", e.getLogPrefix(dryRun), pluginName, resp.Condition.ConditionName, resp.Condition.ConditionType.String()) + _ = e.emitter.StoreInt64(MetricsNameDryRunConditionCNT, 1, metrics.MetricTypeNameRaw, + metrics.MetricTag{Key: "name", Val: pluginName}, + metrics.MetricTag{Key: "condition_name", Val: resp.Condition.ConditionName}, + metrics.MetricTag{Key: "condition_type", Val: fmt.Sprint(resp.Condition.ConditionType)}, + metrics.MetricTag{Key: "effects", Val: strings.Join(resp.Condition.Effects, effectTagValueSeparator)}, + ) if !dryRun { e.getCurrentConditions()[resp.Condition.ConditionName] = proto.Clone(resp.Condition).(*pluginapi.Condition) @@ -162,7 +171,7 @@ func (e *evictionRespCollector) collectTopEvictionPods(dryRunPlugins []string, p general.Infof("%v plugin %v request to evict topN pod %v/%v, reason: met threshold in scope [%v]", e.getLogPrefix(dryRun), pluginName, pod.Namespace, pod.Name, threshold.EvictionScope) if dryRun { - _ = e.emitter.StoreInt64(MetricsNameDryrunVictimPodCNT, 1, metrics.MetricTypeNameRaw, + _ = e.emitter.StoreInt64(MetricsNameDryRunVictimPodCNT, 1, metrics.MetricTypeNameRaw, metrics.MetricTag{Key: "name", Val: pluginName}, metrics.MetricTag{Key: "victim_ns", Val: pod.Namespace}, metrics.MetricTag{Key: "victim_name", Val: pod.Name}) diff --git a/pkg/agent/evictionmanager/manager.go b/pkg/agent/evictionmanager/manager.go index aec7a0a679..bdad9cc31f 100644 --- a/pkg/agent/evictionmanager/manager.go +++ b/pkg/agent/evictionmanager/manager.go @@ -52,7 +52,8 @@ const ( MetricsNameVictimPodCNT = "victims_cnt" MetricsNameRunningPodCNT = "running_pod_cnt" MetricsNameCandidatePodCNT = "candidate_pod_cnt" - MetricsNameDryrunVictimPodCNT = "dryrun_victims_cnt" + MetricsNameDryRunVictimPodCNT = "dryrun_victims_cnt" + MetricsNameDryRunConditionCNT = "dryrun_condition_cnt" ) // LatestCNRGetter returns the latest CNR resources.