Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Add prometheus metrics to database queries #3597

Merged
merged 9 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ingest/ledgerbackend/database_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewDatabaseBackend(dataSourceName, networkPassphrase string) (*DatabaseBack
return NewDatabaseBackendFromSession(session, networkPassphrase)
}

func NewDatabaseBackendFromSession(session *db.Session, networkPassphrase string) (*DatabaseBackend, error) {
func NewDatabaseBackendFromSession(session db.SessionInterface, networkPassphrase string) (*DatabaseBackend, error) {
return &DatabaseBackend{
session: session,
networkPassphrase: networkPassphrase,
Expand Down
4 changes: 2 additions & 2 deletions ingest/ledgerbackend/ledger_hash_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type TrustedLedgerHashStore interface {

// HorizonDBLedgerHashStore is a TrustedLedgerHashStore which uses horizon's db to look up ledger hashes
type HorizonDBLedgerHashStore struct {
session *db.Session
session db.SessionInterface
}

// NewHorizonDBLedgerHashStore constructs a new TrustedLedgerHashStore backed by the horizon db
func NewHorizonDBLedgerHashStore(session *db.Session) TrustedLedgerHashStore {
func NewHorizonDBLedgerHashStore(session db.SessionInterface) TrustedLedgerHashStore {
return HorizonDBLedgerHashStore{session: session}
}

Expand Down
1 change: 1 addition & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased

* Refactor `ingest/ledgerbackend/LedgerBackend.GetLedger` method to always block, removing `ingest/ledgerbackend/LedgerBackend.GetLedgerBlocking`. Adds a first `context.Context` param to most `LedgerBackend` methods.
* Add more in-depth Prometheus metrics (count & duration) for db queries.

## v2.2.0

Expand Down
14 changes: 7 additions & 7 deletions services/horizon/internal/actions/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func TestGetAccountsHandlerPageNoResults(t *testing.T) {
"signer": signer,
},
map[string]string{},
q.Session,
q,
),
)
tt.Assert.NoError(err)
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestGetAccountsHandlerPageResultsBySigner(t *testing.T) {
"signer": signer,
},
map[string]string{},
q.Session,
q,
),
)

Expand Down Expand Up @@ -405,7 +405,7 @@ func TestGetAccountsHandlerPageResultsBySigner(t *testing.T) {
"cursor": accountOne,
},
map[string]string{},
q.Session,
q,
),
)

Expand Down Expand Up @@ -455,7 +455,7 @@ func TestGetAccountsHandlerPageResultsBySponsor(t *testing.T) {
"sponsor": sponsor.Address(),
},
map[string]string{},
q.Session,
q,
),
)

Expand Down Expand Up @@ -511,7 +511,7 @@ func TestGetAccountsHandlerPageResultsByAsset(t *testing.T) {
t,
params,
map[string]string{},
q.Session,
q,
),
)

Expand All @@ -529,7 +529,7 @@ func TestGetAccountsHandlerPageResultsByAsset(t *testing.T) {
t,
params,
map[string]string{},
q.Session,
q,
),
)

