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

Incorrect calculation of metric from Prometheus #1881

Closed
BorisDr opened this issue Jun 11, 2021 · 8 comments
Closed

Incorrect calculation of metric from Prometheus #1881

BorisDr opened this issue Jun 11, 2021 · 8 comments
Labels
bug Something isn't working stale All issues that are marked as stale due to inactivity

Comments

@BorisDr
Copy link

BorisDr commented Jun 11, 2021

Report

To scale deployment based on pods qty in namespace I am using this query to Prometheus:
threshold: '10' query: sum(kube_pod_status_phase{namespace="namespace",phase="Running"}) / sum(kube_pod_status_phase{namespace="namespace",phase="Running",pod=~"workload2.*"})
While direct query to Prometheus show number 15 command kubectl describe hpa shows: "prometheus-http---prometheus-server-prometheus-svc-srv-rps" (target average value): 7 / 10

Expected Behavior

Metrics in keda hpa should be the same as in Prometheus

Actual Behavior

Metrics in keda hpa are not the same as in Prometheus

Steps to Reproduce the Problem

  1. deploy 2 workloads in any namespace. One for reference, second to scale based on 1-st workload qty.
  2. scale workload-1 up to 10 replicas
  3. create keda ScaledObject with Prometheus query like sum(kube_pod_status_phase{namespace="namespace",phase="Running"}) / sum(kube_pod_status_phase{namespace="namespace",phase="Running",pod=~"workload-2*"}) and threshold '10'
  4. scale workload-1 up to 25 replicas

Logs from KEDA operator

example

KEDA Version

2.3.0

Kubernetes Version

1.19

Platform

Amazon Web Services

Scaler Details

Prometheus

Anything else?

No response

@BorisDr BorisDr added the bug Something isn't working label Jun 11, 2021
@diegosanchez
Copy link

Do you have any news? We got similar behaviour with keda 1.5 as well.

@BorisDr
Copy link
Author

BorisDr commented Jul 5, 2021

@diegosanchez Nope, still waiting

@tomkerkhove
Copy link
Member

@zroubalik Is this just because of how we report metrics to HPA or not?

@mishamo
Copy link
Contributor

mishamo commented Jul 6, 2021

The prometheus scaler is an "average value" scaler. This means that the value you get from prometheus will be divided by the number of ready pods in the target deployment/job before being passed on to the HPA.

E.g. Your target deployment has 2 pods, prometheus returns 15 for your metric, your threshold is 10. The HPA will show 7500m/10.

Does that explain this issue, or do you think there's still a bug here?

@diegosanchez
Copy link

After several trials and errors, we (@ronalcelaya and I) bumped into a helpful piece of documentation: https://github.com/kedacore/keda/blob/v1.5.0/CREATE-NEW-SCALER.md#getmetricspecforscaling.

Could we refer to it from the documentation page?

@tomkerkhove
Copy link
Member

Definately, feel free to open a PR!

@stale
Copy link

stale bot commented Oct 13, 2021

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 Oct 13, 2021
@stale
Copy link

stale bot commented Oct 20, 2021

This issue has been automatically closed due to inactivity.

@stale stale bot closed this as completed Oct 20, 2021
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 All issues that are marked as stale due to inactivity
Projects
None yet
Development

No branches or pull requests

4 participants