Skip to content

Commit

Permalink
enhancement(eviction): dry-run condition count
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzhhb committed Jul 31, 2023
1 parent a0247ae commit 3f11832
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pkg/agent/evictionmanager/eviction_resp_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package evictionmanager

import (
"fmt"
"strings"

//nolint
"github.com/golang/protobuf/proto"
Expand All @@ -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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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)
Expand All @@ -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})
Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/evictionmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3f11832

Please sign in to comment.