Skip to content

Commit

Permalink
refine compaction worker metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesnikovae committed Nov 24, 2024
1 parent 39c5c1d commit 65562d1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
51 changes: 28 additions & 23 deletions pkg/experiment/compactor/compaction_worker_metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package compactor

import "github.com/prometheus/client_golang/prometheus"
import (
"github.com/prometheus/client_golang/prometheus"

"github.com/grafana/pyroscope/pkg/util"
)

type metrics struct {
jobsCompleted *prometheus.CounterVec
Expand All @@ -9,28 +13,29 @@ type metrics struct {
}

func newMetrics(r prometheus.Registerer) *metrics {
m := &metrics{}

m.jobsCompleted = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "pyroscope_compaction_jobs_completed_count",
Help: "Total number of compactions that were executed.",
}, []string{"tenant", "shard", "level", "outcome"})
m.jobsInProgress = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "pyroscope_compaction_jobs_current",
Help: "The number of active compaction jobs per level",
}, []string{"tenant", "shard", "level"})
m.jobDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "pyroscope_compaction_jobs_duration_seconds",
Help: "Duration of compaction job runs",
Buckets: prometheus.ExponentialBuckets(1, 2, 14),
}, []string{"tenant", "shard", "level", "outcome"})

if r != nil {
r.MustRegister(
m.jobsCompleted,
m.jobsInProgress,
m.jobDuration,
)
m := &metrics{
jobsCompleted: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "jobs_completed_total",
Help: "Total number of compaction jobs completed.",
}, []string{"tenant", "shard", "level", "status"}),

jobsInProgress: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "jobs_in_progress",
Help: "The number of active compaction jobs currently running.",
}, []string{"tenant", "shard", "level"}),

jobDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "job_duration_seconds",
Help: "Duration of compaction job runs",
Buckets: prometheus.ExponentialBuckets(1, 2, 14),
}, []string{"tenant", "shard", "level", "status"}),
}

util.Register(r,
m.jobsCompleted,
m.jobsInProgress,
m.jobDuration,
)

return m
}
2 changes: 1 addition & 1 deletion pkg/experiment/metastore/metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ func New(
m := &Metastore{
config: config,
logger: logger,
reg: reg,
health: healthService,
bucket: bucket,
placement: placementMgr,
}

var err error
m.reg = prometheus.WrapRegistererWithPrefix("pyroscope_metastore_", reg)
m.fsm, err = fsm.New(m.logger, m.reg, m.config.DataDir)
if err != nil {
return nil, fmt.Errorf("failed to initialize store: %w", err)
Expand Down
6 changes: 4 additions & 2 deletions pkg/phlare/modules_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ func (f *Phlare) initCompactionWorker() (svc services.Service, err error) {
return nil, err
}
logger := log.With(f.logger, "component", "compaction-worker")
registerer := prometheus.WrapRegistererWithPrefix("pyroscope_compaction_worker_", f.reg)
w, err := compactionworker.New(
logger,
f.Cfg.CompactionWorker,
f.metastoreClient,
f.storageBucket,
f.reg,
registerer,
)
if err != nil {
return nil, err
Expand All @@ -111,10 +112,11 @@ func (f *Phlare) initMetastore() (services.Service, error) {

logger := log.With(f.logger, "component", "metastore")
healthService := health.NewGRPCHealthService(f.healthServer, logger, "pyroscope.metastore")
registerer := prometheus.WrapRegistererWithPrefix("pyroscope_metastore_", f.reg)
m, err := metastore.New(
f.Cfg.Metastore,
logger,
f.reg,
registerer,
healthService,
f.metastoreClient,
f.storageBucket,
Expand Down

0 comments on commit 65562d1

Please sign in to comment.