fix(kafka): Set namespace for Loki kafka metrics (#14426)

pull/14416/head
benclive 8 months ago committed by GitHub
parent 5f325aac56
commit 8aa8a2bb0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      pkg/distributor/distributor.go
  2. 18
      pkg/kafka/writer_client.go

@ -279,11 +279,13 @@ func New(
Help: "Total number of times the distributor has sharded streams", Help: "Total number of times the distributor has sharded streams",
}), }),
kafkaAppends: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{ kafkaAppends: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{
Name: "kafka_appends_total", Namespace: constants.Loki,
Help: "The total number of appends sent to kafka ingest path.", Name: "distributor_kafka_appends_total",
Help: "The total number of appends sent to kafka ingest path.",
}, []string{"partition", "status"}), }, []string{"partition", "status"}),
kafkaWriteLatency: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{ kafkaWriteLatency: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{
Name: "kafka_latency_seconds", Namespace: constants.Loki,
Name: "distributor_kafka_latency_seconds",
Help: "Latency to write an incoming request to the ingest storage.", Help: "Latency to write an incoming request to the ingest storage.",
NativeHistogramBucketFactor: 1.1, NativeHistogramBucketFactor: 1.1,
NativeHistogramMinResetDuration: 1 * time.Hour, NativeHistogramMinResetDuration: 1 * time.Hour,
@ -291,13 +293,15 @@ func New(
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
}), }),
kafkaWriteBytesTotal: promauto.With(registerer).NewCounter(prometheus.CounterOpts{ kafkaWriteBytesTotal: promauto.With(registerer).NewCounter(prometheus.CounterOpts{
Name: "kafka_sent_bytes_total", Namespace: constants.Loki,
Help: "Total number of bytes sent to the ingest storage.", Name: "distributor_kafka_sent_bytes_total",
Help: "Total number of bytes sent to the ingest storage.",
}), }),
kafkaRecordsPerRequest: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{ kafkaRecordsPerRequest: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{
Name: "kafka_records_per_write_request", Namespace: constants.Loki,
Help: "The number of records a single per-partition write request has been split into.", Name: "distributor_kafka_records_per_write_request",
Buckets: prometheus.ExponentialBuckets(1, 2, 8), Help: "The number of records a single per-partition write request has been split into.",
Buckets: prometheus.ExponentialBuckets(1, 2, 8),
}), }),
writeFailuresManager: writefailures.NewManager(logger, registerer, cfg.WriteFailuresLogging, configs, "distributor"), writeFailuresManager: writefailures.NewManager(logger, registerer, cfg.WriteFailuresLogging, configs, "distributor"),
kafkaWriter: kafkaWriter, kafkaWriter: kafkaWriter,

@ -18,6 +18,8 @@ import (
"go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
"go.uber.org/atomic" "go.uber.org/atomic"
"github.com/grafana/loki/v3/pkg/util/constants"
) )
// NewWriterClient returns the kgo.Client that should be used by the Writer. // NewWriterClient returns the kgo.Client that should be used by the Writer.
@ -189,6 +191,7 @@ func NewProducer(client *kgo.Client, maxBufferedBytes int64, reg prometheus.Regi
// Metrics. // Metrics.
bufferedProduceBytes: promauto.With(reg).NewSummary( bufferedProduceBytes: promauto.With(reg).NewSummary(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Namespace: constants.Loki,
Name: "buffered_produce_bytes", Name: "buffered_produce_bytes",
Help: "The buffered produce records in bytes. Quantile buckets keep track of buffered records size over the last 60s.", Help: "The buffered produce records in bytes. Quantile buckets keep track of buffered records size over the last 60s.",
Objectives: map[float64]float64{0.5: 0.05, 0.99: 0.001, 1: 0.001}, Objectives: map[float64]float64{0.5: 0.05, 0.99: 0.001, 1: 0.001},
@ -197,16 +200,19 @@ func NewProducer(client *kgo.Client, maxBufferedBytes int64, reg prometheus.Regi
}), }),
bufferedProduceBytesLimit: promauto.With(reg).NewGauge( bufferedProduceBytesLimit: promauto.With(reg).NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Name: "buffered_produce_bytes_limit", Namespace: constants.Loki,
Help: "The bytes limit on buffered produce records. Produce requests fail once this limit is reached.", Name: "buffered_produce_bytes_limit",
Help: "The bytes limit on buffered produce records. Produce requests fail once this limit is reached.",
}), }),
produceRequestsTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ produceRequestsTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "produce_requests_total", Namespace: constants.Loki,
Help: "Total number of produce requests issued to Kafka.", Name: "produce_requests_total",
Help: "Total number of produce requests issued to Kafka.",
}), }),
produceFailuresTotal: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{ produceFailuresTotal: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
Name: "produce_failures_total", Namespace: constants.Loki,
Help: "Total number of failed produce requests issued to Kafka.", Name: "produce_failures_total",
Help: "Total number of failed produce requests issued to Kafka.",
}, []string{"reason"}), }, []string{"reason"}),
} }

Loading…
Cancel
Save