Skip to content

feat: api and indexer instrumented with metrics#221

Open
dhyaniarun1993 wants to merge 30 commits into
mainfrom
feat/api-indexer-metrics
Open

feat: api and indexer instrumented with metrics#221
dhyaniarun1993 wants to merge 30 commits into
mainfrom
feat/api-indexer-metrics

Conversation

@dhyaniarun1993
Copy link
Copy Markdown
Member

@dhyaniarun1993 dhyaniarun1993 commented Apr 17, 2026

Closes #205

@dhyaniarun1993 dhyaniarun1993 self-assigned this Apr 17, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 10.06787% with 795 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@14e507f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pkg/indexer/store/instrumented.go 0.00% 213 Missing ⚠️
pkg/ethrpc/store/instrumented.go 0.00% 117 Missing ⚠️
pkg/userstore/instrumented.go 0.00% 93 Missing ⚠️
pkg/indexer/client/instrumented.go 0.00% 63 Missing ⚠️
pkg/app/indexer/server.go 0.00% 46 Missing ⚠️
pkg/app/api/server.go 0.00% 41 Missing ⚠️
pkg/app/http/metrics.go 0.00% 25 Missing ⚠️
pkg/app/http/middleware.go 0.00% 22 Missing ⚠️
pkg/ethrpc/store/metrics.go 0.00% 22 Missing ⚠️
pkg/indexer/store/metrics.go 0.00% 22 Missing ⚠️
... and 11 more

❌ Your patch status has failed because the patch coverage (10.06%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #221   +/-   ##
=======================================
  Coverage        ?   29.67%           
=======================================
  Files           ?      147           
  Lines           ?    11008           
  Branches        ?        0           
=======================================
  Hits            ?     3267           
  Misses          ?     7471           
  Partials        ?      270           
Flag Coverage Δ
unittests 29.67% <10.06%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/config/config.go 71.18% <ø> (ø)
pkg/ethrpc/miner/metrics.go 100.00% <100.00%> (ø)
pkg/ethrpc/miner/miner.go 97.84% <100.00%> (ø)
pkg/indexer/engine/metrics.go 100.00% <100.00%> (ø)
pkg/indexer/engine/processor.go 67.06% <100.00%> (ø)
pkg/relayer/engine/metrics.go 94.95% <100.00%> (ø)
internal/metrics/metrics.go 0.00% <0.00%> (ø)
pkg/cantonsdk/client/options.go 0.00% <0.00%> (ø)
pkg/relayer/store/metrics.go 0.00% <0.00%> (ø)
pkg/app/relayer/server.go 0.00% <0.00%> (ø)
... and 17 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements comprehensive Prometheus metrics instrumentation across the API server, indexer, relayer, and Canton SDK, including dedicated monitoring endpoints and updated deployment configurations. It also introduces a robust suite of end-to-end tests covering user registration, JSON-RPC facades, and bridge deposit/withdrawal flows. Feedback highlights the need to remove an outdated compile-time guard in the API middleware, address a risky type assertion in the instrumented indexer store to prevent potential panics, and refactor the indexer's monitoring server initialization to ensure architectural consistency across the codebase.

Comment thread pkg/app/api/middleware.go Outdated
Comment thread pkg/indexer/store/instrumented.go Outdated
Comment thread pkg/app/indexer/server.go
Base automatically changed from feat/docker-compose-monitoring to main April 17, 2026 09:05
@dhyaniarun1993 dhyaniarun1993 marked this pull request as ready for review April 17, 2026 11:06
Resolved conflicts in:
- pkg/app/api/server.go: kept main's initServices refactor and new
  AcceptWorker/submitter wiring while layering this branch's metrics
  registerer through evmStore, transferCache, miner, HTTP middleware,
  and the optional metrics server (serveAll).
- pkg/app/http/middleware.go: combined RequestMetricsMiddleware (this
  branch) and CORSMiddleware (main) into a single file.
- pkg/app/indexer/server.go: kept main's multi-template fetcher
  (offers + holdings) and wrapped the resulting store/processor in
  this branch's Prometheus metrics.
- pkg/cantonsdk/client/client.go: kept main's net/http import (used
  by the new registry client).
- pkg/config/config.go: kept Monitoring on APIServer (this branch)
  alongside main's TokenProvider/AcceptWorker/SkipWhitelistCheck/
  CORSOrigins fields.

Carried this branch's instrumentation forward by adding pass-through
metrics for the new main methods: InsertHolding/TakeHolding,
InsertPendingOffer/MarkOfferAccepted, ListPendingOffersForParty/
ListAllPendingOffers, ListCustodialUsers, GetMempoolEntriesByStatus,
GetPendingOffersForParty/GetAllPendingOffers (indexer HTTP client).
Updated the indexer processor's per-event-type counters to type-switch
on the new heterogeneous Batch[any]; only ParsedEvent contributes to
EventType/EffectiveTime metrics.
@sadiq1971
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive Prometheus metrics instrumentation across the Canton Middleware components, including the API server, Indexer, Relayer, Canton SDK client, and database stores, along with Grafana dashboards and Prometheus scraping configurations. The review feedback highlights three key improvement opportunities: preventing potential nil pointer dereference panics in the batch processor and HTTP metrics middleware, and optimizing HTTP request logging performance by replacing fmt.Sprintf with strconv.Itoa in the middleware hot path.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/indexer/engine/processor.go
Comment thread pkg/app/http/middleware.go
Comment thread pkg/app/http/middleware.go Outdated
dhyaniarun1993 and others added 4 commits June 2, 2026 13:28
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Comment thread pkg/app/api/server.go Outdated
reg sharedmetrics.NamespacedRegisterer,
logger *zap.Logger,
) (*services, error) {
userStore := userstore.NewStore(dbBun)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason we are not passing the instrumented userstore here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing it out. I think it got missed while resolving the merge conflict. Fixing

Comment thread pkg/app/api/server.go
if url == "" {
return nil, fmt.Errorf("indexer URL is required: set token_provider.indexer.url or accept_worker.indexer_url")
}
c, err := indexerclient.New(url, nil)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we use InstrumentedClient for indexer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing it out. I think it got missed while resolving the merge conflict. Fixing

Comment thread pkg/app/api/server.go Outdated

if s.cfg.Monitoring != nil && s.cfg.Monitoring.Enabled {
if s.cfg.Monitoring.Server == nil {
return fmt.Errorf("monitoring is enabled but server config is nil")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Returning before g.Wait() abandons the already-started HTTP server goroutine and skips graceful shutdown. This should be a config-validation error at load time (the Monitoring struct is validate:"required", not a runtime check after a goroutine is live. Validate up front and you can delete the runtime guard entirely.

Copy link
Copy Markdown
Member Author

@dhyaniarun1993 dhyaniarun1993 Jun 3, 2026

Choose a reason for hiding this comment

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

True, we already have validate in the config. This is dead code. We can drop this.

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.

Add Prometheus metrics to API Server and Indexer

3 participants