From b5a56137a25e82bc0b7a506faf60a4fc6090d496 Mon Sep 17 00:00:00 2001 From: Kevin Burek Date: Thu, 19 Oct 2023 16:27:38 -0400 Subject: [PATCH] Docs: LogQL `offset` modifier (#10960) Bring back offset modifier doc section from https://github.com/grafana/loki/pull/3455 and lost in https://github.com/grafana/loki/pull/4012 **What this PR does / why we need it**: **Which issue(s) this PR fixes**: Fixes regression from https://github.com/grafana/loki/issues/2785 **Special notes for your reviewer**: **Checklist** - [x] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [x] Documentation added - [ ] Tests updated **N/A** - [ ] `CHANGELOG.md` updated **N/A** - [ ] If the change is worth mentioning in the release notes, add `add-to-release-notes` label **N/A** - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/setup/upgrade/_index.md` **N/A** - [ ] For Helm chart changes bump the Helm chart version in `production/helm/loki/Chart.yaml` and update `production/helm/loki/CHANGELOG.md` and `production/helm/loki/README.md`. [Example PR](https://github.com/grafana/loki/commit/d10549e3ece02120974929894ee333d07755d213) **N/A** (cherry picked from commit 86455195f31185d44b328b08a2e7b4e0d3c9ae9a) --- docs/sources/query/metric_queries.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/sources/query/metric_queries.md b/docs/sources/query/metric_queries.md index 5501d2539cd37..ca4fe38b09cae 100644 --- a/docs/sources/query/metric_queries.md +++ b/docs/sources/query/metric_queries.md @@ -57,6 +57,15 @@ Examples: sum by (host) (rate({job="mysql"} |= "error" != "timeout" | json | duration > 10s [1m])) ``` +#### Offset modifier +The offset modifier allows changing the time offset for individual range vectors in a query. + +For example, the following expression counts all the logs within the last ten minutes to five minutes rather than last five minutes for the MySQL job. Note that the `offset` modifier always needs to follow the range vector selector immediately. +```logql +count_over_time({job="mysql"}[5m] offset 5m) // GOOD +count_over_time({job="mysql"}[5m]) offset 5m // INVALID +``` + ### Unwrapped range aggregations Unwrapped ranges uses extracted labels as sample values instead of log lines. However to select which label will be used within the aggregation, the log query must end with an unwrap expression and optionally a label filter expression to discard [errors]({{< relref ".#pipeline-errors" >}}).