Skip to content

Loki Reaction#292

Open
danielgerlag wants to merge 11 commits intodrasi-project:mainfrom
danielgerlag:loki-reaction
Open

Loki Reaction#292
danielgerlag wants to merge 11 commits intodrasi-project:mainfrom
danielgerlag:loki-reaction

Conversation

@danielgerlag
Copy link
Contributor

@danielgerlag danielgerlag commented Feb 21, 2026

Summary

This PR adds a new Loki reaction for Drasi and a complete local Loki + Grafana example stack demonstrating
end-to-end continuous query observability.

What’s Included

New reaction crate: drasi-reaction-loki

  • Added components/reactions/loki/ with:
    • Builder API (with_query, with_queries, endpoint/auth/labels/templates options)
    • Config types (LokiReactionConfig, QueryConfig, TemplateSpec, BasicAuth)
    • Runtime reaction implementation that pushes to Loki HTTP API (/loki/api/v1/push)
  • Supports:
    • Per-query/default Handlebars templates for ADD/UPDATE/DELETE log lines
    • Static and template-rendered labels
    • Query fan-in (single reaction subscribed to multiple queries)
    • Tenant and auth headers

Testing

  • Unit tests for builder/config/template/label behavior.
  • Ignored integration test (testcontainers + Loki) verifies INSERT/UPDATE/DELETE end-to-end push/query behavior.

Example app + dashboard stack

  • Added/expanded examples/lib/loki/ with:
    • Docker Compose for Loki + Grafana
    • Provisioned Loki datasource and dashboard
    • Example app wiring:
      • persistent-hot-sensors query:
        WHERE drasi.trueFor(s.temperature > 24, duration({ seconds: 5 }))
      • all-sensors query for full temperature history
      • Loki reaction subscribed to both queries
  • Dashboard panels:
    • Per-sensor HOT/COLD stat indicators driven by persistent-hot-sensors
    • Temperature timeseries driven by all-sensors
    • Raw event logs panel
image

Signed-off-by: Daniel Gerlag <daniel@gerlag.ca>
Signed-off-by: Daniel Gerlag <daniel@gerlag.ca>
@danielgerlag danielgerlag requested a review from a team as a code owner February 21, 2026 00:46
@danielgerlag danielgerlag requested a review from Copilot February 21, 2026 00:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new Loki reaction component to the Drasi project, enabling continuous query results to be pushed to Grafana Loki for observability and monitoring. The implementation includes a complete builder API, configuration types, template-based log rendering, and a fully-featured example application with a pre-configured Grafana dashboard.

Changes:

  • Added drasi-reaction-loki crate with builder pattern API, supporting per-query/default Handlebars templates for ADD/UPDATE/DELETE events, dynamic labels, and authentication (Bearer token, Basic auth, X-Scope-OrgID)
  • Implemented integration tests using testcontainers with Loki 3.4.3 to verify end-to-end push/query behavior
  • Created comprehensive example stack (examples/lib/loki/) with Docker Compose orchestration, provisioned Grafana dashboard demonstrating persistent hot sensor alerts and temperature history visualization

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
components/reactions/loki/src/loki.rs Core LokiReaction implementation with template rendering, label handling, and HTTP push logic
components/reactions/loki/src/lib.rs Public API with LokiReactionBuilder fluent interface
components/reactions/loki/src/config.rs Configuration types (LokiReactionConfig, BasicAuth, QueryConfig, TemplateSpec)
components/reactions/loki/Cargo.toml Package manifest with dependencies (handlebars, reqwest, chrono, testcontainers)
components/reactions/loki/tests/loki_integration_tests.rs Integration test verifying INSERT/UPDATE/DELETE event flow
components/reactions/loki/tests/loki_helpers.rs Test utilities for Loki container setup and query verification
components/reactions/loki/README.md Component documentation with usage examples and configuration reference
components/reactions/loki/CHANGELOG.md Version 0.1.0 changelog
components/reactions/loki/Makefile Build, test, integration-test, and lint targets
examples/lib/loki/main.rs Example app demonstrating MockSource → Query → Loki reaction pipeline
examples/lib/loki/docker-compose.yml Loki + Grafana stack orchestration
examples/lib/loki/grafana/dashboards/drasi-loki-overview.json Pre-configured dashboard with HOT/COLD stat panels and temperature timeseries
examples/lib/loki/grafana/provisioning/datasources/loki.yaml Loki datasource provisioning
examples/lib/loki/grafana/provisioning/dashboards/provider.yaml Dashboard provider configuration
examples/lib/loki/bootstrap_data.jsonl Initial sensor data for example
examples/lib/loki/README.md Example documentation with LogQL query patterns
examples/lib/loki/run.sh Helper script to launch stack and example
examples/lib/loki/Makefile Example build targets
examples/lib/loki/Cargo.toml Example dependencies
Cargo.toml Added loki crate to workspace members

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,32 @@
[package]
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cargo.toml file is missing the copyright header that is present in other reaction Cargo.toml files throughout the codebase (e.g., components/reactions/http/Cargo.toml). For consistency with the codebase convention, add the Apache 2.0 copyright header at the beginning of this file.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@agentofreality
Copy link
Member

I have added a 'do not merge' label to this. We need to wait until the dynamic plugin PR is merged and then update this.

danielgerlag and others added 2 commits March 5, 2026 20:49
Signed-off-by: Daniel Gerlag <daniel@gerlag.ca>
}

fn default_endpoint() -> ConfigValue<String> {
ConfigValue::Static("http://localhost:3100".to_string())

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
Signed-off-by: Daniel Gerlag <daniel@gerlag.ca>
impl Default for LokiReactionConfig {
fn default() -> Self {
Self {
endpoint: "http://localhost:3100".to_string(),

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
Signed-off-by: Daniel Gerlag <daniel@gerlag.ca>
danielgerlag and others added 3 commits March 7, 2026 00:40
Signed-off-by: Daniel Gerlag <daniel@gerlag.ca>
Add detailed logging throughout the Loki reaction plugin:
- descriptor.rs: log reaction creation with config summary
- loki.rs: log lifecycle events, result processing, template
  rendering, stream batching, HTTP push results, and shutdown

All messages prefixed with [reaction_id] where possible.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants