Skip to content

Commit

Permalink
fix duplicate metric creation
Browse files Browse the repository at this point in the history
  • Loading branch information
melekes committed Nov 30, 2023
1 parent 5edb51e commit 2441878
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
15 changes: 7 additions & 8 deletions goleveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/syndtr/goleveldb/leveldb/util"

"github.com/prometheus/client_golang/prometheus"

Check failure on line 13 in goleveldb.go

View workflow job for this annotation

GitHub Actions / golangci

import 'github.com/prometheus/client_golang/prometheus' is not allowed from list 'main' (depguard)
"github.com/prometheus/client_golang/prometheus/promauto"
)

func init() {
Expand Down Expand Up @@ -225,49 +224,49 @@ func (db *GoLevelDB) ReverseIterator(start, end []byte) (Iterator, error) {
}

func (db *GoLevelDB) createPrometheusMetrics(dbName string) {
db.getDuration = promauto.NewGauge(prometheus.GaugeOpts{
db.getDuration = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: "get_duration_ms",
Help: "The duration of the Get() operation in ms.",
})
prometheus.MustRegister(db.getDuration)
db.setDuration = promauto.NewGauge(prometheus.GaugeOpts{
db.setDuration = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: "set_duration_ms",
Help: "The duration of the Set() operation in ms.",
})
prometheus.MustRegister(db.setDuration)
db.setSyncDuration = promauto.NewGauge(prometheus.GaugeOpts{
db.setSyncDuration = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: "set_sync_duration_ms",
Help: "The duration of the SetSync() operation in ms.",
})
prometheus.MustRegister(db.setSyncDuration)
db.deleteDuration = promauto.NewGauge(prometheus.GaugeOpts{
db.deleteDuration = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: "delete_duration_ms",
Help: "The duration of the Delete() operation in ms.",
})
prometheus.MustRegister(db.deleteDuration)
db.deleteSyncDuration = promauto.NewGauge(prometheus.GaugeOpts{
db.deleteSyncDuration = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: "delete_sync_duration_ms",
Help: "The duration of the DeleteSync() operation in ms.",
})
prometheus.MustRegister(db.deleteSyncDuration)
db.batchDuration = promauto.NewGauge(prometheus.GaugeOpts{
db.batchDuration = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: "batch_duration_ms",
Help: "The duration of the batch#write operation in ms.",
})
prometheus.MustRegister(db.batchDuration)
db.batchSyncDuration = promauto.NewGauge(prometheus.GaugeOpts{
db.batchSyncDuration = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: "batch_sync_duration_ms",
Expand Down
5 changes: 2 additions & 3 deletions goleveldb_stats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"sync"

"github.com/prometheus/client_golang/prometheus"

Check failure on line 7 in goleveldb_stats_collector.go

View workflow job for this annotation

GitHub Actions / golangci

import 'github.com/prometheus/client_golang/prometheus' is not allowed from list 'main' (depguard)
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/syndtr/goleveldb/leveldb"
)

Expand All @@ -23,7 +22,7 @@ func newLevelDBCollector(db *leveldb.DB, dbName string) *levelDBCollector {
names := getMetricNames()
metrics := make(map[string]prometheus.Gauge, len(names))
for _, field := range names {
metrics[field] = promauto.NewGauge(prometheus.GaugeOpts{
metrics[field] = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: field,
Expand All @@ -40,7 +39,7 @@ func newLevelDBCollector(db *leveldb.DB, dbName string) *levelDBCollector {
}
levelMetrics := make(map[string]*prometheus.GaugeVec, len(levelMetricsNames))
for _, field := range levelMetricsNames {
levelMetrics[field] = promauto.NewGaugeVec(prometheus.GaugeOpts{
levelMetrics[field] = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: PROMETHEUS_NAMESPACE,
Subsystem: dbName,
Name: field,
Expand Down

0 comments on commit 2441878

Please sign in to comment.