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

Unable to get metrics data from Cloudwach when using more than one dimension #6236

Open
abanfi-nozomi opened this issue Oct 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@abanfi-nozomi
Copy link

abanfi-nozomi commented Oct 14, 2024

Report

We are using AWS Cloudwatch scaler.
When the metric we want to retrieve data for has one dimension, everything works as expected
When the metric has more than one diimension, the scaler seems not able to retrieve metrics data and default values is returned.

Expected Behavior

By defining this trigger

{{ if .Values.application.AutoscalingEnabled }}
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: {{ .Values.application.name }}
  labels:
    deploymentName: {{ .Values.application.name }}
    {{- include "n2eos.labels" . | nindent 4 }}
spec:
  minReplicaCount: {{ .Values.application.minReplicas }}
  maxReplicaCount: {{ .Values.application.maxReplicas }}
  scaleTargetRef:
    apiVersion: argoproj.io/v1alpha1
    kind: Rollout
    name: {{ .Values.application.name }}
  triggers:
  - type: aws-cloudwatch
    metricType: Value
    metadata:
      identityOwner: "operator"
      awsRegion: {{ .Values.application.env.AWS_REGION }}
      namespace: "AWS/ApplicationELB"
      dimensionName: "TargetGroup;LoadBalancer"
      dimensionValue: "{{ .Values.application.env.TG_NAME }};{{ .Values.application.env.ALB_NAME }}"
      metricName: "TargetResponseTime"
      metricStat: "Average"
      metricCollectionTime: "180"
      metricStatPeriod: "60"
      targetMetricValue: {{ .Values.application.HighExternalRequestsLatencyMetrictarget | quote }}
      minMetricValue: "0"
  - type: cpu
    metadata:
      type: Utilization
      value: {{ .Values.application.targetAverageUtilization | quote }}
{{ end }}

we expect to retrieve data from cloudwatch, but this is not happening

Actual Behavior

The keda operator logs says that the metrics is empty and the default value (0) is returned.
Running
``kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/***/s0-aws-cloudwatch?labelSelector=scaledobject.keda.sh%2Fname%3Dapplication"`
zero value (which is the default is returned)
The workaround we found to make this work is to use expression.
If we define the trigger like the following


{{ if .Values.application.AutoscalingEnabled }}
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: {{ .Values.application.name }}
  labels:
    deploymentName: {{ .Values.application.name }}
    {{- include "n2eos.labels" . | nindent 4 }}
spec:
  minReplicaCount: {{ .Values.application.minReplicas }}
  maxReplicaCount: {{ .Values.application.maxReplicas }}
  scaleTargetRef:
    apiVersion: argoproj.io/v1alpha1
    kind: Rollout
    name: {{ .Values.application.name }}
  triggers:
  - type: aws-cloudwatch
    metricType: Value
    metadata:
      identityOwner: "operator"
      awsRegion: {{ .Values.application.env.AWS_REGION }}
      expression: SELECT AVG(TargetResponseTime) FROM SCHEMA("AWS/ApplicationELB", LoadBalancer,TargetGroup) WHERE TargetGroup = '{{ .Values.application.env.TG_NAME }}' AND LoadBalancer = '{{ .Values.application.env.ALB_NAME }}'
      metricStat: "Average"
      metricCollectionTime: "180"
      metricStatPeriod: "60"
      targetMetricValue: {{ .Values.application.HighExternalRequestsLatencyMetrictarget | quote }}
      minMetricValue: "0"
  - type: cpu
    metadata:
      type: Utilization
      value: {{ .Values.application.targetAverageUtilization | quote }}
{{ end }}

the actual value for the metric is returned

Steps to Reproduce the Problem

  1. Create the trigger
  2. See that metrics value is not returned from keda

Logs from KEDA operator

│ 2024-10-14T05:54:18Z    INFO    aws_cloudwatch_scaler    empty metric data received, returning minMetricValue    {"type": "ScaledObject", "namespace": "***", "name": "***"}                         

KEDA Version

2.15.1

Kubernetes Version

1.30

Platform

Amazon Web Services

Scaler Details

aws-cloudwatch

Anything else?

Another trigger definition we have, with only one dimension, is working as expected

{{- if .Values.applications.rq.enabled }}
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: {{ .Values.applications.rq.name }}-scaling
spec:
  scaleTargetRef:
    apiVersion: argoproj.io/v1alpha1
    kind: Rollout
    name: {{ .Values.applications.rq.name }}
  minReplicaCount: {{ .Values.applications.rq.deployment.minReplicas }}
  maxReplicaCount: {{ .Values.applications.rq.deployment.maxReplicas }}
  advanced:
    horizontalPodAutoscalerConfig:
      behavior:
        scaleDown:
          stabilizationWindowSeconds: 30
  triggers:
  - type: aws-cloudwatch
    metricType: Value
    metadata:
      identityOwner: "operator"
      awsRegion: {{ $.Values.applications.rq.env.AWS_REGION }}
      namespace: "AWS/ElastiCache"
      dimensionName: "CacheClusterId"
      dimensionValue: {{ $.Values.applications.rq.dimensionValue }}
      metricName: "DatabaseMemoryUsagePercentage"
      metricStat: "Maximum"
      metricCollectionTime: "180"
      metricStatPeriod: "60"
      targetMetricValue: {{ .Values.applications.rq.memoryPercent | quote }}
      minMetricValue: "0"
{{- end }}
@abanfi-nozomi abanfi-nozomi added the bug Something isn't working label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant