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

Fallback is incorrect when using multiple triggers with scalingModifiers #5371

Open
Tracked by #5275
RRethy opened this issue Jan 13, 2024 · 3 comments
Open
Tracked by #5275
Assignees
Labels
bug Something isn't working stale-bot-ignore All issues that should not be automatically closed by our stale bot

Comments

@RRethy
Copy link

RRethy commented Jan 13, 2024

Report

When using 2 or more triggers and a scalingModifier (e.g. max(trigger_1, trigger_2)), if all triggers fail then the amount that gets scaled to is incorrect.

Expected Behavior

I would expect the fallback to scale to the amount specified in the .spec.fallback.replicas field.

Actual Behavior

It scales to t * n where t is the number of triggers and n is the .spec.fallback.replicas.

Steps to Reproduce the Problem

You can reproduce it with the following minimal manifest:

I also put this into a repo which includes a script to spin up a kind cluster to reproduce this, https://github.com/RRethy/keda-issue-minimum-reproducible.

After applying this manifest, the deployment will eventually get scaled to 24 even though it should scale to 12.

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: myscaledobject
  namespace: foobar
spec:
  scaleTargetRef:
    kind: Deployment
    name: mydeployment
  fallback:
    failureThreshold: 4
    replicas: 12
  advanced:
    scalingModifiers:
      formula: "max(trigger_1, trigger_2)"
      metricType: AverageValue
      target: "1"
      activationTarget: "0"
  pollingInterval: 30
  minReplicaCount: 3
  maxReplicaCount: 30
  triggers:
  - type: prometheus
    name: trigger_1
    metricType: AverageValue
    metadata:
      serverAddress: http://fake.svc.cluster.local:9090
      threshold: "1"
      activationThreshold: "0"
      query: >
        max(mymetric1{}[2m])
  - type: prometheus
    name: trigger_2
    metricType: AverageValue
    metadata:
      serverAddress: http://fake.svc.cluster.local:9090
      threshold: "1"
      activationThreshold: "0"
      query: >
        max(mymetric2{}[2m])
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mydeployment
  namespace: foobar
  labels:
    app: busybox
spec:
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
    spec:
      containers:
      - name: busybox
        image: busybox:latest
        ports:
        - containerPort: 8080

Logs from KEDA operator

The logs are long but I put them into the above repo, https://github.com/RRethy/keda-issue-minimum-reproducible/blob/master/keda-operator-logs.txt. There are also logs for the other components in that repo.

KEDA Version

2.12.1

Kubernetes Version

1.27

Platform

Other

Scaler Details

Prometheus

Anything else?

From a glance at the code, it seems to want to ignore the scalingModifiers if there is a fallback active, but this seems like the wrong intention even if it did work. I would expect a scalingModifier with a formula of max(trigger_1, trigger_2) to become max(12, 12) and then 12 (assuming the fallback is 12).

cc. @gauron99

@RRethy RRethy added the bug Something isn't working label Jan 13, 2024
@zroubalik zroubalik mentioned this issue Jan 15, 2024
25 tasks
@zroubalik
Copy link
Member

@gauron99 is looking at this

@zroubalik zroubalik moved this from To Triage to In Progress in Roadmap - KEDA Core Jan 15, 2024
@gauron99
Copy link
Contributor

gauron99 commented Jan 21, 2024

It looks to me like immediately upon deployment the scaled deployment is scaled to fallback value and doesnt "wait" to reach the failureThreshold. Once the threshold is reached the number of replicas is doubled. This has to do with the number of triggers (during my testing I increased the number and the replica number would eventually increase accordingly. It would usually switch between multiples of the fallback value; up to max of number of triggers * fallback value).

On HPA request for metrics (in scaleHandler), the values are all correct as they should be and do not match this bug. However the fallback code is executed for each metric and I think it has to do with parallelization that was introduced, thats the only thing I see that could be the culprit here (i can be wrong ofcourse). Furthermore in scaleExecutor: it looks to me like its scaling to fallback value even before the failureThreshold is reached (this would explain the immediate scale to fallback at the very start).

This is probably related #5359. (and thanks to Jorge for help)

Copy link

stale bot commented Mar 23, 2024

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 stale bot added the stale All issues that are marked as stale due to inactivity label Mar 23, 2024
@zroubalik zroubalik added stale-bot-ignore All issues that should not be automatically closed by our stale bot and removed stale All issues that are marked as stale due to inactivity labels Mar 27, 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 stale-bot-ignore All issues that should not be automatically closed by our stale bot
Projects
Status: In Progress
Development

No branches or pull requests

3 participants