Skip to main content

Grafana Cloud Loki ExecModule

Overview​

GrafanaCloudLokiModule runs a read-only LogQL range query against Grafana Cloud Logs. Use it to collect specific log events around a deployment or alert. The result retains stream labels and nanosecond timestamps, so a downstream workflow can identify which service emitted each event and when it happened.

Usage​

  1. Copy the query origin and numeric Loki instance ID from the Grafana Cloud stack. Create a Cloud Access Policy token scoped to logs:read for that stack.
  2. Ask a deployment administrator to approve the exact Loki query hostname for outbound workflow traffic.
  3. Create a READY connection in the Integration Account Console and select it in Workflow Studio under General > Connection.
  4. Map the start and end of the incident or rollout window. Use a label selector to scope the service, then filter for the log lines you need.
  5. Check status before consuming results. A successful query with zero matching entries is separate from a provider error. Check limitReached when the workflow needs to know whether to query a narrower interval.

Inputs​

InputTypePurpose
querystringRequired LogQL expression that returns log streams, up to 4,096 characters.
startEpochSecondsintegerRequired inclusive Unix start time in seconds.
endEpochSecondsintegerRequired exclusive Unix end time in seconds. The window may span up to 24 hours.
limitintegerMaximum number of log entries requested. Defaults to 100 and accepts 1–1,000.
directionstringUse backward for newest first or forward for oldest first within each stream. Defaults to backward.

Outputs​

OutputTypeMeaning
statusstringsuccess or error.
resultTypestringstreams for a successful log query.
resultarrayLog streams with a stream label map and values containing timestamp and log-line pairs. Loki may also return structured metadata as a third item.
countintegerNumber of log entries across all returned streams.
limitReachedbooleanThe result reached the requested limit. Narrow the query if additional matches may matter.
httpStatusintegerProvider HTTP status when available.
attemptsintegerNumber of provider request attempts.
errorobjectSanitized failure details when the query fails.

Keep timestamps as strings until you use a representation that can hold nanosecond precision. Treat log lines as service data. Keep them within workflow destinations approved for that data and apply any downstream filtering before copying them into a shared incident or notification.

IntegrationAccount Requirements​

Use a READY IntegrationAccount dedicated to Grafana Cloud Loki. Set accountId to the exact HTTPS query origin with no API path. Store the numeric Loki instance ID in username and the Cloud Access Policy token in the encrypted password field. Keep credentials out of LogQL, workflow mappings, and downstream output.

Configuration​

Mapped query, time window, limit, and direction values override saved defaults. The module requires a publicly resolving Grafana Cloud Loki origin on HTTPS port 443. The operator must approve its exact hostname via valkyrai.security.network.allowed-destinations or VALKYRAI_SECURITY_NETWORK_ALLOWED_DESTINATIONS. It uses the platform’s guarded route, standard TLS verification, and no redirects. Set maxAttempts in the saved module configuration. It defaults to two attempts and accepts one to three.

Operations​

The module calls GET /loki/api/v1/query_range, passing the LogQL expression, the time window converted to Unix nanoseconds, the limit, and the direction. It supports stream results from log queries. Use a separate metrics connector for a LogQL workflow that requires metric-series processing.

Errors and Failure Modes​

Invalid inputs, an unready account, or a denied destination fail before sending a query. Check the Grafana Cloud stack and token scope if the provider rejects the credentials. If Loki rejects the expression, test the selector and line filter against a short window. Errors omit the submitted query, the provider error body, and account credentials.

Transient connection failures and HTTP 429, 502, 503, and 504 may retry within the configured attempt budget. Each request attempt has a 20-second timeout. Use a smaller window and more specific label selectors when the query is slow or returns a response larger than 5 MiB. When a provider asks the module to wait longer than five seconds, the module returns a retryable failure for the workflow to handle.

Example​

A release workflow gathers matching checkout error events during a five-minute rollout window.

{
"query": "{service_name=\"checkout\"} |= \"payment timeout\"",
"startEpochSeconds": 1794009600,
"endEpochSeconds": 1794009900,
"limit": 20,
"direction": "backward"
}

A successful result with one matching line might contain:

{
"status": "success",
"resultType": "streams",
"count": 1,
"limitReached": false,
"result": [
{
"stream": {"service_name": "checkout", "environment": "production"},
"values": [["1794009720000000000", "payment timeout contacting upstream gateway"]]
}
]
}

Map the count and service label into an incident review step. A workflow that also compares error metrics can use this log query to collect diagnostic context for the same period.

Notes​

  • Pagination. Loki supplies no continuation cursor for this operation. If the result hits the limit, split the window or narrow the selector and account for timestamp boundaries.
  • Rate limits. Grafana Cloud limits depend on the stack. Prefer narrow selectors and short intervals, especially in workflows triggered by multiple alerts.
  • API limits. This module covers bounded log stream queries on Grafana Cloud. Ingestion, tailing, log administration, and self-hosted Loki endpoints are outside its scope.
  • Idempotency and destructive behavior. The query leaves Loki resources unchanged. Late ingestion and retention can change the results of a repeated query.

See the Loki HTTP API for query semantics and Grafana Cloud Logs authentication for connection setup.