• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rm-hull / fuel-prices-api / 22929444349

10 Mar 2026 11:46PM UTC coverage: 26.814% (+9.2%) from 17.598%
22929444349

push

github

web-flow
feat: add fuel price distribution metrics (#31)

* feat: add fuel price distribution metrics

- Add `fuel_price_distribution_stats` SQL view to calculate price
buckets.
- Expose price distribution data via `SnapshotStatistics` model.
- Add Prometheus gauge metric `fuel_prices_govuk_api_price_distribution`
  to track sample counts per price bucket.
- Include database migration to support new distribution analytics.

* feat: refactor distribution data into buckets

Migrate `Distribution` model to use a `map[int]int` for buckets instead
of individual records per price point. This reduces payload size and
improves query grouping logic when exporting fuel price statistics.

```mermaid
graph LR
    subgraph OldStructure
    A[Row 1: Bucket 10]
    B[Row 2: Bucket 20]
    end

    subgraph NewStructure
    C[Distribution { Buckets: {10: X, 20: Y} }]
    end

    A --> C
    B --> C
```

* feat: separate distribution and snapshot stats

Split statistics logic and endpoints to allow independent querying of
snapshot and distribution data.

- Updated `FuelPricesRepository` interfaces and implementation.
- Refactored `metrics.fuelPricesGaugeCollector` to handle separate data
  fetchers.
- Moved endpoints to `/v1/fuel-prices/stats/snapshot` and
  `/v1/fuel-prices/stats/distribution`.

```mermaid
sequenceDiagram
    participant API as API Server
    participant Repo as Repository
    participant DB as SQLite DB

    API->>Repo: DistributionStats()
    Repo->>Repo: Check Cache
    Repo->>DB: Query Distribution
    DB-->>Repo: Result
    Repo-->>API: DistributionStatistics
```

* refactor: split metrics collectors into dedicated files

Separated `Snapshot` and `Distribution` metric collectors into their own
files to improve maintainability and decouple their registration logic.

```mermaid
graph TD
    subgraph metrics [metrics package]
        A[bootstrap.go] --> B[snapshot_metrics.go]
        A --> C[distribution_metrics.go]
    end
```

* chore: remove legacy snap... (continued)

126 of 162 new or added lines in 6 files covered. (77.78%)

1 existing line in 1 file now uncovered.

351 of 1309 relevant lines covered (26.81%)

0.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/api_server.go


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc