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

CloudWatch scaler not targeting the right result #6547

Open
mosheavni opened this issue Feb 13, 2025 · 0 comments
Open

CloudWatch scaler not targeting the right result #6547

mosheavni opened this issue Feb 13, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@mosheavni
Copy link

mosheavni commented Feb 13, 2025

Report

I have a ScaledObject for cloudwatch metrics (truncated irrelevant parts):

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: keda-cmpny-asset-mgmt-gateway
  namespace: cmpny-production
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: cmpny-asset-mgmt-gateway
  minReplicaCount: 10
  maxReplicaCount: 50
  pollingInterval: 10
  cooldownPeriod: 90
  fallback:
    failureThreshold: 3
    replicas: 5
  advanced:
    restoreToOriginalReplicaCount: true
    horizontalPodAutoscalerConfig:
      name: keda-cmpny-asset-mgmt-gateway
      behavior:
        scaleDown:
          stabilizationWindowSeconds: 90
          policies:
            - type: Percent
              value: 100
              periodSeconds: 10
  triggers:
    - type: aws-cloudwatch
      metadata:
        # Required: namespace
        namespace: AWS/ApplicationELB
        #with and condition for lb and tg
        expression: >-
          SELECT SUM(RequestCountPerTarget)
          FROM SCHEMA("AWS/ApplicationELB", LoadBalancer,TargetGroup)
          WHERE TargetGroup = 'targetgroup/k8s-cmpny-cmpny-xxx/xxx'
          AND LoadBalancer = 'app/k8s-cmpnyassetmgmt-xxx/xxx'
        metricName: RequestCountPerTarget
        targetMetricValue: "2300"
        minMetricValue: "0"
        awsRegion: "us-east-1"
        identityOwner: operator
        metricCollectionTime: "60"
        metricStat: "Average"
        metricStatPeriod: "30"
        metricUnit: "Count"

from the operator logs, I get these lines (after enabling debug log level):

2025-02-13T09:11:01Z  DEBUG aws_cloudwatch_scaler Received Metric Data  {"type": "ScaledObject", "namespace": "cmpny-production", "name": "keda-cmpny-asset-mgmt-gateway", "data": {"Messages":[],"MetricDataResults":[{"Id":"q1","Label":"q1","Messages":null,"StatusCode":"Complete","Timestamps":["2025-02-13T09:11:00Z"],"Values":[866.1200000000001]}],"NextToken":null,"ResultMetadata":{}}}

2025-02-13T09:11:01Z  INFO  aws_cloudwatch_scaler empty metric data received, returning minMetricValue  {"type": "ScaledObject", "namespace": "cmpny-production", "name": "keda-cmpny-asset-mgmt-gateway"}

2025-02-13T09:11:01Z  DEBUG scale_handler Getting metrics and activity from scaler  {"scaledObject.Namespace": "cmpny-production", "scaledObject.Name": "keda-cmpny-asset-mgmt-gateway", "scaler": "awsCloudwatchScaler", "metricName": "s2-aws-cloudwatch", "metrics": [{"metricName":"s2-aws-cloudwatch","metricLabels":null,"timestamp":"2025-02-13T09:11:01Z","value":"0"}], "activity": false, "scalerError": null}

2025-02-13T09:11:01Z  DEBUG scaleexecutor ScaleTarget no change {"scaledobject.Name": "keda-cmpny-asset-mgmt-gateway", "scaledObject.Namespace": "cmpny-production", "scaleTarget.Name": "cmpny-asset-mgmt-gateway"}

I can see this being executed:
https://github.com/kedacore/keda/blob/3e87999/pkg/scalers/aws_cloudwatch_scaler.go#L282
and the output is:

{
  "type": "ScaledObject",
  "namespace": "cmpny-production",
  "name": "keda-cmpny-asset-mgmt-gateway",
  "data": {
    "Messages": [],
    "MetricDataResults": [
      {
        "Id": "q1",
        "Label": "q1",
        "Messages": null,
        "StatusCode": "Complete",
        "Timestamps": ["2025-02-13T09:11:00Z"],
        "Values": [866.1200000000001]
      }
    ],
    "NextToken": null,
    "ResultMetadata": {}
  }
}

then, it looks for output.MetricDataResults which is not a key in output:
https://github.com/kedacore/keda/blob/3e87999/pkg/scalers/aws_cloudwatch_scaler.go#L286C16-L286C33
Granted, I'm no golang expert, but I can clearly see that the MetricDataResults is under data not directly under output
is it a bug and it really should check output.data.MetricDataResults instead?
what am I missing? it's not working :((

Expected Behavior

metric should not be defaulted to min value since the query does succeed.

Actual Behavior

it uses the default min value

Steps to Reproduce the Problem

everything I did is described above

Logs from KEDA operator

No response

KEDA Version

2.14.0

Kubernetes Version

1.30

Platform

Amazon Web Services

Scaler Details

CloudWatch

Anything else?

No response

@mosheavni mosheavni added the bug Something isn't working label Feb 13, 2025
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
Status: To Triage
Development

No branches or pull requests

1 participant