Skip to content

Commit

Permalink
tsp indicator isolated from ehpa
Browse files Browse the repository at this point in the history
  • Loading branch information
whitebear009 committed Dec 28, 2023
1 parent 6d7758e commit 2982d0f
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions pkg/metrics/metric_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,7 @@ func (c *CraneMetricCollector) Collect(ch chan<- prometheus.Metric) {
if err != nil {
klog.Errorf("Failed to list ehpa: %v", err)
}
var predictionMetrics []PredictionMetric
for _, ehpa := range ehpaList.Items {
namespace := ehpa.Namespace
if ehpa.Spec.Prediction != nil {
var tsp predictionapi.TimeSeriesPrediction
tspName := "ehpa-" + ehpa.Name

err := c.Get(context.TODO(), client.ObjectKey{Namespace: namespace, Name: tspName}, &tsp)
if err != nil {
klog.Errorf("Failed to get tsp: %v", err)
return
}
metricListTsp := c.getMetricsTsp(&tsp)
for _, metric := range metricListTsp {
if MetricContains(predictionMetrics, metric) {
continue
}

ch <- prometheus.NewMetricWithTimestamp(metric.Timestamp, prometheus.MustNewConstMetric(metric.Desc, prometheus.GaugeValue, metric.MetricValue, metric.TargetKind, metric.TargetName, metric.TargetNamespace, metric.ResourceIdentifier, metric.Algorithm))
predictionMetrics = append(predictionMetrics, metric)
}
}

if ehpa.Spec.Crons != nil {
metricCron, err := c.getMetricsCron(&ehpa)
if err != nil {
Expand All @@ -130,6 +108,27 @@ func (c *CraneMetricCollector) Collect(ch chan<- prometheus.Metric) {
}
}
}

if utilfeature.DefaultFeatureGate.Enabled(features.CraneTimeSeriesPrediction) {
var tspList predictionapi.TimeSeriesPredictionList
err := c.List(context.TODO(), &tspList)
if err != nil {
klog.Errorf("Failed to list tsp: %v", err)
}

var predictionMetrics []PredictionMetric
for _, tsp := range tspList.Items {
metricListTsp := c.getMetricsTsp(&tsp)
for _, metric := range metricListTsp {
if MetricContains(predictionMetrics, metric) {
continue
}

ch <- prometheus.NewMetricWithTimestamp(metric.Timestamp, prometheus.MustNewConstMetric(metric.Desc, prometheus.GaugeValue, metric.MetricValue, metric.TargetKind, metric.TargetName, metric.TargetNamespace, metric.ResourceIdentifier, metric.Algorithm))
predictionMetrics = append(predictionMetrics, metric)
}
}
}
metricsRuleError := c.getMetricsRuleError()
for _, i := range metricsRuleError {
ch <- i
Expand Down

0 comments on commit 2982d0f

Please sign in to comment.