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

Loki: add a 'since' query parameter for easier querying using relative time #7964

Merged
merged 3 commits into from
Jan 5, 2023

Conversation

slim-bean
Copy link
Collaborator

@slim-bean slim-bean commented Dec 18, 2022

Signed-off-by: Edward Welch edward.welch@grafana.com

What this PR does / why we need it:

logcli has a command line parameter called since which makes it easy to query logs relative to the current time, however this is some syntactic sugar used in logcli to calculate start and end query parameters for the query sent to Loki.

This PR adds native support for a since query parameter to make it a little easier to consume the Loki query API without having to calculate precise start/end times with every request.

This is useful if you are polling the Loki API from a third party app which doesn't let you easily build dynamic URL's and all you want to do is poll for say the last 3 hours of logs.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/upgrading/_index.md

@slim-bean slim-bean requested a review from a team as a code owner December 18, 2022 15:42
@github-actions github-actions bot added the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label Dec 18, 2022
Comment on lines 37 to 51
//{`1`, false},
//{`1 + 1`, false},
//{`{a="1"}`, false},
//{`{a="1"} |= "number: 10"`, false},
//{`rate({a=~".+"}[1s])`, false},
//{`sum by (a) (rate({a=~".+"}[1s]))`, false},
//{`sum(rate({a=~".+"}[1s]))`, false},
//{`max without (a) (rate({a=~".+"}[1s]))`, false},
//{`count(rate({a=~".+"}[1s]))`, false},
//{`avg(rate({a=~".+"}[1s]))`, true},
//{`avg(rate({a=~".+"}[1s])) by (a)`, true},
//{`1 + sum by (cluster) (rate({a=~".+"}[1s]))`, false},
//{`sum(max(rate({a=~".+"}[1s])))`, false},
//{`max(count(rate({a=~".+"}[1s])))`, false},
//{`max(sum by (cluster) (rate({a=~".+"}[1s]))) / count(rate({a=~".+"}[1s]))`, false},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, had some stuff on my working directory I didn't notice when I made this... fixed..

… range

Signed-off-by: Edward Welch <edward.welch@grafana.com>
Signed-off-by: Edward Welch <edward.welch@grafana.com>
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-target-branch/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

Copy link
Contributor

@DylanGuedes DylanGuedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just a nit/question

pkg/loghttp/params.go Show resolved Hide resolved
Copy link
Contributor

@kavirajk kavirajk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. LGTM

Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@owen-d owen-d enabled auto-merge (squash) January 5, 2023 17:32
@owen-d owen-d merged commit 2b66c6b into main Jan 5, 2023
@owen-d owen-d deleted the since-parameter branch January 5, 2023 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants