Skip to content

Commit 50bf518

Browse files
fix(metrics): gemini_cql_requests were not registered before metrics server is running
Signed-off-by: Dusan Malusev <dusan.malusev@scylladb.com>
1 parent f4ad56e commit 50bf518

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

pkg/metrics/metrics.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package metrics
2+
3+
import (
4+
"github.com/prometheus/client_golang/prometheus"
5+
"github.com/prometheus/client_golang/prometheus/promauto"
6+
)
7+
8+
var CQLRequests = promauto.NewCounterVec(prometheus.CounterOpts{
9+
Name: "gemini_cql_requests",
10+
Help: "How many CQL requests processed, partitioned by system and CQL query type aka 'method' (batch, delete, insert, update).",
11+
}, []string{"system", "method"},
12+
)

pkg/store/cqlstore.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ import (
2121

2222
"github.com/gocql/gocql"
2323
"github.com/pkg/errors"
24-
"github.com/prometheus/client_golang/prometheus"
2524
"github.com/scylladb/gocqlx/v2/qb"
2625
"go.uber.org/zap"
2726

27+
"github.com/scylladb/gemini/pkg/metrics"
2828
"github.com/scylladb/gemini/pkg/stmtlogger"
2929
"github.com/scylladb/gemini/pkg/typedef"
3030
)
3131

3232
type cqlStore struct { //nolint:govet
3333
session *gocql.Session
3434
schema *typedef.Schema
35-
ops *prometheus.CounterVec
3635
logger *zap.Logger
3736
system string
3837
maxRetriesMutate int
@@ -48,7 +47,7 @@ func (cs *cqlStore) name() string {
4847
func (cs *cqlStore) mutate(ctx context.Context, stmt *typedef.Stmt) error {
4948
for range cs.maxRetriesMutate {
5049
if err := cs.doMutate(ctx, stmt); err == nil {
51-
cs.ops.WithLabelValues(cs.system, opType(stmt)).Inc()
50+
metrics.CQLRequests.WithLabelValues(cs.system, opType(stmt)).Inc()
5251
return nil
5352
}
5453

@@ -92,7 +91,7 @@ func (cs *cqlStore) load(ctx context.Context, stmt *typedef.Stmt) ([]map[string]
9291
defer query.Release()
9392

9493
iter := query.Iter()
95-
cs.ops.WithLabelValues(cs.system, opType(stmt)).Inc()
94+
metrics.CQLRequests.WithLabelValues(cs.system, opType(stmt)).Inc()
9695

9796
result := loadSet(iter)
9897

pkg/store/store.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import (
3030
"github.com/google/go-cmp/cmp"
3131
"github.com/google/go-cmp/cmp/cmpopts"
3232
"github.com/pkg/errors"
33-
"github.com/prometheus/client_golang/prometheus"
34-
"github.com/prometheus/client_golang/prometheus/promauto"
3533
"go.uber.org/multierr"
3634
"gopkg.in/inf.v0"
3735

@@ -72,21 +70,15 @@ type Config struct {
7270
}
7371

7472
func New(schema *typedef.Schema, testCluster, oracleCluster *gocql.ClusterConfig, cfg Config, traceOut io.Writer, logger *zap.Logger) (Store, error) {
75-
ops := promauto.NewCounterVec(prometheus.CounterOpts{
76-
Name: "gemini_cql_requests",
77-
Help: "How many CQL requests processed, partitioned by system and CQL query type aka 'method' (batch, delete, insert, update).",
78-
}, []string{"system", "method"},
79-
)
80-
81-
oracleStore, err := getStore("oracle", schema, oracleCluster, cfg, cfg.OracleLogStatementsFile, traceOut, logger, ops)
73+
oracleStore, err := getStore("oracle", schema, oracleCluster, cfg, cfg.OracleLogStatementsFile, traceOut, logger)
8274
if err != nil {
8375
return nil, err
8476
}
8577

8678
if testCluster == nil {
8779
return nil, errors.New("test cluster is empty")
8880
}
89-
testStore, err := getStore("test", schema, testCluster, cfg, cfg.TestLogStatementsFile, traceOut, logger, ops)
81+
testStore, err := getStore("test", schema, testCluster, cfg, cfg.TestLogStatementsFile, traceOut, logger)
9082
if err != nil {
9183
return nil, err
9284
}
@@ -265,7 +257,6 @@ func getStore(
265257
stmtLogFile string,
266258
traceOut io.Writer,
267259
logger *zap.Logger,
268-
ops *prometheus.CounterVec,
269260
) (out storeLoader, err error) {
270261
if clusterConfig == nil {
271262
return &noOpStore{
@@ -285,7 +276,6 @@ func getStore(
285276
session: oracleSession,
286277
schema: schema,
287278
system: name,
288-
ops: ops,
289279
maxRetriesMutate: cfg.MaxRetriesMutate + 10,
290280
maxRetriesMutateSleep: cfg.MaxRetriesMutateSleep,
291281
useServerSideTimestamps: cfg.UseServerSideTimestamps,

0 commit comments

Comments
 (0)