Skip to content

Conversation

@kmlx
Copy link

@kmlx kmlx commented Aug 3, 2025

I've started playing with this server and received an error when running the following query in loki_query:

{
  "query": "sum by (container) (count_over_time({cluster=\"mia2\"} | detected_level=\"error\" [5m]))",
  "start": "-5m"
}

query execution failed: json: cannot unmarshal number into Go struct field LokiEntry.data.result.values of type string

This error suggests that the server can't properly serialize numeric results from aggregations. Which I have confirmed by outputting raw loki results.

Hopefully this PR solves or at least starts the discussion towards solving this issue.

In this PR we will find the following:

  • Support both Stream and Metric label fields in LokiEntry
  • Handle numeric values in addition to log strings in Values array
  • Detect timestamp format (seconds vs nanoseconds) for proper parsing
  • Update formatLokiResults to work with both log and metric query results
  • Add comprehensive tests for numeric values and metric query handling

Please have a look and let me know if any changes are needed or a different direction is preferred.

- Support both Stream and Metric label fields in LokiEntry
- Handle numeric values in addition to log strings in Values array
- Detect timestamp format (seconds vs nanoseconds) for proper parsing
- Update formatLokiResults to work with both log and metric query results
- Add comprehensive tests for numeric values and metric query handling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@CLAassistant
Copy link

CLAassistant commented Aug 3, 2025

CLA assistant check
All committers have signed the CLA.

@kmlx kmlx changed the title Support Loki query result handling for metric queries and numeric values support metric queries and numeric values Aug 3, 2025
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.

2 participants