Expand Down Expand Up @@ -613,7 +613,7 @@ func TestGetAccountsHandlerInvalidParams(t *testing.T) {
t,
tc.params,
map[string]string{},
q.Session,
q,
),
)
tt.Assert.Error(err)
Expand Down
4 changes: 2 additions & 2 deletions services/horizon/internal/actions/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func TestAssetStats(t *testing.T) {
},
} {
t.Run(testCase.name, func(t *testing.T) {
r := makeRequest(t, testCase.queryParams, map[string]string{}, q.Session)
r := makeRequest(t, testCase.queryParams, map[string]string{}, q)
results, err := handler.GetResourcePage(httptest.NewRecorder(), r)
assert.NoError(t, err)

Expand Down Expand Up @@ -450,7 +450,7 @@ func TestAssetStatsIssuerDoesNotExist(t *testing.T) {
tt.Assert.NoError(err)
tt.Assert.Equal(numChanged, int64(1))

r := makeRequest(t, map[string]string{}, map[string]string{}, q.Session)
r := makeRequest(t, map[string]string{}, map[string]string{}, q)
results, err := handler.GetResourcePage(httptest.NewRecorder(), r)
tt.Assert.NoError(err)

Expand Down
48 changes: 24 additions & 24 deletions services/horizon/internal/actions/claimable_balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestGetClaimableBalanceByID(t *testing.T) {
t,
map[string]string{},
map[string]string{"id": id},
q.Session,
q,
))
tt.Assert.NoError(err)

Expand All @@ -85,7 +85,7 @@ func TestGetClaimableBalanceByID(t *testing.T) {
t,
map[string]string{},
map[string]string{"id": id},
q.Session,
q,
))
tt.Assert.Error(err)
tt.Assert.True(q.NoRows(errors.Cause(err)))
Expand All @@ -95,7 +95,7 @@ func TestGetClaimableBalanceByID(t *testing.T) {
t,
map[string]string{},
map[string]string{"id": "0000001112122"},
q.Session,
q,
))
tt.Assert.Error(err)
p := err.(*problem.P)
Expand All @@ -108,7 +108,7 @@ func TestGetClaimableBalanceByID(t *testing.T) {
t,
map[string]string{},
map[string]string{"id": ""},
q.Session,
q,
))
tt.Assert.Error(err)
p = err.(*problem.P)
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestGetClaimableBalances(t *testing.T) {
t,
map[string]string{},
map[string]string{},
q.Session,
q,
))
tt.Assert.NoError(err)
tt.Assert.Len(response, 4)
Expand All @@ -230,7 +230,7 @@ func TestGetClaimableBalances(t *testing.T) {
"cursor": response[3].(protocol.ClaimableBalance).PagingToken(),
},
map[string]string{},
q.Session,
q,
))
tt.Assert.NoError(err)
tt.Assert.Len(response, 0)
Expand All @@ -240,7 +240,7 @@ func TestGetClaimableBalances(t *testing.T) {
t,
map[string]string{"limit": "2"},
map[string]string{},
q.Session,
q,
))
tt.Assert.NoError(err)
tt.Assert.Len(response, 2)
Expand All @@ -259,7 +259,7 @@ func TestGetClaimableBalances(t *testing.T) {
"cursor": response[1].(protocol.ClaimableBalance).PagingToken(),
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -281,7 +281,7 @@ func TestGetClaimableBalances(t *testing.T) {
"cursor": lastIngestedCursor,
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestGetClaimableBalances(t *testing.T) {
t,
map[string]string{},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -342,7 +342,7 @@ func TestGetClaimableBalances(t *testing.T) {
"cursor": lastIngestedCursor,
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -361,7 +361,7 @@ func TestGetClaimableBalances(t *testing.T) {
"cursor": response[1].(protocol.ClaimableBalance).PagingToken(),
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -378,7 +378,7 @@ func TestGetClaimableBalances(t *testing.T) {
"cursor": response[0].(protocol.ClaimableBalance).PagingToken(),
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -392,7 +392,7 @@ func TestGetClaimableBalances(t *testing.T) {
"order": "desc",
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -414,7 +414,7 @@ func TestGetClaimableBalances(t *testing.T) {
"cursor": response[1].(protocol.ClaimableBalance).PagingToken(),
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -431,7 +431,7 @@ func TestGetClaimableBalances(t *testing.T) {
"asset": native.StringCanonical(),
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -450,7 +450,7 @@ func TestGetClaimableBalances(t *testing.T) {
"asset": usd.StringCanonical(),
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -469,7 +469,7 @@ func TestGetClaimableBalances(t *testing.T) {
"asset": euro.StringCanonical(),
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -488,7 +488,7 @@ func TestGetClaimableBalances(t *testing.T) {
"sponsor": "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML",
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -507,7 +507,7 @@ func TestGetClaimableBalances(t *testing.T) {
"claimant": "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML",
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -519,7 +519,7 @@ func TestGetClaimableBalances(t *testing.T) {
"claimant": "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H",
},
map[string]string{},
q.Session,
q,
))

tt.Assert.NoError(err)
Expand All @@ -539,7 +539,7 @@ func TestCursorAndOrderValidation(t *testing.T) {
"cursor": "-1-00000043d380c38a2f2cac46ab63674064c56fdce6b977fdef1a278ad50e1a7e6a5e18",
},
map[string]string{},
q.Session,
q,
))
p := err.(*problem.P)
tt.Assert.Equal("bad_request", p.Type)
Expand All @@ -552,7 +552,7 @@ func TestCursorAndOrderValidation(t *testing.T) {
"cursor": "1003529-00000043d380c38a2f2cac46ab63674064c56fdce6b977fdef1a278ad50e1a7e6a5e18",
},
map[string]string{},
q.Session,
q,
))
p = err.(*problem.P)
tt.Assert.Equal("bad_request", p.Type)
Expand All @@ -566,7 +566,7 @@ func TestCursorAndOrderValidation(t *testing.T) {
"cursor": "1003529-00000043d380c38a2f2cac46ab63674064c56fdce6b977fdef1a278ad50e1a7e6a5e18",
},
map[string]string{},
q.Session,
q,
))
p = err.(*problem.P)
tt.Assert.Equal("bad_request", p.Type)
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/actions/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func makeRequest(
t *testing.T,
queryParams map[string]string,
routeParams map[string]string,
session *db.Session,
session db.SessionInterface,
) *http.Request {
request, err := http.NewRequest("GET", "/", nil)
if err != nil {
Expand Down
Loading