Skip to content

component_sent_bytes_total for the loki sink reports compressed bytes, unlike other sinks #26510

Description

@hillmandj

A note for the community

Vector version: 0.57.0

Summary

The loki sink reports component_sent_bytes_total after compression. Other sinks, such as datadog_logs, report it before compression, which is what the component spec and #20610 say it should be.

The result is that the same logs sent to two sinks show very different sizes. That makes the metric misleading for capacity planning and cost comparisons.

What we see

We send the same log stream to both a datadog_logs sink and a loki sink (snappy compression). We compare component_sent_bytes_total to component_sent_event_bytes_total for each:

Sink sent_bytes ÷ sent_event_bytes
datadog_logs ~1.0
loki ~0.2
  • For datadog_logs, bytes sent roughly equals event bytes, which is what we expect.
  • For loki, bytes sent is about 5× smaller, which fits the compressed payload size rather than the uncompressed one. Loki's own ingest metrics agree with the event-bytes figure.

Why it happens

The loki sink uses the shared default RequestBuilder::encode_events. That function compresses the payload first, then passes the compressed length into the slot meant for the uncompressed size:

That value then flows into the metric:

  1. src/sinks/util/metadata.rs#L93-L99: uncompressed_byte_size becomes request_encoded_size.
  2. lib/vector-common/src/request_metadata.rs#L270-L310: it is stored and returned as-is.
  3. src/sinks/loki/service.rs#L56-L57: bytes_sent() returns request_encoded_size().

By contrast, datadog_logs has its own builder. It measures the size before compressing:

Expected

component_sent_bytes_total should report uncompressed bytes for every sink, including loki. Any other siult encode_events with compression turned on is probably affected too.

Suggested fix

In the default encode_events, record the payload length before compression and pass that as uncompressed_datadog_logs does.

Problem

component_sent_bytes_total for the loki sink reports compressed bytes, unlike other sinks

Configuration


Version

0.57.0

Debug Output


Example Data

No response

Additional Context

No response

References

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions