Ravindra BagaleCourses & study guides मराठी

Chapter 95: Logging with Loki, Elastic Stack and CloudWatch

DevOps

95.5 Loki — streams, labels and cardinality

Story (fictional teaching scenario). At a fictional Kolhapur app team, Aisha and Luca from Rome first label every request separately. They then see why that makes too many tiny streams.

Loki — streams, labels and cardinality
Loki — streams, labels and cardinality

Why

Loki indexes labels rather than treating every line as a fully indexed document. Label design shapes query cost and performance.

What

  • Loki stores logs grouped into streams and indexes their label sets.
  • A label is a key/value describing origin, such as app or environment.
  • A stream is one unique combination of labels.
  • Cardinality is the number of distinct values/combinations.
  • Structured metadata can carry high-cardinality context where supported without making it an index label; ordinary log fields are also useful.

How

  1. Choose a few stable origin labels.

  2. Keep unique request IDs and timestamps in content/metadata, not index labels.

  3. Estimate combinations rather than counting label names alone.

Example 1: Count possible streams

  1. Read the command or request.
2 services ×3 environments = up to 6 label combinations
Add 1000 request IDs = up to 6000 combinations
  1. Read the result.

Output (illustrative; NOT executed against Loki, Elastic or CloudWatch)

One high-cardinality label can multiply the stream count.
  1. Line by line: The multiplication is an upper bound, not an observed Loki test. The number of actual combinations depends on which values occur together. Avoid user identifiers, unique IDs and timestamps as labels, even when they seem convenient for one search.

Ravindra Bagale's Tip

Use labels to select the source, then search event fields.

Did you understand? Let us try it once more.