Reference
Log patterns
The log patterns endpoints of the HTTP API.
POST /datasources/{uid}/log-patterns
Group the lines a logs query matches over a range into patterns with counts.
A pattern is a line template with the variable tokens replaced by <*>, with the number of lines it covers, ordered by count descending then by pattern. On Loki with the pattern ingester enabled and a query that is a bare stream selector, the patterns come from Loki’s pattern index over the whole range (source loki): count sums Loki’s samples over the range, first and last are the first and last sample buckets, sample is empty and lines_sampled is 0. Otherwise, on a Loki without the pattern ingester, a Loki query with filters or stages, or ClickHouse, the server reads the newest sample lines of the query and clusters them itself (source server): count is the lines of the sample in that pattern, sample the newest of them, first and last the times of its oldest and newest sampled lines, and lines_sampled the lines read. Either way every pattern carries a trend of 30 equal buckets over the range, and a level. lines_matched is the sum of every pattern’s count, before the limit cut, and truncated says more patterns exist than limit, or that the server clustering read only its first 5,000 lines or folded lines into the nearest of its 500 clusters. The Loki query must be a log query that starts with a stream selector; the ClickHouse query one SELECT that selects Timestamp and Body, whose top-level ORDER BY and LIMIT the server replaces. The query runs with the agent tools’ limits, nothing is cached, and the call counts against the caller’s 8 in-flight query requests. Viewers and above may call it, service-account keys included. from and to take relative expressions such as now-1h, epoch milliseconds or RFC 3339 times.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
uid (required) |
path | string |
Request body
application/json, required.
| Field | Type | Description |
|---|---|---|
query (required) |
string |
The logs query the page runs. |
from (required) |
string |
|
to (required) |
string |
|
timezone |
string |
The browser’s IANA time zone, used to resolve relative times such as now/d. |
limit |
integer |
The most patterns to return. Between 1 and 100. Default 20. |
sample |
integer |
The newest lines to read when the server computes the patterns itself. Between 100 and 5000. Default 2000. |
Responses
| Status | Description | Body |
|---|---|---|
200 |
The top patterns of the query over the range. | LogPatterns |
400 |
The request is malformed or fails validation, limit or sample is out of range, or the datasource is not Loki or ClickHouse (invalid_request), or the query is longer than 64 KiB (query_too_long). |
PanelDataError |
401 |
Authentication is missing or invalid. | Error |
404 |
The datasource does not exist (not_found). |
PanelDataError |
413 |
The request body exceeds the size limit. | Error |
422 |
The query cannot run: query_invalid for a Loki metric query, a ClickHouse query that does not select Timestamp or Body, or an upstream rejection; query_forbidden, limit_exceeded or unknown_macro as for the explore query; the body carries no ref. |
PanelDataError |
429 |
The caller already has the maximum number of query requests in flight, or the server’s shared upstream call slots stayed busy for 5 seconds. | Error |
500 |
The server failed to handle the request, including a datasource call that failed without a classified cause. | PanelDataError |
502 |
The datasource is unavailable. | PanelDataError |
504 |
The datasource did not answer within the 15 second query timeout, or the request did not finish within 20 seconds. | PanelDataError |
Generated from api/openapi.yaml at c770e5e0. Report a problem.