Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsp indicator isolated from ehpa #881

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading