Skip to content

LogQL: unwrap conversion functions (duration(), duration_seconds(), bytes()) are rejected #990

Closed

Description

@rita7lopes

What

None of LogQL's three unwrap conversion functions parse:

logql_parser.Parse(`rate({app="x"} | logfmt | unwrap duration(duration) [5m])`)
// 1:42: unexpected token "(" (expected "[" <integer> ("ns"|"us"|"ms"|"s"|"m"|"h") "]" ...)

logql_parser.Parse(`rate({app="x"} | logfmt | unwrap bytes(size) [5m])`)
// 1:39: unexpected token "("

logql_parser.Parse(`rate({app="x"} | logfmt | unwrap duration_seconds(d) [5m])`)
// 1:50: unexpected token "("

Bare unwrap <label> works; the conversion-function form does not.

All three are valid LogQL. Upstream Loki, pkg/logql/syntax/syntax.y:154-163:

unwrapExpr:
    PIPE UNWRAP IDENTIFIER                                            { newUnwrapExpr($3, "") }
  | PIPE UNWRAP convOp OPEN_PARENTHESIS IDENTIFIER CLOSE_PARENTHESIS  { newUnwrapExpr($5, $3) }

convOp:
    BYTES_CONV            { OpConvBytes }
  | DURATION_CONV         { OpConvDuration }
  | DURATION_SECONDS_CONV { OpConvDurationSeconds }

These matter in practice: unwrap duration(...) is the standard way to turn a text latency label into a numeric metric, which is most of what LogQL metric queries over logs are used for.

Scope

Grammar rule for unwrap <convOp>(<label>) in reader/logql/logql_parser, plus the conversion applied in the transpiler — duration/duration_seconds parse a Go duration string to seconds, bytes parses a byte size to bytes.

Credit

Found via @tsouza's parser-pin work in #925. The PR pinned unwrap duration(duration) as a must-fail case; the Loki grammar shows it should succeed — and the other two conversion functions turned out to be missing too.

Activity

  1. added a commit that references this issue on Nov 5, 2026
    122a4f0
  2. added a commit that references this issue on Nov 9, 2026
    dd45698
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions