diff --git a/pkg/promtail/client/client.go b/pkg/promtail/client/client.go index d080fedd55d1e..f9d1c84caed86 100644 --- a/pkg/promtail/client/client.go +++ b/pkg/promtail/client/client.go @@ -65,6 +65,10 @@ var ( Name: "request_duration_seconds", Help: "Duration of send requests.", }, []string{"status_code", "host"}) + + countersWithHost = []*prometheus.CounterVec{ + encodedBytes, sentBytes, droppedBytes, sentEntries, droppedEntries, + } ) func init() { @@ -129,6 +133,12 @@ func New(cfg Config, logger log.Logger) (Client, error) { c.client.Timeout = cfg.Timeout + // Initialize counters to 0 so the metrics are exported before the first + // occurrence of incrementing to avoid missing metrics. + for _, counter := range countersWithHost { + counter.WithLabelValues(c.cfg.URL.Host).Add(0) + } + c.wg.Add(1) go c.run() return c, nil diff --git a/pkg/promtail/client/client_test.go b/pkg/promtail/client/client_test.go index e0d0fb55473eb..9a1ab2627b2cf 100644 --- a/pkg/promtail/client/client_test.go +++ b/pkg/promtail/client/client_test.go @@ -70,6 +70,9 @@ func TestClient_Handle(t *testing.T) { # HELP promtail_sent_entries_total Number of log entries sent to the ingester. # TYPE promtail_sent_entries_total counter promtail_sent_entries_total{host="__HOST__"} 3.0 + # HELP promtail_dropped_entries_total Number of log entries dropped because failed to be sent to the ingester after all retries. + # TYPE promtail_dropped_entries_total counter + promtail_dropped_entries_total{host="__HOST__"} 0 `, }, "batch log entries together until the batch wait time is reached": { @@ -93,6 +96,9 @@ func TestClient_Handle(t *testing.T) { # HELP promtail_sent_entries_total Number of log entries sent to the ingester. # TYPE promtail_sent_entries_total counter promtail_sent_entries_total{host="__HOST__"} 2.0 + # HELP promtail_dropped_entries_total Number of log entries dropped because failed to be sent to the ingester after all retries. + # TYPE promtail_dropped_entries_total counter + promtail_dropped_entries_total{host="__HOST__"} 0 `, }, "retry send a batch up to backoff's max retries in case the server responds with a 5xx": { @@ -119,6 +125,9 @@ func TestClient_Handle(t *testing.T) { # HELP promtail_dropped_entries_total Number of log entries dropped because failed to be sent to the ingester after all retries. # TYPE promtail_dropped_entries_total counter promtail_dropped_entries_total{host="__HOST__"} 1.0 + # HELP promtail_sent_entries_total Number of log entries sent to the ingester. + # TYPE promtail_sent_entries_total counter + promtail_sent_entries_total{host="__HOST__"} 0 `, }, "do not retry send a batch in case the server responds with a 4xx": { @@ -137,6 +146,9 @@ func TestClient_Handle(t *testing.T) { # HELP promtail_dropped_entries_total Number of log entries dropped because failed to be sent to the ingester after all retries. # TYPE promtail_dropped_entries_total counter promtail_dropped_entries_total{host="__HOST__"} 1.0 + # HELP promtail_sent_entries_total Number of log entries sent to the ingester. + # TYPE promtail_sent_entries_total counter + promtail_sent_entries_total{host="__HOST__"} 0 `, }, "batch log entries together honoring the client tenant ID": { @@ -156,6 +168,9 @@ func TestClient_Handle(t *testing.T) { # HELP promtail_sent_entries_total Number of log entries sent to the ingester. # TYPE promtail_sent_entries_total counter promtail_sent_entries_total{host="__HOST__"} 2.0 + # HELP promtail_dropped_entries_total Number of log entries dropped because failed to be sent to the ingester after all retries. + # TYPE promtail_dropped_entries_total counter + promtail_dropped_entries_total{host="__HOST__"} 0 `, }, "batch log entries together honoring the tenant ID overridden while processing the pipeline stages": { @@ -183,6 +198,9 @@ func TestClient_Handle(t *testing.T) { # HELP promtail_sent_entries_total Number of log entries sent to the ingester. # TYPE promtail_sent_entries_total counter promtail_sent_entries_total{host="__HOST__"} 4.0 + # HELP promtail_dropped_entries_total Number of log entries dropped because failed to be sent to the ingester after all retries. + # TYPE promtail_dropped_entries_total counter + promtail_dropped_entries_total{host="__HOST__"} 0 `, }, }