diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index a7d79e46d4..b4620219ac 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -509,7 +509,7 @@ var httpClient = &http.Client{ func LabelValuesHandler(qt *querytracer.Tracer, startTime time.Time, at *auth.Token, labelName string, w http.ResponseWriter, r *http.Request) error { defer labelValuesDuration.UpdateDuration(startTime) - cp, err := getCommonParams(r, startTime, false) + cp, err := getCommonParamsWithDefaultDuration(r, startTime, false) if err != nil { return err } @@ -608,7 +608,7 @@ var tsdbStatusDuration = metrics.NewSummary(`vm_request_duration_seconds{path="/ func LabelsHandler(qt *querytracer.Tracer, startTime time.Time, at *auth.Token, w http.ResponseWriter, r *http.Request) error { defer labelsDuration.UpdateDuration(startTime) - cp, err := getCommonParams(r, startTime, false) + cp, err := getCommonParamsWithDefaultDuration(r, startTime, false) if err != nil { return err } @@ -664,17 +664,14 @@ var seriesCountDuration = metrics.NewSummary(`vm_request_duration_seconds{path=" func SeriesHandler(qt *querytracer.Tracer, startTime time.Time, at *auth.Token, w http.ResponseWriter, r *http.Request) error { defer seriesDuration.UpdateDuration(startTime) - cp, err := getCommonParams(r, startTime, true) - if err != nil { - return err - } // Do not set start to searchutils.minTimeMsecs by default as Prometheus does, // since this leads to fetching and scanning all the data from the storage, // which can take a lot of time for big storages. // It is better setting start as end-defaultStep by default. // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/91 - if cp.start == 0 { - cp.start = cp.end - defaultStep + cp, err := getCommonParamsWithDefaultDuration(r, startTime, true) + if err != nil { + return err } limit, err := searchutils.GetInt(r, "limit") if err != nil { @@ -1137,6 +1134,17 @@ func getExportParams(r *http.Request, startTime time.Time) (*commonParams, error return cp, nil } +func getCommonParamsWithDefaultDuration(r *http.Request, startTime time.Time, requireNonEmptyMatch bool) (*commonParams, error) { + cp, err := getCommonParams(r, startTime, requireNonEmptyMatch) + if err != nil { + return nil, err + } + if cp.start == 0 { + cp.start = cp.end - defaultStep + } + return cp, nil +} + // getCommonParams obtains common params from r, which are used in /api/v1/* handlers: // // - timeout @@ -1147,13 +1155,12 @@ func getExportParams(r *http.Request, startTime time.Time) (*commonParams, error // - extra_filters[] func getCommonParams(r *http.Request, startTime time.Time, requireNonEmptyMatch bool) (*commonParams, error) { deadline := searchutils.GetDeadlineForQuery(r, startTime) - ct := startTime.UnixNano() / 1e6 - start, err := searchutils.GetTime(r, "start", ct-3*defaultStep) + start, err := searchutils.GetTime(r, "start", 0) if err != nil { return nil, err } + ct := startTime.UnixNano() / 1e6 end, err := searchutils.GetTime(r, "end", ct) - if err != nil { return nil, err } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3a86a3d7f5..e9225ebf75 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,6 +15,8 @@ The following tip changes can be tested by building VictoriaMetrics components f ## tip +* FEATURE: set the `start` arg to `end - 5 minutes` if isn't passed explicitly to [/api/v1/labels](https://docs.victoriametrics.com/url-examples.html#apiv1labels) and [/api/v1/label/.../values](https://docs.victoriametrics.com/url-examples.html#apiv1labelvalues). + * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly calculate `rate_over_sum(m[d])` as `sum_over_time(m[d])/d`. Previously the `sum_over_time(m[d])` could be improperly divided by smaller than `d` time range. See [rate_over_sum() docs](https://docs.victoriametrics.com/MetricsQL.html#rate_over_sum) and [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3045). diff --git a/docs/README.md b/docs/README.md index 51a3a98815..3d72e3eebe 100644 --- a/docs/README.md +++ b/docs/README.md @@ -638,7 +638,7 @@ VictoriaMetrics accepts `round_digits` query arg for `/api/v1/query` and `/api/v VictoriaMetrics accepts `limit` query arg for `/api/v1/labels` and `/api/v1/label//values` handlers for limiting the number of returned entries. For example, the query to `/api/v1/labels?limit=5` returns a sample of up to 5 unique labels, while ignoring the rest of labels. If the provided `limit` value exceeds the corresponding `-search.maxTagKeys` / `-search.maxTagValues` command-line flag values, then limits specified in the command-line flags are used. -By default, VictoriaMetrics returns time series for the last 5 minutes from `/api/v1/series`, while the Prometheus API defaults to all time. Use `start` and `end` to select a different time range. +By default, VictoriaMetrics returns time series for the last 5 minutes from `/api/v1/series`, `/api/v1/labels` and `/api/v1/label//values` while the Prometheus API defaults to all time. Explicitly set `start` and `end` to select the desired time range. VictoriaMetrics accepts `limit` query arg for `/api/v1/series` handlers for limiting the number of returned entries. For example, the query to `/api/v1/series?limit=5` returns a sample of up to 5 series, while ignoring the rest. If the provided `limit` value exceeds the corresponding `-search.maxSeries` command-line flag values, then limits specified in the command-line flags are used. Additionally, VictoriaMetrics provides the following handlers: diff --git a/docs/Single-server-VictoriaMetrics.md b/docs/Single-server-VictoriaMetrics.md index 5b847e4705..aef1b24043 100644 --- a/docs/Single-server-VictoriaMetrics.md +++ b/docs/Single-server-VictoriaMetrics.md @@ -642,7 +642,7 @@ VictoriaMetrics accepts `round_digits` query arg for `/api/v1/query` and `/api/v VictoriaMetrics accepts `limit` query arg for `/api/v1/labels` and `/api/v1/label//values` handlers for limiting the number of returned entries. For example, the query to `/api/v1/labels?limit=5` returns a sample of up to 5 unique labels, while ignoring the rest of labels. If the provided `limit` value exceeds the corresponding `-search.maxTagKeys` / `-search.maxTagValues` command-line flag values, then limits specified in the command-line flags are used. -By default, VictoriaMetrics returns time series for the last 5 minutes from `/api/v1/series`, while the Prometheus API defaults to all time. Use `start` and `end` to select a different time range. +By default, VictoriaMetrics returns time series for the last 5 minutes from `/api/v1/series`, `/api/v1/labels` and `/api/v1/label//values` while the Prometheus API defaults to all time. Explicitly set `start` and `end` to select the desired time range. VictoriaMetrics accepts `limit` query arg for `/api/v1/series` handlers for limiting the number of returned entries. For example, the query to `/api/v1/series?limit=5` returns a sample of up to 5 series, while ignoring the rest. If the provided `limit` value exceeds the corresponding `-search.maxSeries` command-line flag values, then limits specified in the command-line flags are used. Additionally, VictoriaMetrics provides the following handlers: diff --git a/docs/url-examples.md b/docs/url-examples.md index 9700b73260..ca00f36808 100644 --- a/docs/url-examples.md +++ b/docs/url-examples.md @@ -267,7 +267,7 @@ Additional information: ## /api/v1/labels -**Get a list of label names** +**Get a list of label names at the given time range** Single-node VictoriaMetrics:
@@ -287,6 +287,8 @@ curl http://:8481/select/0/prometheus/api/v1/labels
+By default VictoriaMetrics returns labels seen during the last 5 minutes. An arbitrary time range can be set via `start` and `end` query args. + Additional information: * [Prometheus querying API usage](https://docs.victoriametrics.com/#prometheus-querying-api-usage) * [Querying label values](https://prometheus.io/docs/prometheus/latest/querying/api/#querying-label-values) @@ -294,7 +296,7 @@ Additional information: ## /api/v1/label/.../values -**Get a list of values for a particular label** +**Get a list of values for a particular label on the given time range** Single-node VictoriaMetrics:
@@ -314,6 +316,8 @@ curl http://:8481/select/0/prometheus/api/v1/label/job/values
+By default VictoriaMetrics returns label values seen during the last 5 minutes. An arbitrary time range can be set via `start` and `end` query args. + Additional information: * [Prometheus querying API usage](https://docs.victoriametrics.com/#prometheus-querying-api-usage) * [Getting label names](https://prometheus.io/docs/prometheus/latest/querying/api/#getting-label-names) @@ -377,7 +381,7 @@ Additional information: ## /api/v1/series -**Returns series names with their labels** +**Returns series names with their labels on the given time range** Single-node VictoriaMetrics:
@@ -397,6 +401,8 @@ curl http://:8481/select/0/prometheus/api/v1/series -d 'match[]=vm_htt
+By default VictoriaMetrics returns time series seen during the last 5 minutes. An arbitrary time range can be set via `start` and `end` query args. + Additional information: * [Prometheus querying API usage](https://docs.victoriametrics.com/#prometheus-querying-api-usage) * [Finding series by label matchers](https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers)