-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add pause metric in prometheus for scaledobject #4446
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,16 @@ var ( | |
}, | ||
[]string{"type", "namespace"}, | ||
) | ||
|
||
scaledObjectPausedTotal = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Namespace: DefaultPromMetricsNamespace, | ||
Subsystem: "scaled_object", | ||
Name: "paused", | ||
Help: "Total number of paused scaled_objects", | ||
}, | ||
[]string{"namespace", "scaledObject"}, | ||
) | ||
) | ||
|
||
func init() { | ||
|
@@ -118,6 +128,7 @@ func init() { | |
metrics.Registry.MustRegister(scalerActive) | ||
metrics.Registry.MustRegister(scalerErrors) | ||
metrics.Registry.MustRegister(scaledObjectErrors) | ||
metrics.Registry.MustRegister(scaledObjectPausedTotal) | ||
|
||
metrics.Registry.MustRegister(triggerTotalsGaugeVec) | ||
metrics.Registry.MustRegister(crdTotalsGaugeVec) | ||
|
@@ -204,3 +215,9 @@ func DecrementCRDTotal(crdType, namespace string) { | |
|
||
crdTotalsGaugeVec.WithLabelValues(crdType, namespace).Dec() | ||
} | ||
|
||
func RecordScalerPaused(namespace string, scaledObject string, value float64) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please rewrite this function to accept bool instead of float64? the same way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind doing it. I just can't figure out why the tests fails |
||
labels := prometheus.Labels{"namespace": namespace, "scaledObject": scaledObject} | ||
|
||
scaledObjectPausedTotal.With(labels).Set(value) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,6 +239,51 @@ spec: | |
name: {{.TestName}}-secret | ||
key: key | ||
--- | ||
` | ||
deploymentForPausedTemplate = ` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{.DeploymentName}}-pause | ||
namespace: {{.TestNamespace}} | ||
labels: | ||
app: {{.DeploymentName}}-pause | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: {{.DeploymentName}}-pause | ||
template: | ||
metadata: | ||
labels: | ||
app: {{.DeploymentName}}-pause | ||
spec: | ||
containers: | ||
- name: {{.DeploymentName}}-pause | ||
image: nginxinc/nginx-unprivileged | ||
` | ||
|
||
scaledObjectPausedTemplate = ` | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: {{.ScaledObjectName}}-paused | ||
namespace: {{.TestNamespace}} | ||
annotations: | ||
autoscaling.keda.sh/paused-replicas: "2" | ||
spec: | ||
scaleTargetRef: | ||
name: {{.DeploymentName}}-pause | ||
pollingInterval: 5 | ||
idleReplicaCount: 0 | ||
minReplicaCount: 1 | ||
maxReplicaCount: 2 | ||
cooldownPeriod: 10 | ||
triggers: | ||
- type: kubernetes-workload | ||
metadata: | ||
podSelector: 'app={{.DeploymentName}}-pause' | ||
value: '1' | ||
` | ||
) | ||
|
||
|
@@ -265,6 +310,7 @@ func TestPrometheusMetrics(t *testing.T) { | |
testMetricsServerScalerMetricValue(t) | ||
testOperatorMetrics(t, kc, data) | ||
testWebhookMetrics(t, data) | ||
testPauseMetric(t, data) | ||
|
||
// cleanup | ||
DeleteKubernetesResources(t, testNamespace, data, templates) | ||
|
@@ -707,3 +753,36 @@ func checkWebhookValues(t *testing.T, families map[string]*promModel.MetricFamil | |
} | ||
assert.GreaterOrEqual(t, metricValue, 1.0, "keda_webhook_scaled_object_validation_total has to be greater than 0") | ||
} | ||
|
||
func testPauseMetric(t *testing.T, data templateData) { | ||
t.Log("--- testing scaleobject pause metric ---") | ||
|
||
family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) | ||
|
||
if _, ok := family["keda_scaled_object_paused"]; ok { | ||
t.Errorf("metric should not be available") | ||
} | ||
|
||
KubectlApplyWithTemplate(t, data, "deploymentForPausedTemplate", deploymentForPausedTemplate) | ||
KubectlApplyWithTemplate(t, data, "scaledObjectPausedTemplate", scaledObjectPausedTemplate) | ||
|
||
family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) | ||
Comment on lines
+766
to
+769
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the metric is checked too fast and KEDA doesn't have enough time to process the ScaledObject. I guess that you can introduce a sleep here (5 seconds should be enough) or maybe deploying this resources in the beginning of the test file instead of inside the test case |
||
|
||
if val, ok := family["keda_scaled_object_paused"]; ok { | ||
metrics := val.GetMetric() | ||
for _, metric := range metrics { | ||
assert.Equal(t, float64(1), *metric.Gauge.Value) | ||
} | ||
} else { | ||
t.Errorf("metric not available") | ||
} | ||
|
||
KubectlDeleteWithTemplate(t, data, "deploymentForPausedTemplate", deploymentForPausedTemplate) | ||
KubectlDeleteWithTemplate(t, data, "scaledObjectPausedTemplate", scaledObjectPausedTemplate) | ||
|
||
family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) | ||
|
||
if _, ok := family["keda_scaled_object_paused"]; ok { | ||
t.Errorf("metric should not be available") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help message is wrong.