diff --git a/pkg/metrics/analysis.go b/pkg/metrics/analysis.go index 79356b882..10b37cee2 100644 --- a/pkg/metrics/analysis.go +++ b/pkg/metrics/analysis.go @@ -15,8 +15,18 @@ var ( }, []string{"apiversion", "owner_kind", "namespace", "owner_name", "container", "resource"}, ) + + ReplicasRecommendation = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: "crane", + Subsystem: "analysis", + Name: "replicas_recommendation", + Help: "The workload's replicas recommended value", + }, + []string{"apiversion", "owner_kind", "namespace", "owner_name"}, + ) ) func init() { - metrics.Registry.MustRegister(ResourceRecommendation) + metrics.Registry.MustRegister(ResourceRecommendation, ReplicasRecommendation) } diff --git a/pkg/recommend/advisor/replicas.go b/pkg/recommend/advisor/replicas.go index 60959d930..c86c3a5d5 100644 --- a/pkg/recommend/advisor/replicas.go +++ b/pkg/recommend/advisor/replicas.go @@ -20,6 +20,7 @@ import ( "github.com/gocrane/crane/pkg/common" "github.com/gocrane/crane/pkg/metricnaming" "github.com/gocrane/crane/pkg/metricquery" + "github.com/gocrane/crane/pkg/metrics" "github.com/gocrane/crane/pkg/prediction/config" "github.com/gocrane/crane/pkg/recommend/types" "github.com/gocrane/crane/pkg/utils" @@ -197,6 +198,8 @@ func (a *ReplicasAdvisor) Advise(proposed *types.ProposedRecommendation) error { Replicas: &minReplicas, } + a.recordReplicasRecommendation(minReplicas) + proposed.EffectiveHPA = proposedEHPA proposed.ReplicasRecommendation = replicasRecommendation return nil @@ -391,6 +394,16 @@ func (a *ReplicasAdvisor) proposeMaxReplicas(percentileCpu float64, targetUtiliz return maxReplicas, nil } +func (a *ReplicasAdvisor) recordReplicasRecommendation(replicas int32) { + labels := map[string]string{ + "apiversion": a.Recommendation.Spec.TargetRef.APIVersion, + "owner_kind": a.Recommendation.Spec.TargetRef.Kind, + "namespace": a.Recommendation.Spec.TargetRef.Namespace, + "owner_name": a.Recommendation.Spec.TargetRef.Name, + } + metrics.ReplicasRecommendation.With(labels).Set(float64(replicas)) +} + func getPredictionCpuConfig() *config.Config { return &config.Config{ DSP: &predictionapi.DSP{