You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Loki: add __line__ and __timestamp__ to label_format (grafana#6983)
<!-- Thanks for sending a pull request! Before submitting:
1. Read our CONTRIBUTING.md guide
2. Name your PR as `<Feature Area>: Describe your change`.
a. Do not end the title with punctuation. It will be added in the changelog.
b. Start with an imperative verb. Example: Fix the latency between System A and System B.
c. Use sentence case, not title case.
d. Use a complete phrase or sentence. The PR title will appear in a changelog, so help other people understand what your change will be.
3. Rebase your PR if it gets out of sync with main
-->
**What this PR does / why we need it**:
We have the `__line__` and `__timestamp__` functions currently available in the `line_format` stage but not in the `label_format` stage. This PR fixes that.
Specifically `__timestamp__` can be valuable in a label because you can do things like
```
label_format hour_of_day=`{{__timestamp__ | date "15"}}`
```
To be able to conditionaly select log lines based on the hour of the day they were created, this can be useful for conditional alerting as an example.
**Which issue(s) this PR fixes**:
Fixesgrafana#6402
**Special notes for your reviewer**:
<!--
Note about CHANGELOG entries, if a change adds:
* an important feature
* fixes an issue present in a previous release,
* causes a change in operation that would be useful for an operator of Loki to know
then please add a CHANGELOG entry.
For documentation changes, build changes, simple fixes etc please skip this step. We are attempting to curate a changelog of the most relevant and important changes to be easier to ingest by end users of Loki.
Note about the upgrade guide, if this changes:
* default configuration values
* metric names or label names
* changes existing log lines such as the metrics.go query output line
* configuration parameters
* anything to do with any API
* any other change that would require special attention or extra steps to upgrade
Please document clearly what changed AND what needs to be done in the upgrade guide.
-->
**Checklist**
- [x] Documentation added
- [ ] Tests updated
- [x] Is this an important fix or new feature? Add an entry in the `CHANGELOG.md`.
- [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/upgrading/_index.md`
Signed-off-by: Edward Welch <[email protected]>
Copy file name to clipboardexpand all lines: CHANGELOG.md
+1
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@
5
5
#### Loki
6
6
7
7
##### Enhancements
8
+
*[6983](https://github.com/grafana/loki/pull/6983)**slim-bean**: `__timestamp__` and `__line__` are now available in the logql `label_format` query stage.
8
9
*[6821](https://github.com/grafana/loki/pull/6821)**kavirajk**: Introduce new cache type `embedded-cache` which is an in-process cache system that runs loki without the need for an external cache (like memcached, redis, etc). It can be run in two modes `distributed: false` (default, and same as old `fifocache`) and `distributed: true` which runs cache in distributed fashion sharding keys across peers if Loki is run in microservices or SSD mode.
9
10
*[6691](https://github.com/grafana/loki/pull/6691)**dannykopping**: Update production-ready Loki cluster in docker-compose
Copy file name to clipboardexpand all lines: docs/sources/logql/template_functions.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ All labels are added as variables in the template engine. They can be referenced
13
13
{{ .path }}
14
14
```
15
15
16
-
Additionally you can also access the log line using the [`__line__`](#__line__) function.
16
+
Additionally you can also access the log line using the [`__line__`](#__line__) function and the timestamp using the [`__timestamp__`](#__timestamp__) function.
17
17
18
18
You can take advantage of [pipeline](https://golang.org/pkg/text/template/#hdr-Pipelines) to join together multiple functions.
19
19
In a chained pipeline, the result of each command is passed as the last argument of the following command.
0 commit comments