Skip to content

Commit

Permalink
adds distributor replication factor metric (grafana#3594)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d authored Apr 13, 2021
1 parent 56af725 commit 965d482
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ import (
)

var (
ingesterAppends = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "loki",
Name: "distributor_ingester_appends_total",
Help: "The total number of batch appends sent to ingesters.",
}, []string{"ingester"})
ingesterAppendFailures = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "loki",
Name: "distributor_ingester_append_failures_total",
Help: "The total number of failed batch appends sent to ingesters.",
}, []string{"ingester"})

maxLabelCacheSize = 100000
)

Expand Down Expand Up @@ -81,6 +70,11 @@ type Distributor struct {
// Per-user rate limiter.
ingestionRateLimiter *limiter.RateLimiter
labelCache *lru.Cache

// metrics
ingesterAppends *prometheus.CounterVec
ingesterAppendFailures *prometheus.CounterVec
replicationFactor prometheus.Gauge
}

// New a distributor creates.
Expand Down Expand Up @@ -130,7 +124,23 @@ func New(cfg Config, clientCfg client.Config, configs *runtime.TenantConfigs, in
pool: cortex_distributor.NewPool(clientCfg.PoolConfig, ingestersRing, factory, util_log.Logger),
ingestionRateLimiter: limiter.NewRateLimiter(ingestionRateStrategy, 10*time.Second),
labelCache: labelCache,
ingesterAppends: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{
Namespace: "loki",
Name: "distributor_ingester_appends_total",
Help: "The total number of batch appends sent to ingesters.",
}, []string{"ingester"}),
ingesterAppendFailures: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{
Namespace: "loki",
Name: "distributor_ingester_append_failures_total",
Help: "The total number of failed batch appends sent to ingesters.",
}, []string{"ingester"}),
replicationFactor: promauto.With(registerer).NewGauge(prometheus.GaugeOpts{
Namespace: "loki",
Name: "distributor_replication_factor",
Help: "The configured replication factor.",
}),
}
d.replicationFactor.Set(float64(ingestersRing.ReplicationFactor()))

servs = append(servs, d.pool)
d.subservices, err = services.NewManager(servs...)
Expand Down Expand Up @@ -335,9 +345,9 @@ func (d *Distributor) sendSamplesErr(ctx context.Context, ingester ring.Instance
}

_, err = c.(logproto.PusherClient).Push(ctx, req)
ingesterAppends.WithLabelValues(ingester.Addr).Inc()
d.ingesterAppends.WithLabelValues(ingester.Addr).Inc()
if err != nil {
ingesterAppendFailures.WithLabelValues(ingester.Addr).Inc()
d.ingesterAppendFailures.WithLabelValues(ingester.Addr).Inc()
}
return err
}
Expand Down

0 comments on commit 965d482

Please sign in to comment.