From 5bfbfe6ad2ccdea1152a7f985e1dbc8254027c92 Mon Sep 17 00:00:00 2001 From: Yury Molodov Date: Fri, 17 May 2024 14:08:33 +0200 Subject: [PATCH] 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 be291c36f7288aa8ee3d40763fc83ecaff08346e) --- .../CardinalityPanel/hooks/useCardinalityFetch.ts | 12 +++++++----- docs/CHANGELOG.md | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/vmui/packages/vmui/src/pages/CardinalityPanel/hooks/useCardinalityFetch.ts b/app/vmui/packages/vmui/src/pages/CardinalityPanel/hooks/useCardinalityFetch.ts index 8764184eea..1e5426bc0f 100644 --- a/app/vmui/packages/vmui/src/pages/CardinalityPanel/hooks/useCardinalityFetch.ts +++ b/app/vmui/packages/vmui/src/pages/CardinalityPanel/hooks/useCardinalityFetch.ts @@ -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, diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 281c1ecd23..ec40259add 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 `_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).