vmui: remove redundant requests on the Explore Cardinality page (#6263)

Remove redundant requests on the Explore Cardinality page.

https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6240
(cherry picked from commit be291c36f7)
This commit is contained in:
Yury Molodov 2024-05-17 14:08:33 +02:00 committed by hagen1778
parent 0edef9105b
commit 5bfbfe6ad2
No known key found for this signature in database
GPG key ID: 3BF75F3741CA9640
2 changed files with 8 additions and 5 deletions

View file

@ -1,6 +1,6 @@
import { ErrorTypes } from "../../../types";
import { useAppState } from "../../../state/common/StateContext";
import { useEffect, useState } from "preact/compat";
import { useEffect, useRef, useState } from "preact/compat";
import { CardinalityRequestsParams, getCardinalityInfo } from "../../../api/tsdb";
import { TSDBStatus } from "../types";
import AppConfigurator from "../appConfigurator";
@ -25,6 +25,7 @@ export const useFetchQuery = (): {
const topN = +(searchParams.get("topN") || 10);
const date = searchParams.get("date") || dayjs().tz().format(DATE_FORMAT);
const prevDate = usePrevious(date);
const prevTotal = useRef<{data: TSDBStatus}>();
const { serverUrl } = useAppState();
const [isLoading, setIsLoading] = useState(false);
@ -72,7 +73,7 @@ export const useFetchQuery = (): {
const prevDayParams = {
...requestParams,
date: dayjs(requestParams.date).subtract(1, "day").tz().format(DATE_FORMAT),
date: dayjs(requestParams.date).subtract(1, "day").format(DATE_FORMAT),
};
const urls = [
@ -80,15 +81,16 @@ export const useFetchQuery = (): {
getCardinalityInfo(serverUrl, prevDayParams),
];
if (prevDate !== date) {
if (prevDate !== date && (requestParams.match || requestParams.focusLabel)) {
urls.push(getCardinalityInfo(serverUrl, totalParams));
}
try {
const [resp, respPrev, respTotals = {}] = await Promise.all(urls.map(getResponseJson));
const [resp, respPrev, respTotals] = await Promise.all(urls.map(getResponseJson));
const prevResult = { ...respPrev.data };
const { data: dataTotal } = respTotals;
const { data: dataTotal } = respTotals || prevTotal.current || resp;
prevTotal.current = { data: dataTotal as TSDBStatus };
const result: TSDBStatus = {
...resp.data,
totalSeries: resp.data?.totalSeries || resp.data?.headStats?.numSeries || 0,

View file

@ -49,6 +49,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/).
* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix bug that prevents the first query trace from expanding on click event. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6186). The issue was introduced in [v1.100.0](https://docs.victoriametrics.com/changelog/#v11000) release.
* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix calendar display when `UTC+00:00` timezone is set. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6239).
* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): remove redundant requests on the `Explore Cardinality` page. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6240).
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent/): prevent potential panic during [stream aggregation](https://docs.victoriametrics.com/stream-aggregation.html) if more than one `--remoteWrite.streamAggr.dedupInterval` is configured. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6205).
* BUGFIX: [stream aggregation](https://docs.victoriametrics.com/stream-aggregation/): set correct suffix `<output>_prometheus` for aggregation outputs [increase_prometheus](https://docs.victoriametrics.com/stream-aggregation/#increase_prometheus) and [total_prometheus](https://docs.victoriametrics.com/stream-aggregation/#total_prometheus). Before, outputs `total` and `total_prometheus` or `increase` and `increase_prometheus` had the same suffix.
* BUGFIX: properly estimate the needed memory for query execution if it has the format [`aggr_func`](https://docs.victoriametrics.com/metricsql/#aggregate-functions)([`rollup_func[d]`](https://docs.victoriametrics.com/metricsql/#rollup-functions) (for example, `sum(rate(request_duration_seconds_bucket[5m]))`). This should allow performing aggregations over bigger number of time series when VictoriaMetrics runs in environments with small amounts of available memory. The issue has been introduced in [this commit](https://github.com/VictoriaMetrics/VictoriaMetrics/commit/5138eaeea0791caa34bcfab410e0ca9cd253cd8f) in [v1.83.0](https://docs.victoriametrics.com/changelog_2022/#v1830).