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

Scaling Modifiers to intervene from CRON trigger #6529

Open
paragbhingre opened this issue Feb 6, 2025 · 5 comments
Open

Scaling Modifiers to intervene from CRON trigger #6529

paragbhingre opened this issue Feb 6, 2025 · 5 comments

Comments

@paragbhingre
Copy link

Hi All,

I’m currently using CRON trigger to scale up and down my resources like given below. And I would like to use scaling modifiers such that if we are under CRON time schedule and cpu utilization is less than 75% then I want to the new desiredReplicas. Would that be possible? If yes, what formula I would need?

triggers: - metadata: Value: 75 metric type: Utilization name: metric_one type: cpu - metadata: desiredReplicas: 5 start: 10 10 * * * end: 10 12 * * * time zone: America/New_York name: metric_two type: CRON

I’m new to building formulas in scalingmodifiers so tried couple of ways but didn’t work.

Thank you for your help in advanced.

@paragbhingre paragbhingre changed the title Scaling Modifiers to intervene from trigger Scaling Modifiers to intervene from CRON trigger Feb 6, 2025
@SpiritZhou
Copy link
Contributor

It is not possible to combine CPU scaler and cron scaler as the scaling modifiers do not support CPU/memory scaling. By the way, why do you want to scale when the CPU usage is less than 75%? Normally, scaling is required when CPU utilization exceeds a certain percentage.

@dogzzdogzz
Copy link
Contributor

I have similar requirement, here is my use case, I want to enable the autoscale based on rps during peak hours (8-22) only, and scale down to 0 during off-peak hours for saving cost. Is it feasible?

  minReplicaCount: 0
  maxReplicaCount: 3    
  triggers:
  - metadata:
      desiredReplicas: "1"
      start: 0 8 * * *
      end: 0 22 * * *
      timezone: Asia/Singapore
    name: cron
    type: cron
  - metadata:
      query: rps
      serverAddress: http://prometheus
      threshold: "10"
    name: rps
    metricType: AverageValue
    type: prometheus
  advanced:
    scalingModifiers:
      formula: "cron > 0 ? rps : 0"
      target: "10"
      activationTarget: "10"
      metricType: "AverageValue"

@paragbhingre
Copy link
Author

I have similar requirement, here is my use case, I want to enable the autoscale based on rps during peak hours (8-22) only, and scale down to 0 during off-peak hours for saving cost. Is it feasible?

minReplicaCount: 0
maxReplicaCount: 3
triggers:

  • metadata:
    desiredReplicas: "1"
    start: 0 8 * * *
    end: 0 22 * * *
    timezone: Asia/Singapore
    name: cron
    type: cron
  • metadata:
    query: rps
    serverAddress: http://prometheus
    threshold: "10"
    name: rps
    metricType: AverageValue
    type: prometheus
    advanced:
    scalingModifiers:
    formula: "cron > 0 ? rps : 0"
    target: "10"
    activationTarget: "10"
    metricType: "AverageValue"

I’ve the similar case too. I scale up during peak hours 9-16 but if CPU/Memory utilization is not above 75% during peak hours then I would like to scale down by half. How is that possible?

@zroubalik
Copy link
Member

@dogzzdogzz or you could use something like http scaler, to allow you scale to zero.

@paragbhingre unfortunately cpu/mem scalers can't be used in scaling modifiers

@dogzzdogzz
Copy link
Contributor

@zroubalik My workaround would be to send a PEAK_HOUR custom metric to Prometheus and leverage a scaling modifier as shown below. However, either this approach or http scaler requires a custom logic to generate and send the metric, and could be complex if we need different time window for different SO. I'd like to explore the possibility of achieving a simpler solution using KEDA's built-in support for custom scaling logic based on a specific time window.

  minReplicaCount: 0
  maxReplicaCount: 3    
  triggers:
  - metadata:
      query: peak_hour
      serverAddress: http://prometheus
      threshold: "10"
    name: peak_hour
    metricType: AverageValue
    type: prometheus
  - metadata:
      query: rps
      serverAddress: http://prometheus
      threshold: "10"
    name: rps
    metricType: AverageValue
    type: prometheus
  advanced:
    scalingModifiers:
      formula: "peak_hour > 0 ? rps : 0"
      target: "10"
      activationTarget: "10"

@JorTurFer JorTurFer moved this from To Triage to Proposed in Roadmap - KEDA Core Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Proposed
Development

No branches or pull requests

4 participants