Skip to content

Commit

Permalink
feat: support simple selection of labels in json expr parser (#6151)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityacs committed May 16, 2022
1 parent c6b7752 commit c6af640
Show file tree
Hide file tree
Showing 4 changed files with 396 additions and 168 deletions.
12 changes: 12 additions & 0 deletions docs/sources/logql/log_queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ The **json** parser operates in two modes:
"server_list" => `["129.0.1.1","10.2.1.3"]`
"headers" => `{"Accept": "*/*", "User-Agent": "curl/7.68.0"}`
```

If the label to be extracted is same as the original JSON field, expression can be written as just `| json <label>`

For example, to extract `servers` fields as label, expression can be written as following

`| json servers` will extract:

```kv
"servers" => `["129.0.1.1","10.2.1.3"]`
```

Note that `| json servers` is same as `| json servers="servers"`

#### logfmt

Expand Down
1 change: 1 addition & 0 deletions pkg/logql/syntax/expr.y
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ labelFilter:

jsonExpression:
IDENTIFIER EQ STRING { $$ = log.NewJSONExpr($1, $3) }
| IDENTIFIER { $$ = log.NewJSONExpr($1, $1) }

jsonExpressionList:
jsonExpression { $$ = []log.JSONExpression{$1} }
Expand Down
Loading

0 comments on commit c6af640

Please sign in to comment.