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

perf(query): Align start/end times with step #1473

Merged
merged 3 commits into from Nov 18, 2022

Conversation

Pokom
Copy link
Collaborator

@Pokom Pokom commented Nov 7, 2022

Range queries will now have their start and end times aligned with the step. This will help metric stores take better advantage of caches for queries. See
(https://promlabs.com/blog/2020/06/18/the-anatomy-of-a-promql-query#range-queries) for details on range queries.

What does this PR change?

  • Ensures the start and end times are aligned to the step for any range query.

Does this PR relate to any other PRs?

  • N\A

How will this PR impact users?

  • In theory this should reduce the amount of time metric stores need to spend processing the queries.

Does this PR address any GitHub or Zendesk issues?

How was this PR tested?

  • Added unit tests to validate the two added methods, will rely upon E2E tests from the kubecost team and am more then willing to run a generated container in production at Grafana

Does this PR require changes to documentation?

  • N\A

Have you labeled this PR and its corresponding Issue as "next release" if it should be part of the next Opencost release? If not, why not?

Range queries will now have their start and end times aligned with the
step. This will help metric stores take better advantage of caches for
queries. See
(https://promlabs.com/blog/2020/06/18/the-anatomy-of-a-promql-query#range-queries)
for details on range queries.

- closes opencost#1472

Signed-off-by: pokom <mark.poko@grafana.com>
@Pokom Pokom force-pushed the perf/align-step-range-queries branch from b94f65d to ef27ef8 Compare November 7, 2022 20:38
@AjayTripathy
Copy link
Contributor

AjayTripathy commented Nov 7, 2022

Awesome thank you! We will review this soon and are excited by the potential perf improvements!

@Pokom
Copy link
Collaborator Author

Pokom commented Nov 7, 2022

@AjayTripathy I'm going to add some unit tests for aligning the start/end times, my main concern right now is around the correctness of the time conversions. Let me know if there's anything obviously off with it while I write up some tests.

@Pokom
Copy link
Collaborator Author

Pokom commented Nov 8, 2022

I found an issue with the new method: query.isRequestStepAligned that I'm looking to resolve now. I was not sure which precision we needed on the time(started with milliseconds). I'm working on that now and some unit tests

Caught two bugs due to mismatch in seconds and milliseconds
when calculating the updated values for aligning the window.

`isRequestStepAligned` will now convert the step to seconds and then check
if the modulo of the start and end time(represented as unix time stamps)
is zero. If either of the values is not aligned, return false. Otherwise
will return true.

`alignWindow` will be called if the result of `isRequestStepAligned` is
false. This method accepts the start, end and step times. It will
convert each number to seconds and then truncate the amount time
proportional to the step function. The current implementation will round
always round down. IE, if the step is an hour then the minutes and
seconds will be removed. See the unit tests for some examples of how the
times will be aligned.

Adds basic unit tests for both methods.

Signed-off-by: pokom <mark.poko@grafana.com>
@Pokom Pokom marked this pull request as ready for review November 8, 2022 21:21
@Pokom
Copy link
Collaborator Author

Pokom commented Nov 8, 2022

@AjayTripathy I added some unit tests and fixed two bugs I found due to converting between seconds/milliseconds. Let me know when you get a chance to review the PR! I'm in the #opencost CNCF slack channel, feel free to reach out to me there as well 😄

@AjayTripathy
Copy link
Contributor

This LGTM. @nikovacevic would be great if you could take a quick look but in general I think this is low risk since it only touches QueryRange and thus only /model/allocation/compute codepaths.

@nikovacevic
Copy link
Collaborator

nikovacevic commented Nov 15, 2022

@AjayTripathy I don't think it even touches that. (All I see using QueryRange is ComputeCostDataRange -- i.e. CostDataModelRange, AggregatedCostModel -- ClusterCostsOverTime, and some health queries.)

Seems fine to me.

@AjayTripathy AjayTripathy merged commit f7c7366 into opencost:develop Nov 18, 2022
@mattray mattray added opencost OpenCost issues vs. external/downstream v1.100 labels Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
opencost OpenCost issues vs. external/downstream v1.100
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Downstream performance impacts on Metrics store
4 participants