Skip to content

Conversation

littlepangdi
Copy link
Contributor

@littlepangdi littlepangdi commented Sep 25, 2025

What this PR does / why we need it:
Populates the querier stats with data derived from the query range response stats. This change allows the frontend component to access and log stats information passed through the context, providing a more comprehensive view of query performance.

Which issue(s) this PR fixes:
Fixes #11264 , fix zero value in "query stats" logs.

Since querier_stats.Stats is set to context here but never updated before log,we'll always get zero values in logs.
The code referenced in the issue #11264 is very clear, so I will not repeat it here.

Before fixing:

once -frontend.query-stats-enabled option is enabled, followed logs will be printed. query_wall_time_seconds,fetched_series_count,fetched_series_count always report 0

level=info ts=2025-09-25T08:02:18.065274Z caller=handler.go:323 org_id=xxx msg="query stats" component=query-frontend method=GET status=200 path=/loki/api/v1/query_range response_time=1.574975625s **query_wall_time_seconds=0 fetched_series_count=0 fetched_chunks_bytes=0** param_direction=backward param_query="{app_name=\"hlth-async-handler\"}" param_limit=1 param_start=1758542240865000000 param_end=1758545840865000000 header_x_grafana_user=huxiang header_user_agent=Grafana/8.5

After this fixing:

query_wall_time_seconds,fetched_series_count,fetched_series_count will be accurate values as result.stats.

level=info ts=2025-09-25T07:47:56.16836Z caller=handler.go:323 org_id=xxx msg="query stats" component=query-frontend method=GET status=200 path=/loki/api/v1/query_range response_time=789.782583ms query_wall_time_seconds=0.959356417 fetched_series_count=5052 fetched_chunks_bytes=762099 param_start=1758542240865000000 param_end=1758545840865000000 param_direction=backward param_query="xxx" param_limit=1 header_x_grafana_user=huxiang header_user_agent=Grafana/8.5

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

Populates the querier stats with data derived from the query range response stats.
This change allows the frontend component to access and log stats information passed through the context,
providing a more comprehensive view of query performance.
@littlepangdi littlepangdi requested a review from a team as a code owner September 25, 2025 07:53
@littlepangdi littlepangdi changed the title fix: Updates querier stats based on response stats(#11264) fix: query stats always logs zero value(#11264) Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fetched_chunks_bytes, query_wall_time_seconds & fetched_series_count always report 0
1 participant