-
Notifications
You must be signed in to change notification settings - Fork 72
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
Fix K6 Prometheus Dashboard Metrics Quantile Mismatch by Changing Aggregation to lastNotNull #170
Conversation
…put by updating aggregation to lastNotNull
7a1d11e
to
b4aa289
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
But to be honest I am not very profitiant with this specific aggregation method.
@ppcano maybe you have more experience?
@mstoykov I don't remember off top of my head. Is this change necessary for the Histogram dashboard? |
@ppcano, I’m fairly confident that this change is also necessary for the Histogram dashboard. However, when I tried using native histograms, I couldn’t get the console output to exactly match the values displayed on the dashboard, so I couldn’t confirm with certainty. Is this a known issue with the native histogram dashboard? When using trend metrics, the dashboard aligns perfectly with the console values for all quantiles. But with the native histogram dashboard, there’s an inconsistency, with values varying by different amounts. |
@dylanjpaulson thanks for informing us of your findings, and your detailed report in the community forum.
I don't know.
If it's a minor difference, it could be because: We could look at this in another PR. I noticed the difference between the terminal output and dashboard output in this example was small. This is a common issue when k6 exports data because as detailed previously: In the non-native histogram dashboard, the query is uses
Then, the returned query data is reduced using @oleiade, LGTM, I wonder how k6 does the same calculation. |
This only appears to be an issue with the Native Histograms. As shown below, the Trend Query Metrics with the LastNotNull calculation matches the log exactly. Also, the screenshot below highlights that the difference between the console and dashboard when using the mean calculation is much larger and more inconsistent when running more complex test cases with greater variation in API request duration. The screenshots below show that the console output exactly matches the dashboard when using LastNotNull, and the difference between the console and the dashboard is exaggerated when an api's request duration is more variable for example with |
Hey folks 👋🏻 Thanks for the fruitful discussions. We've discussed this topic internally, and we're happy to merge the PR as-is. Thanks a lot for your contribution @dylanjpaulson, much appreciated 🎉 🙇🏻 |
Summary
This pull request updates the k6-prometheus.json file for the K6 Prometheus dashboard. Specifically, I’ve changed the aggregation method in the Requests by URL panel to use lastNotNull for quantile calculations. Previously, the aggregation used mean, which caused the dashboard to not match the K6 console output.
I discovered this issue while comparing the K6 console output and the Grafana dashboard and also discussed it in this Grafana forum post.
Details
The problem was that the dashboard used the mean aggregation for quantiles, leading to discrepancies, particularly in cases where URL request durations varied more significantly.
By switching to the lastNotNull aggregation for quantile calculations, the dashboard now accurately reflects the values seen in the K6 console output.
Screenshots and Comparison:
Here is a comparison of the K6 console output and the dashboard with different aggregation methods applied:
Console Output:
Dashboard with mean aggregation (before fix):
Dashboard with lastNotNull aggregation (after fix)
Note that the K6 console output shows the p90 and p95 quantiles, while the dashboard shows p95 and p99. In this comparison, the p95 values can be directly compared. I have confirmed this issue across various test cases and quantile calculations.
Steps to Reproduce the Issue:
Define threshold tests for specific API endpoints to monitor their request durations. Below is an example using https://jsonplaceholder.typicode.com for the test:
Run the Test with Prometheus Remote Write Enabled:
Execute the K6 test with Prometheus remote write configured, ensuring the results are available for monitoring in your Grafana dashboard. Use the default K6 Prometheus dashboard here.
Compare Console Output and Dashboard:
After running the test:
Apply the Fix:
Change the aggregation method in the Requests by URL panel to lastNotNull for more accurate quantile calculations. Compare the updated dashboard values with the console output again to confirm the fix.