Skip to content

Break up the huge MetricsService interface#543

Draft
aditya1702 wants to merge 9 commits intofeature/finalize-metricsfrom
feature/remove-metrics-interface
Draft

Break up the huge MetricsService interface#543
aditya1702 wants to merge 9 commits intofeature/finalize-metricsfrom
feature/remove-metrics-interface

Conversation

@aditya1702
Copy link
Contributor

What

[TODO: Short statement about what is changing.]

Why

[TODO: Why this change is being made. Include any context required to understand the why.]

Known limitations

[TODO or N/A]

Issue that this PR addresses

[TODO: Attach the link to the GitHub issue or task. Include the priority of the task here in addition to the link.]

Checklist

PR Structure

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

Phase 1 of metrics refactor: create domain-specific metric structs
(DBMetrics, RPCMetrics, IngestionMetrics, HTTPMetrics, GraphQLMetrics,
AuthMetrics) with constructors taking prometheus.Registerer. Add pool
registration functions. Rewrite metrics.go to compose sub-structs in a
top-level Metrics struct. The legacy MetricsService interface is kept
temporarily and now delegates to the new structs.
Phase 2: Replace MetricsService interface with *metrics.DBMetrics in all
11 data model structs. Call sites now use direct Prometheus API
(e.g., m.Metrics.QueryDuration.WithLabelValues(...).Observe(...)).
Add DBMetrics() bridge method to legacy MetricsService interface for
callers that still create via NewMetricsService(). Update NewModels()
signature and all wiring in serve.go, ingest.go, and loadtest/runner.go.
Phase 3: Replace MetricsService interface with *metrics.RPCMetrics in
rpcService. Call sites now use direct Prometheus API
(e.g., r.metrics.MethodCallsTotal.WithLabelValues(...).Inc()).
Add RPCMetrics() bridge method to legacy MetricsService interface.
Update all NewRPCService callers.
Phase 4: Replace MetricsService interface in all middleware:
- MetricsMiddleware: accepts *metrics.HTTPMetrics
- GraphQLFieldMetrics: accepts *metrics.GraphQLMetrics
- ComplexityLogger: accepts *metrics.GraphQLMetrics
- AuthenticationMiddleware: accepts *metrics.AuthMetrics
Update serve.go wiring to pass sub-structs from *metrics.Metrics.
Phase 5+7: Replace MetricsService in ingestion pipeline:
- IngestServiceConfig.Metrics now holds *metrics.Metrics
- ingestService uses m.appMetrics.Ingestion.* for all metric calls
- Indexer accepts *metrics.IngestionMetrics directly
- All processors accept *metrics.IngestionMetrics instead of
  MetricsServiceInterface, calling StateChangeProcessingDuration
  directly
- loadtest/runner.go and ingest/ingest.go create *metrics.Metrics
  directly instead of going through the legacy interface
Phase 6: Replace MockMetricsService + .On().Maybe() chains with real
prometheus.NewRegistry() + metrics.NewMetrics(reg) in all 23 test files.
Delete MetricsService interface, metricsService struct, mocks.go,
processors/metrics.go, and metrics_test.go (to be rewritten).
Update resolver.go to accept *metrics.Metrics directly. Remove legacy
MetricsService field from serve.go handlerDeps. Update cmd/channel_account
to use *metrics.Metrics.

Net effect: -2050 lines of mock boilerplate removed.
@aditya1702 aditya1702 changed the base branch from main to feature/finalize-metrics March 19, 2026 13:27
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.

1 participant