Skip to content

Implement vector() function #6946

Description

@tonychoe

Is your feature request related to a problem? Please describe.
I want to turn null (no data) to zero in query result in easy and reliable way.

There are other Loki users who want the same.
https://community.grafana.com/t/how-can-i-turn-no-data-to-zero-in-loki/40694

Describe the solution you'd like
Implement a function like vector() in PromQL.

vector(s scalar) returns the scalar s as a vector with no labels.
Then users can join their query with vector() to turn NULL to zero, as below.

vector1
or
vector(0)

Describe alternatives you've considered
(1) Grafana's transform feature.
However, this feature only works for a dashboard panel with single Loki query. It doesn't work for multiple queries for a panel.

(2) Tried to generate zeros reliably, but not perfect

sum(count_over_time({namespace="traefik"}|="foo"[1m])) 
or
sum(count_over_time({namespace="traefik"}[1m])) < bool 0

The 2nd vector can still return NULL if there is no log data matching labels sets. Not useful for log streams which has fluctuating log ingestion.

(3) Tried absent_over_time() as 2nd vector instead, it didn't work for me.

(4) First, stored the log-metrics in Prometheus. Second, use vector() in Prometheus.
This works of course. But I wish I can do the same using LokiQL which is upstream.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions