Skip to content

LogQL Pipeline Formatting (label_format, line_format, decolorize) #14

@frisbeeman

Description

@frisbeeman

Overview

Implement LogQL pipeline formatting stages that transform labels and log lines using Go template syntax.

Parent Issue

Part of #6 (Query Service Implementation), delegated from #8 (LogQL Query Compiler).

Context

Pipeline formatting stages allow users to transform labels and log lines. Currently, all formatting stages are no-op placeholders that return the DataFrame unchanged.

Requirements

Formatting Stages to Implement

Stage Syntax Description
label_format | label_format new="{{.old}}" Create/modify labels using Go templates
line_format | line_format "{{.level}}: {{.message}}" Reformat the entire log line
decolorize | decolorize Remove ANSI color codes from log lines

Example Queries

{job="app"} | label_format level_upper="{{.level | ToUpper}}"
{job="app"} | line_format "{{.timestamp}} [{{.level}}] {{.message}}"
{job="app"} | decolorize

Implementation Approach

  1. Add gtmpl crate for Go template parsing and rendering

  2. Create UDFs in src/query/logql/datafusion/udf.rs:

    • label_format_template(template: String, ...labels) -> String
    • line_format_template(template: String, ...labels) -> String
    • decolorize(text: String) -> String (ANSI regex removal)
  3. Update planner in src/query/logql/datafusion/planner.rs:

    • Replace no-op implementations in apply_label_format(), apply_line_format(), apply_decolorize()

Acceptance Criteria

  • label_format creates/modifies labels using Go template syntax
  • line_format transforms log lines using Go template syntax
  • decolorize removes ANSI escape sequences
  • Go template functions (ToUpper, ToLower, Replace, etc.) are supported
  • Template errors are handled gracefully
  • Unit tests for each formatting stage
  • Integration tests with full LogQL queries

Dependencies

  • gtmpl crate for Go template parsing

Technical References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions