prometheus / prometheus

The Prometheus monitoring system and time series database.
https://prometheus.io/
Apache License 2.0
53.78k stars 8.92k forks source link

Configuring PromQL query statistics #10953

Open puetzp opened 2 years ago

puetzp commented 2 years ago

Hey there, it is currently possible to retrieve query statistics using the stats query parameter. Since v2.35 query statistics of range queries can be extended with per-step data by running Prometheus with --enable-feature=promql-per-step-stats. When I'm not interested in per-step stats I simply need to pass stats with in arbitrary non-empty value, e.g. stats=foo. So the query parameters basically behaves like a boolean, see source:

func defaultStatsRenderer(ctx context.Context, s *stats.Statistics, param string) stats.QueryStats {
    if param != "" {
        return stats.NewQueryStats(s)
    }
    return nil
}

In the context of per-step stats however I need to pass stats=all in order to retrieve the data. So in the latter case the value matters and is pattern-matched in the handler:

func extractQueryOpts(r *http.Request) *promql.QueryOpts {
    return &promql.QueryOpts{
        EnablePerStepStats: r.FormValue("stats") == "all",
    }
}

I guess my question is if it does make sense to change stats to an enum and deny unsupported values since other endpoints already do this (e.g. /api/v1/rules with type=alert|record). I think that would make it easier for client libraries to reason about this parameter as well.

Feel free to close this issue when the matter has been discussed ad nauseam.

roidelapluie commented 1 year ago

Hello,

Unfortunately this is not possible within Prometheus v2. We could consider it for Prometheus v3.

puetzp commented 1 year ago

That would be great! By the way is there a place where ideas/discussions/issues are tracked for a future v3?