Interview Prep/Monitoring & Observability/Logging: ELK/EFK, Loki & Log Shippers

What do `|=`, `|~`, `!=`, `!~` cost in LogQL compared with label filters after a parser?

AdvancedConceptLogging: ELK/EFK, Loki & Log Shippers
Answer

Line filters run directly on raw log bytes and are the cheapest operation after stream selection; |= (substring) is faster than |~ (regex). Label filters after | json require parsing every line first, which is much more CPU.

So we write:

{app="api"} |= "checkout" | json | status >= 500

instead of {app="api"} | json | path="/checkout" | status >= 500. The pre-filter discards most lines before the expensive parser. Loki 3.x bloom filters can also accelerate |= searches on structured metadata.

All Monitoring & Observability questions Roadmap: Logging & tracing

More on Logging: ELK/EFK, Loki & Log Shippers