Skip to content

Record query timings and top searched repos/orgs for Grafana - #1252

Draft
EngCaioFonseca wants to merge 4 commits into
devfrom
query-metrics
Draft

EngCaioFonseca wants to merge 4 commits into
devfrom
query-metrics

Conversation

@EngCaioFonseca

@EngCaioFonseca EngCaioFonseca commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Change Description

Closes #1247

Records how long each query takes at each pipeline stage, and which repos and orgs users search for most, in a small dedicated Redis (redis-metrics). Both are shown in a Grafana dashboard provisioned from this repo. This uses Redis with Grafana reading it directly, so no Prometheus or exporter is needed.

  • Stages:

    Stage What it times
    augur_sql source query plus fetches
    cache_write inserts, bookkeeping and commit
    cache_read retrieve_from_cache
    queue_wait dispatch to task start
    e2e dispatch to task success
  • Search counts

Counted only on a search-button click, not on page load.
An org search counts the org, not its repos. User groups are not recorded.
Storage: one TimeSeries per stage and query, kept for 30 days, plus sorted sets of repo and org counts for all time, per day, and the last 30 days. See docs/query-metrics.md.

  • Services: both are behind the metrics profile, so the default stack and CI are unchanged.

  • redis-metrics: Redis 8 with TimeSeries, running as a non-root user, capped at 256 MB, on a persistent volume.
    grafana 13.3.1:
    It reaches Redis through the redis-datasource plugin.
    It is bound to 127.0.0.1, with anonymous access off.
    It won't start without GF_SECURITY_ADMIN_PASSWORD.

Production enablement is a separate change in oss-aspen/infra-ansible (it adds the two services to the 8Knot compose template). The top-repos and top-orgs lists are meant to feed the cache pre-warm list.

  • Dashboard: the top 15 repos and orgs (last 30 days and all time). For each stage, a latency trend and a p50/p95/max/count table per query.

scripts/seed_query_metrics.sh loads sample data for trying it locally. Production enablement is in oss-aspen/infra-ansible#23. The top lists are meant to drive cache pre-warming.

How it was verified

Run locally with Podman, using a real source database for the app checks.

Generative AI disclosure

Please select one option:

  • This contribution was NOT assisted or created by Generative AI tools.
  • This contribution was assisted or created by Generative AI tools.

If AI tools were used, please provide details below:
- What tools were used? Claude Opus 5.5, Claude Fable 5.2; GLM 5.3; Gemini 4 Neon
- How were these tools used? Orchestration: spec design, coding, review and verification
- Did you review these outputs before submitting this PR? yes.

Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Comment thread 8Knot/query_metrics.py
Comment on lines +36 to +37
except Exception:
pass
Comment thread 8Knot/query_metrics.py
Comment on lines +46 to +47
except Exception:
pass
@EngCaioFonseca EngCaioFonseca self-assigned this Nov 23, 2026
@EngCaioFonseca EngCaioFonseca added the infrastructure issues pertaining to production operations or running 8Knot in prod (configuration, architecture) label Nov 23, 2026
@EngCaioFonseca EngCaioFonseca moved this from Backlog to In Progress in CollectOSS + 8Knot WG Feature Roadmap Nov 23, 2026

@MoralCode MoralCode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses Redis with Grafana reading it directly, so no Prometheus or exporter is needed.

I'm curious why this decision was made this particular way. IMO keeping a clean network boundary layer between 8knot and grafana helps allow people to customize their monitoring setup, like how we want one dashboard for both our instances.

Keeping grafana stuff in a separate repo also helps keep each repo focused in its purpose, be less confusing to newcomers, and help keep AI tools more focused/use tokens more effectively.

# A server-side cursor keeps large results out of worker memory.
query_start = time.perf_counter()
with collectoss_conn.execution_options(yield_per=server_pagination).exec_driver_sql(query, vars) as result:
augur_sql_seconds += time.perf_counter() - query_start

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line creates a new variable with the old Augur name. Should be updated to collectoss or removed/made generic

Comment thread docker-compose.yml
restart: always

# query timing and search counts, read by Grafana (docs/query-metrics.md)
redis-metrics:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a performance penalty for having an entirely new redid instance rather than reusing the one we have somehow? This makes me think of Josh's advice to not have two postgres instances due to overhead

Comment thread docker-compose.yml
- GF_AUTH_ANONYMOUS_ENABLED=false
- GF_USERS_ALLOW_SIGN_UP=false
volumes:
- ./grafana/provisioning:/etc/grafana/provisioning:ro

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already provision dashboards in the CollectOSS-monitoring repo. This was part of why I was suggesting 8knot just make a metrics endpoint available for Prometheus/grafana to query, so the dashboard can be maintained and published separately so we can keep it in a central dashboard, rather than creating a third grafana instance.

@github-project-automation github-project-automation Bot moved this from In Progress to In Testing in CollectOSS + 8Knot WG Feature Roadmap Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infrastructure issues pertaining to production operations or running 8Knot in prod (configuration, architecture)

Projects

Development

Successfully merging this pull request may close these issues.

Logging of Query times

3 participants