From 2ca3f84585d1f3ae1312f3e0487bd85c724aacd8 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Mon, 7 Jun 2021 14:51:21 +0200 Subject: [PATCH] services/horizon: Fix DB metrics when replica enabled (#3668) This commit fixes the duplicate metrics in `db.Session` that prevents Horizon from starting. An attempt to run Horizon with read replica middleware results in an error: panic: duplicate metrics collector registration attempted --- services/horizon/CHANGELOG.md | 1 + services/horizon/internal/init.go | 2 +- support/db/metrics.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/services/horizon/CHANGELOG.md b/services/horizon/CHANGELOG.md index 2d3ebe7cb5..9724e52dc0 100644 --- a/services/horizon/CHANGELOG.md +++ b/services/horizon/CHANGELOG.md @@ -8,6 +8,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/). ### Code Changes * Fix bug in `horizon db reingest range` command, which would throw a duplicate entry conflict error from the DB. ([3661](https://github.com/stellar/go/pull/3661)). +* Fix bug in DB metrics preventing Horizon from starting when read-only replica middleware is enabled. ([3668](https://github.com/stellar/go/pull/3668)). ## v2.4.0 diff --git a/services/horizon/internal/init.go b/services/horizon/internal/init.go index c9c636faf3..97ab048f99 100644 --- a/services/horizon/internal/init.go +++ b/services/horizon/internal/init.go @@ -62,7 +62,7 @@ func mustInitHorizonDB(app *App) { )} app.primaryHistoryQ = &history.Q{mustNewDBSession( - db.HistorySubservice, + db.HistoryPrimarySubservice, app.config.DatabaseURL, maxIdle, maxOpen, diff --git a/support/db/metrics.go b/support/db/metrics.go index 1733d2d1d7..5b322e80c8 100644 --- a/support/db/metrics.go +++ b/support/db/metrics.go @@ -19,6 +19,7 @@ var QueryTypeContextKey = CtxKey("query_type") type Subservice string var CoreSubservice = Subservice("core") +var HistoryPrimarySubservice = Subservice("history_primary") var HistorySubservice = Subservice("history") var IngestSubservice = Subservice("ingest")