Skip to content

feat: collect performance metrics for regenerating cached suggestions#1141

Merged
fricklerhandwerk merged 1 commit into
NixOS:mainfrom
DarshanCode2005:app-metrics
Jul 10, 2026
Merged

feat: collect performance metrics for regenerating cached suggestions#1141
fricklerhandwerk merged 1 commit into
NixOS:mainfrom
DarshanCode2005:app-metrics

Conversation

@DarshanCode2005

Copy link
Copy Markdown
Collaborator

Related to #1002

Problem

Performance-sensitive batch jobs (cache regeneration, CVE ingestion, garbage collection etcetra) only log durations and counts to stdout/logs. Operators have no Grafana view of whether these jobs are slowing down or processing less data over time. The existing SQL exporter gives aggregate counts and recency (sql_delta, sql_matching), but not job durations or throughput.

What this PR does

Establishes the end-to-end wiring for application-level metrics from batch jobs to Grafana. Per issue scope, this is wiring + one sample metric, not full instrumentation.

Pipeline

regenerate_cached_suggestions -> cache_regeneration.prom -> node_exporter textfile collector -> Prometheus -> Grafana

Comment thread src/shared/metrics.py Fixed
@Erethon Erethon self-requested a review June 22, 2026 11:46

@Erethon Erethon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've left an early review. Besides the inline comments, can you also fix the python formatting so that CI is happy please?

Comment thread contrib/grafana-dashboard.json
Comment thread src/shared/management/commands/regenerate_cached_suggestions.py Outdated
Comment thread src/shared/metrics.py Outdated
Comment thread src/shared/metrics.py Outdated
Comment thread src/shared/metrics.py Fixed
Comment thread infra/common.nix Outdated
Comment thread infra/common.nix Outdated
Comment thread src/project/settings.py Outdated
Comment thread src/shared/metrics.py Fixed
Comment thread src/shared/metrics.py Outdated
Comment thread default.nix
Comment thread src/project/settings.py Outdated
Comment thread src/project/settings.py Outdated
Comment thread src/shared/tests/test_metrics.py Outdated
@fricklerhandwerk fricklerhandwerk requested a review from Erethon July 1, 2026 13:50
Comment thread nix/configuration.nix Outdated
EVALUATION_LOGS_DIRECTORY = mkDefault "/var/log/nix-security-tracker/evaluation";
LOCAL_NIXPKGS_CHECKOUT = mkDefault "/var/lib/nix-security-tracker/nixpkgs-repo";
CVE_CACHE_DIR = mkDefault "/var/lib/nix-security-tracker/cve-cache";
METRICS_TEXTFILE_DIR = mkDefault "/var/lib/nix-security-tracker/metrics";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This needs to go to the other settings = -- sorry, this settings jungle is a mess, I'm in the process of cleaning it up so this sort of friction doesn't occur in the future #1166

@fricklerhandwerk fricklerhandwerk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM now! @Erethon final words?

@fricklerhandwerk

fricklerhandwerk commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Apart from formatting this seems correct now. I can't merge it yet because I ran into an unrelated problem introduced by #1130, which makes it impossible to regenerate the cache and try it out the metrics locally.

Comment thread infra/common.nix Outdated
@DarshanCode2005

Copy link
Copy Markdown
Collaborator Author

Took a while to debug , but did it : )

The issue was that after @fricklerhandwerk refactored write_metrics_textfile() to accept a filename (name: str) and use METRICS_TEXTFILE_DIR from settings, the tests weren't updated. They were still passing a full Path object (tmp_path / "sample"). Since tmp_path is an absolute path, pathlib ignored METRICS_TEXTFILE_DIR entirely, so the tests wrote directly to the temporary directory instead of using the configured metrics directory. As a result, the tests still passed but weren't actually verifying the production behavior.

To fix this, the tests now use override_settings(METRICS_TEXTFILE_DIR=tmp_path) so they're isolated and don't depend on the environment. They also pass simple string filenames like "sample" and "cache_regeneration", which matches how the function is used in production, for example in regenerate_cached_suggestions.py. The implementation of src/shared/metrics.py itself didn't change. Only the tests were updated to correctly reflect the refactor.

Comment thread nix/configuration.nix
@fricklerhandwerk fricklerhandwerk changed the title feat: application metrics wiring with cache regen sample feat: collect performance metrics for regenerating cached suggestions Jul 10, 2026
This provides infrastructure and an initial example for collecting
metrics from workers, which run in separate, non-persistent processes
and therefore can't expose Prometheus exporters.

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
@fricklerhandwerk

fricklerhandwerk commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Unfortunately I can't test this locally for dumb reasons (related #1045 (comment)), but this is well-tested and I trust it will work and at worst need small fixups in the future.

@fricklerhandwerk fricklerhandwerk added this pull request to the merge queue Jul 10, 2026
Merged via the queue into NixOS:main with commit 90e8e43 Jul 10, 2026
3 checks passed
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.

4 participants