kedacore / keda

KEDA is a Kubernetes-based Event Driven Autoscaling component. It provides event driven scale for any container running in Kubernetes
https://keda.sh
Apache License 2.0
8.51k stars 1.08k forks source link

New Relic scaler fails to parse a query invoking a 2-argument function #5414

Closed jorgeAtSama closed 3 months ago

jorgeAtSama commented 9 months ago

Report

I’m using the New Relic (NR) scaler. KEDA fails to parse this query:

SELECT percentile(duration * 1000, 95) FROM Transaction WHERE (appName = 'REPLACE_ME') AND (transactionType = 'Web') SINCE 1 MINUTE AGO

I tested it New Relic query builder and it works fine (see error below).

And this is the json response I’m getting from the NR server:

[
  {
    "results": [
      {
        "percentiles": {
          "95": 528
        }
      }
    ],
    "metadata": {
      "contents": [
        {
          "function": "percentile",
          "attribute": "duration * 1000",
          "relativeError": 0.03125,
          "thresholds": [
            95
          ]
        }
      ],
      "eventTypes": [
        "Transaction"
      ],
      "eventType": "Transaction",
      "openEnded": true,
      "messages": [],
      "beginTimeMillis": 1705672618300,
      "endTimeMillis": 1705672678300,
      "beginTime": "2024-01-19T13:56:58Z",
      "endTime": "2024-01-19T13:57:58Z",
      "guid": "abf9084f-2c73-d8ff-17cb-1f53d853af87",
      "routerGuid": "abf9084f-2c73-d8ff-17cb-1f53d853af87",
      "rawSince": "1 MINUTES AGO",
      "rawUntil": "NOW",
      "rawCompareWith": "",
      "accounts": [
        **********
      ]
    },
    "performanceStats": {
      "inspectedCount": **********,
      "responseTime": 51,
      "exceedsRetentionWindow": false
    }
  }
]

This is my scaled object:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  creationTimestamp: "2024-01-18T17:30:04Z"
  finalizers:
    - finalizer.keda.sh
  generation: 12
  labels:
    scaledobject.keda.sh/name: sh3-scaler-scaled-object
  name: sh3-scaler-scaled-object
  namespace: prod
spec:
  advanced:
    horizontalPodAutoscalerConfig:
      behavior:
        scaleDown:
          policies:
            - periodSeconds: 1200
              type: Percent
              value: 25
            - periodSeconds: 1200
              type: Pods
              value: 4
          selectPolicy: Min
          stabilizationWindowSeconds: 1800
        scaleUp:
          policies:
            - periodSeconds: 300
              type: Pods
              value: 4
            - periodSeconds: 300
              type: Percent
              value: 50
          selectPolicy: Min
          stabilizationWindowSeconds: 300
    scalingModifiers: {}
  maxReplicaCount: 8
  minReplicaCount: 4
  scaleTargetRef:
    name: sh3-web
  triggers:
    - authenticationRef:
        name: sh3-scaler-trigger-authentication # auth works well, tested with our queries.
      metadata:
        noDataError: "true"
        nrql: "SELECT percentile(duration * 1000, 95) FROM Transaction WHERE appName='REPLACE_ME' SINCE 1 MINUTE AGO"       
        threshold: "1.25"
      metricType: Value
      type: new-relic

Expected Behavior

The query should be correctly parsed and the result value used to determine the scaled object behavior. I believe the problem comes from KEDA's inability to parse the result.

Actual Behavior

The KEDA operator fails to parse the query. See logs below.

Steps to Reproduce the Problem

  1. Create a scaled object using the New Relic scaler and deploy to cluster. The trigger configuration is displayed below:
    triggers:
    - authenticationRef:
      name: sh3-scaler-trigger-authentication
      metadata:
        noDataError: "true"
        nrql: "SELECT percentile(duration * 1000, 95) FROM Transaction WHERE (appName = 'REPLACE_ME') AND (transactionType = 'Web') SINCE 1 MINUTE AGO"
        threshold: "1250"
      metricType: Value
      type: new-relic

Logs from KEDA operator

2024-01-18T17:55:12Z    ERROR   scale_handler   error getting metric for scaler {"scaledObject.Namespace": "prod", "scaledObject.Name": "sh3-scaler-scaled-object", "scaler": "newrelicScaler", "error": "query return no results SELECT percentile(duration * 1000, 95) FROM Transaction WHERE appName=********** SINCE 1 MINUTE AGO"}

KEDA Version

2.12.0

Kubernetes Version

1.27

Platform

Amazon Web Services

Scaler Details

New Relic

Anything else?

We're actually running our workloads in Kubernetes v1.28.

JorTurFer commented 9 months ago

I've checked the code and I'm not 100% sure about if percentile is a supported option for the query: https://github.com/kedacore/keda/blob/072fcf09ed0259b4e78f1173a6fc5fe9cdadcf4a/pkg/scalers/newrelic_scaler.go#L155-L171

Are you willing to open a PR supporting it?

stale[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 months ago

This issue has been automatically closed due to inactivity.