Skip to content

Commit 025b89d

Browse files
authored
Merge pull request #18 from Arkiv-Network/rvdp/pr
Add the prometheus query time metric back
2 parents 46e4349 + ebc8ae4 commit 025b89d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

api/api.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,8 @@ import (
99

1010
"github.com/Arkiv-Network/query-api/sqlstore"
1111
"github.com/Arkiv-Network/sqlite-store/query"
12-
"github.com/prometheus/client_golang/prometheus"
13-
"github.com/prometheus/client_golang/prometheus/promauto"
1412
)
1513

16-
var queryDuration = promauto.NewHistogram(prometheus.HistogramOpts{
17-
Name: "arkiv_query_api_query_duration_seconds",
18-
Help: "Duration of database queries in seconds",
19-
Buckets: prometheus.DefBuckets, // Default: .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10
20-
})
21-
2214
type arkivAPI struct {
2315
store *sqlstore.SQLStore
2416
log *slog.Logger

sqlstore/sqlstore.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ import (
1212

1313
"github.com/Arkiv-Network/sqlite-store/query"
1414
"github.com/ethereum/go-ethereum/common"
15+
"github.com/prometheus/client_golang/prometheus"
16+
"github.com/prometheus/client_golang/prometheus/promauto"
1517
)
1618

1719
var ErrStopIteration = errors.New("stop iteration")
1820

21+
var queryDuration = promauto.NewHistogram(prometheus.HistogramOpts{
22+
Name: "arkiv_query_api_query_duration_seconds",
23+
Help: "Duration of database queries in seconds",
24+
Buckets: prometheus.DefBuckets, // Default: .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10
25+
})
26+
1927
type SQLStore struct {
2028
log *slog.Logger
2129

@@ -194,6 +202,7 @@ func (s *SQLStore) QueryEntitiesInternalIterator(
194202
startTime := time.Now()
195203
defer func() {
196204
elapsed := time.Since(startTime)
205+
queryDuration.Observe(elapsed.Seconds())
197206
s.log.Info("query execution time", "seconds", elapsed.Seconds(), "query", originalQuery)
198207
}()
199208

0 commit comments

Comments
 (0)