Marcio Cunha

Excess logs? How to use Vector and Loki without high costs

Learn how to filter, mask sensitive data, and compress high-volume log streams using Vector before sending them to Grafana Loki.

Marcio Cunha•3 min
Also available in:PortuguêsEspañol
Summary
  • Unfiltered log overload saturates storage and drastically raises the operational costs of Grafana Loki
  • Vector acts as an ultra-fast collection agent capable of processing and transforming massive data streams in real time
  • Source-level filtering blocks noise and irrelevant messages before they reach the persistence layer
  • Data masking automatically removes tokens, passwords, and sensitive IDs to ensure compliance with privacy laws
  • Well-configured pipelines combine compression and efficient partitioning to optimize analytical queries

Why does log volume explode in modern environments?

When applications grow and microservices multiply, the amount of text data generated — known as logs — grows exponentially. Every web request, database error, and system warning becomes a line written to disk. In practice, this means most stored data will never be read by a human or used for debugging, wasting massive infrastructure resources and driving up storage costs.

Managing this data torrent requires modern tools that filter information before disks become saturated. This is where optimizing data routing becomes essential, especially when combining efficient collection pipelines with lightweight, index-oriented databases like Grafana Loki. Maintaining resilient systems often demands tough decisions about what is truly worth keeping, much like the considerations we face when tuning liveness probes in Kubernetes environments under heavy load.

The role of Vector in telemetry collection and transformation

Vector is a lightweight, high-performance tool written in Rust designed to collect, transform, and route logs, metrics, and events. Unlike heavier traditional collectors, it consumes minimal memory and CPU, even when processing hundreds of thousands of events per second. Its modular architecture allows reading, processing, and shipping stages to be chained cleanly and predictably.

In practice, Vector acts as a translator and traffic controller for your data. It captures logs at the source — whether a text file, TCP socket, or API —, applies complex modification rules, and delivers clean results to the final destination. This flexibility eliminates the need to alter application code just to change the format in which records are saved, centralizing telemetry governance.

Filtering noise and discarding irrelevant data at the source

The first step to taming log volume is eliminating content that adds no operational value. Repetitive health check messages or trivial warnings from third-party libraries often account for over seventy percent of total text volume generated by a system. Storing this content is equivalent to paying rent to store garbage.

With Vector, we can create filters based on regular expressions or logical conditions to discard these events right at the entry point. If a log has an irrelevant severity level or matches a standard monitoring route, the pipeline simply drops it. This single change drastically reduces network pressure and saves precious gigabytes of storage daily.

Masking sensitive information to comply with privacy regulations

Beyond volume, the accidental presence of sensitive data — such as plaintext passwords, credit card numbers, access tokens, and personal IDs — represents a critical security risk. Leaks in logging systems often happen because developers leave debug mode active in production, recording confidential information into text files.

Vector solves this problem through real-time rewrite and masking transformations. We can configure rules to identify specific patterns, such as a credit card number sequence, and replace it with asterisks before the data is transmitted. This ensures immediate compliance with regulations like GDPR without compromising the ability to trace operational errors.

Compressing streams and preparing data for Grafana Loki

Once logs are filtered and cleaned, the resulting stream must be packaged efficiently for delivery. Grafana Loki adopts a minimalist indexing approach based solely on labels, meaning raw log text must be sent in a structured way to keep searches fast and inexpensive.

Below is a practical Vector configuration example (in TOML format) that reads logs from a file, discards health check requests, masks credit card data, and sends the compressed result to Loki:

[sources.in_file]  type = "file"  include = ["/var/log/app/*.log"]

[transforms.filter_health]  type = "filter"  inputs = ["in_file"]  condition = '.message != "GET /healthz 200"'

[transforms.mask_sensitive]  type = "remap"  inputs = ["filter_health"]  source = '''    .message = replace(.message, r'\d{4}-\d{4}-\d{4}-\d{4}', "****-****-****-****")  '''

[sinks.to_loki]  type = "loki"  inputs = ["mask_sensitive"]  endpoint = "http://loki.internal:3100"  encoding.codec = "json"

Final considerations on efficient observability pipelines

Implementing a solid filtering and masking strategy with Vector and Loki completely transforms the financial and operational health of a modern infrastructure. Instead of blindly accumulating data and suffering from unpredictable storage costs, engineering teams take active control of what enters visualization dashboards. This discipline not only improves query performance but ensures a much safer, cleaner, and more predictable scaling environment.