Repository navigation
feat: generate openspec/specs to reflect the current state - #1106
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces new documentation that formally specifies the existing API surface, system architecture, and database data model of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds generated OpenSpec documentation for the API surface, architecture, and data model. The documentation is comprehensive and largely accurate. I've found a few minor discrepancies between the specification and the codebase, such as an incorrect priority value, a non-existent method in the API surface, a wrong method name in the architecture description, and a stated SQL convention that is not followed in practice. Please see the detailed comments for suggestions on how to align the documentation with the implementation.
|
Related Documentation 2 document(s) may need updating based on files changed in this PR: kalbasit's Space OpenTelemetry Instrumentation and MetricsView Suggested Changes@@ -113,12 +113,36 @@
Consider restricting access to the pprof port using network policies or firewall rules, and only enable profiling temporarily when investigating performance issues.
-### Metrics Collected for NAR and NarInfo File Serving
-A new observable gauge metric is available:
+### Available Metrics
-- `ncps_store_total_size_bytes`: Tracks the total size (in bytes) of all NAR files currently stored. This metric is periodically updated and provides visibility into overall storage usage. It does not have additional attributes.
+The following OpenTelemetry metrics are collected and exposed via the `/metrics` endpoint (when Prometheus export is enabled):
-This complements the existing NAR and NarInfo file serving metrics, and can be used to monitor storage growth and capacity planning.
+#### Cache Operations Metrics
+
+- `ncps_narinfo_served_total`: Counter tracking NarInfo requests served. Includes `result` (hit, miss, error), `status` (HTTP status code), and `source` (database, storage, upstream) attributes for detailed analysis of cache behavior.
+- `ncps_nar_served_total`: Counter tracking NAR file requests served. Includes `result` and `status` attributes.
+- `ncps_store_total_size_bytes`: Gauge tracking the total size (in bytes) of all NAR files currently stored. Provides visibility into overall storage usage.
+
+#### Cache Utilization Metrics
+
+- `ncps_cache_utilization_ratio`: Gauge reporting the current cache size as a ratio of the configured maximum size (0.0 to 1.0). Useful for monitoring storage capacity.
+- `ncps_cache_max_size_bytes`: Gauge reporting the configured maximum cache size in bytes.
+
+#### LRU Eviction Metrics
+
+- `ncps_lru_narinfos_evicted_total`: Counter tracking the total number of NarInfo records evicted by the LRU policy.
+- `ncps_lru_nar_files_evicted_total`: Counter tracking the total number of NAR files evicted by the LRU policy.
+- `ncps_lru_chunks_evicted_total`: Counter tracking the total number of CDC chunks evicted by the LRU policy.
+- `ncps_lru_bytes_freed_total`: Counter tracking the total bytes freed by LRU eviction operations.
+
+#### Upstream Fetch Duration Metrics
+
+- `ncps_upstream_narinfo_fetch_duration`: Histogram measuring the duration of NarInfo fetch operations from upstream caches, enabling latency analysis.
+- `ncps_upstream_nar_fetch_duration`: Histogram measuring the duration of NAR file fetch operations from upstream caches.
+
+#### Background Operations Metrics
+
+- `ncps_background_migration_objects_total`: Counter tracking the number of objects migrated from legacy storage to the database in background operations.
### Tracing Spans for NAR and NarInfo Operations
In addition to tracing spans for NAR and NarInfo operations, lock operations are now instrumented with OpenTelemetry metrics. Both local and distributed (Redis-based) lock implementations record metrics for acquisition attempts, contention, failures (with detailed reasons), retry attempts, and lock hold durations. While lock operations do not create tracing spans, the emitted metrics provide fine-grained observability into lock behavior, including contention events and failure diagnostics for distributed systems.
@@ -146,7 +170,7 @@
- targets: ['localhost:8501']
```
-You can then query metrics such as `ncps_nar_served_total` and `ncps_narinfo_served_total` in Prometheus or Grafana, filtering by `result` and `status` attributes for detailed analysis.
+You can then query metrics such as `ncps_nar_served_total` and `ncps_narinfo_served_total` in Prometheus or Grafana. For example, filter `ncps_narinfo_served_total` by `result`, `status`, and `source` attributes to analyze cache hits, misses, and error rates across different data sources (database, storage, upstream).
### Best Practices and Troubleshooting
- Exclude `/metrics` and `/healthz` from telemetry to avoid polluting observability data.Prometheus Metrics IntegrationView Suggested Changes@@ -16,24 +16,58 @@
### Metrics Tracked
-Two primary custom metrics are tracked:
+The application exposes the following categories of metrics:
-- `ncps_nar_served_total`: Counts the number of NAR (Nix ARchive) files served by the cache.
-- `ncps_narinfo_served_total`: Counts the number of NarInfo files served.
+#### Cache Serving Metrics
+
+- `ncps_nar_served_total`: Counts the number of NAR (Nix ARchive) files served by the cache. This counter includes `result` and `status` attributes.
+- `ncps_narinfo_served_total`: Counts the number of NarInfo files served. This counter includes `result`, `status`, and `source` attributes.
Both metrics are OpenTelemetry counters and are incremented each time a NAR or NarInfo is served. Each counter is enriched with attributes for detailed analysis:
- `result`: Indicates whether the request was a cache `hit` or `miss`.
- `status`: Indicates the outcome, such as `success` or `error`.
+- `source`: (narinfo only) Indicates the source of the narinfo (`database`, `storage`, or `upstream`).
Example metric output:
```
ncps_nar_served_total{result="hit",status="success"} 42
-ncps_narinfo_served_total{result="miss",status="error"} 3
+ncps_narinfo_served_total{result="miss",status="error",source="upstream"} 3
```
-These metrics allow you to monitor cache efficiency and error rates in serving NAR and NarInfo files [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/pkg/cache/cache.go#L1-L1887).
+These metrics allow you to monitor cache efficiency and error rates in serving NAR and NarInfo files.
+
+#### LRU Eviction Metrics
+
+The LRU eviction process tracks the following counters to monitor cache cleanup operations:
+
+- `ncps_lru_narinfos_evicted_total`: Count of narinfos evicted by the LRU process.
+- `ncps_lru_nar_files_evicted_total`: Count of NAR files evicted by the LRU process.
+- `ncps_lru_chunks_evicted_total`: Count of chunks evicted by the LRU process (relevant when CDC is enabled).
+- `ncps_lru_bytes_freed_total`: Total bytes freed by LRU eviction operations.
+
+These metrics help track cache cleanup activity and understand how effectively the LRU policy is managing disk space.
+
+#### Cache Utilization Metrics
+
+- `ncps_cache_utilization_ratio`: Gauge indicating the current cache utilization as a ratio (current size / max size).
+- `ncps_cache_max_size_bytes`: Gauge showing the maximum configured cache size in bytes.
+
+These gauges provide real-time insight into cache capacity and usage.
+
+#### Upstream Fetch Duration Metrics
+
+- `ncps_upstream_narinfo_fetch_duration`: Histogram tracking the duration of upstream narinfo fetch operations.
+- `ncps_upstream_nar_fetch_duration`: Histogram tracking the duration of upstream NAR fetch operations.
+
+These histograms enable analysis of upstream performance and network latency.
+
+#### Background Operations Metrics
+
+- `ncps_background_migration_objects_total`: Count of objects (narinfos) migrated from legacy storage to the database in the background.
+
+This counter tracks the progress of background migration operations for legacy narinfo storage [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/pkg/cache/cache.go#L1-L1887).
### Instrumentation with OpenTelemetry
@@ -49,11 +83,11 @@
curl http://localhost:8080/metrics
```
-The response will include all registered metrics in Prometheus format, including `ncps_nar_served_total` and `ncps_narinfo_served_total` with their respective labels and values. These can be scraped and visualized using Prometheus and Grafana or used for alerting and analysis.
+The response will include all registered metrics in Prometheus format, including cache serving metrics, LRU eviction counters, cache utilization gauges, upstream fetch histograms, and background migration counters. These can be scraped and visualized using Prometheus and Grafana or used for alerting and analysis.
### Notes
- The Prometheus metrics endpoint is independent of other OpenTelemetry exporters (such as gRPC or stdout). Enabling Prometheus replaces the default MeterProvider with one that exports exclusively to Prometheus.
-- The `/metrics` endpoint is excluded from request tracing and other telemetry middleware to avoid double instrumentation and unnecessary overhead.
+- The `/metrics` endpoint is never traced to avoid double instrumentation and unnecessary overhead.
For more details on the implementation, see the relevant sections in the [source code](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/cmd/serve.go#L26-L266).Note: You must be authenticated to accept/decline updates. |
Have Claude create the specs by reverse engineer the existing repository.
e458605 to
5e02c48
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1106 +/- ##
========================================
- Coverage 6.38% 5.04% -1.34%
========================================
Files 6 6
Lines 329 436 +107
========================================
+ Hits 21 22 +1
- Misses 304 410 +106
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Have Claude create the specs by reverse engineer the existing
repository.