Skip to content

Commit

Permalink
fixup! Add jsonpath support
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
  • Loading branch information
chaudum committed Dec 18, 2024
1 parent aae4ffe commit 01d71ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/distributor/field_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func getValueUsingJSONParser(line []byte, hints []string) []byte {
if err != nil {
continue
}
l, _, _, err := jsonparser.Get(line, log.JSONPathsToStrings(parsed)...)
l, _, _, err := jsonparser.Get(line, log.JSONPathToStrings(parsed)...)
if err != nil {
continue
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/logql/log/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func NewJSONExpressionParser(expressions []LabelExtractionExpr) (*JSONExpression
}

ids = append(ids, exp.Identifier)
paths = append(paths, JSONPathsToStrings(path))
paths = append(paths, JSONPathToStrings(path))
}

return &JSONExpressionParser{
Expand All @@ -581,17 +581,17 @@ func NewJSONExpressionParser(expressions []LabelExtractionExpr) (*JSONExpression
}, nil
}

func JSONPathsToStrings(paths []interface{}) []string {
stingPaths := make([]string, 0, len(paths))
func JSONPathToStrings(paths []interface{}) []string {
stringPaths := make([]string, 0, len(paths))
for _, p := range paths {
switch v := p.(type) {
case int:
stingPaths = append(stingPaths, fmt.Sprintf("[%d]", v))
stringPaths = append(stringPaths, fmt.Sprintf("[%d]", v))
case string:
stingPaths = append(stingPaths, v)
stringPaths = append(stringPaths, v)
}
}
return stingPaths
return stringPaths
}

func (j *JSONExpressionParser) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]byte, bool) {
Expand Down

0 comments on commit 01d71ce

Please sign in to comment.