Query logs from Grafana Loki within a time range

Execute LogQL queries against Loki over a specified time range. Supports both log queries (returning stream responses) and metric queries (returning matrix responses).

yaml
type: "io.kestra.plugin.grafana.loki.QueryRange"

Query error logs from the last hour using relative time

yaml
id: query_loki_errors
namespace: company.team

tasks:
  - id: fetch_errors
    type: io.kestra.plugin.grafana.loki.QueryRange
    url: http://localhost:3100
    query: '{job="api"} |= "error"'
    since: 1h
    limit: 1000

Query with authentication and absolute time range

yaml
id: query_loki
namespace: company.team

tasks:
  - id: fetch_logs
    type: io.kestra.plugin.grafana.loki.QueryRange
    url: https://loki.example.com
    token: "{{ secret('LOKI_TOKEN') }}"
    tenantId: team-a
    query: '{namespace="production", container="frontend"}'
    start: "2024-01-01T00:00:00Z"
    end: "2024-01-01T23:59:59Z"
    limit: 5000
    direction: BACKWARD

Metric query with step interval

yaml
id: loki_test
namespace: company.team

tasks:
  - id: query_metrics
    type: io.kestra.plugin.grafana.loki.QueryRange
    url: http://localhost:3100
    query: 'rate({job="api"}[5m])'
    start: "{{ now() | dateAdd(-6, 'HOURS') }}"
    step: 1m
Properties

LogQL query

The LogQL query to execute (e.g., '{job="api"} |= "error"')

Loki base URL

The base URL of your Loki instance (e.g., http://localhost: 3100 or https://logs.example.com)

Authentication token

Bearer token for authentication if Loki is secured

Default 30

Connection timeout

HTTP connection timeout in seconds

Default BACKWARD
Possible Values
FORWARDBACKWARD

Direction

Determines the sort order of logs. Use FORWARD for ascending order, or BACKWARD for descending order. Defaults to BACKWARD.

End time

The end time for the query as a nanosecond Unix epoch or another supported format (e.g., RFC3339). Defaults to now.

Interval

Entries are returned at the specified interval. Only applies to log queries that return stream responses (e.g., '1m', '30s').

Default 100

Limit

Maximum number of entries to return

Default 60

Read timeout

HTTP read timeout in seconds

Since

Duration to calculate start time relative to end time (e.g., '1h', '30m'). Alternative to specifying absolute start time.

Start time

The start time for the query as a nanosecond Unix epoch or another supported format (e.g., RFC3339). Defaults to one hour ago.

Step

Query resolution step width in duration format (e.g., '1m', '30s') or seconds. Applies only to metric queries that return matrix responses.

Grafana Loki Tenant ID

X-Scope-OrgID header value for multi-tenant Loki setups

SubType object

List of log entries

Each entry contains timestamp, labels, and log line

Result type

Type of result returned by Loki (streams or matrix)

Total number of log entries retrieved from Loki range query