SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
chore: replace search bar in inspect page (#10342)
Amlan Kumar Nandya9b1dd8510d6
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/__tests__/QuerySearch.test.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/__tests__/QuerySearch.test.tsxindex 09cf910f80..e68b65c7a6 100644--- a/frontend/src/components/QueryBuilderV2/QueryV2/__tests__/QuerySearch.test.tsx+++ b/frontend/src/components/QueryBuilderV2/QueryV2/__tests__/QuerySearch.test.tsx@@ -6,6 +6,7 @@ import { getKeySuggestions } from 'api/querySuggestions/getKeySuggestions';import { getValueSuggestions } from 'api/querySuggestions/getValueSuggestion';import { initialQueriesMap } from 'constants/queryBuilder';import { fireEvent, render, userEvent, waitFor } from 'tests/test-utils';+import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';import type { QueryKeyDataSuggestionsProps } from 'types/api/querySuggestions/types';import { DataSource } from 'types/common/queryBuilder';@@ -367,4 +368,36 @@ describe('QuerySearch (Integration with Real CodeMirror)', () => {dispatchSpy.mockRestore();});++ it('fetches key suggestions for metrics even without aggregateAttribute.key when showFilterSuggestionsWithoutMetric is true', async () => {+ const mockedGetKeys = getKeySuggestions as jest.MockedFunction<+ typeof getKeySuggestions+ >;+ mockedGetKeys.mockClear();++ const queryData = {+ ...initialQueriesMap.metrics.builder.queryData[0],+ aggregateAttribute: {+ key: '',+ dataType: DataTypes.String,+ type: 'string',+ },+ };++ render(+ <QuerySearch+ onChange={jest.fn()}+ queryData={queryData}+ dataSource={DataSource.METRICS}+ showFilterSuggestionsWithoutMetric+ />,+ );++ await waitFor(+ () => {+ expect(mockedGetKeys).toHaveBeenCalled();+ },+ { timeout: 2000 },+ );+ });});diff --git a/frontend/src/container/MetricsExplorer/Inspect/ExpandedView.tsx b/frontend/src/container/MetricsExplorer/Inspect/ExpandedView.tsxindex 49af1e367c..53a133931b 100644--- a/frontend/src/container/MetricsExplorer/Inspect/ExpandedView.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/ExpandedView.tsx@@ -33,7 +33,7 @@ function ExpandedView({options,spaceAggregationSeriesMap,step,- metricInspectionOptions,+ metricInspectionAppliedOptions,timeAggregatedSeriesMap,}: ExpandedViewProps): JSX.Element {const [@@ -44,17 +44,17 @@ function ExpandedView({useEffect(() => {logEvent(MetricsExplorerEvents.InspectPointClicked, {[MetricsExplorerEventKeys.Modal]: 'inspect',- [MetricsExplorerEventKeys.Filters]: metricInspectionOptions.filters,+ [MetricsExplorerEventKeys.Filters]: metricInspectionAppliedOptions.filters,[MetricsExplorerEventKeys.TimeAggregationInterval]:- metricInspectionOptions.timeAggregationInterval,+ metricInspectionAppliedOptions.timeAggregationInterval,[MetricsExplorerEventKeys.TimeAggregationOption]:- metricInspectionOptions.timeAggregationOption,+ metricInspectionAppliedOptions.timeAggregationOption,[MetricsExplorerEventKeys.SpaceAggregationOption]:- metricInspectionOptions.spaceAggregationOption,+ metricInspectionAppliedOptions.spaceAggregationOption,[MetricsExplorerEventKeys.SpaceAggregationLabels]:- metricInspectionOptions.spaceAggregationLabels,+ metricInspectionAppliedOptions.spaceAggregationLabels,});- }, [metricInspectionOptions]);+ }, [metricInspectionAppliedOptions]);useEffect(() => {if (step !== InspectionStep.COMPLETED) {@@ -167,7 +167,7 @@ function ExpandedView({<Typography.Text strong>{`${absoluteValue} is the ${SPACE_AGGREGATION_OPTIONS_FOR_EXPANDED_VIEW[- metricInspectionOptions.spaceAggregationOption ??+ metricInspectionAppliedOptions.spaceAggregationOption ??SpaceAggregationOptions.SUM_BY]} of`}@@ -240,7 +240,7 @@ function ExpandedView({)?.value ?? options?.value} is the ${TIME_AGGREGATION_OPTIONS[- metricInspectionOptions.timeAggregationOption ??+ metricInspectionAppliedOptions.timeAggregationOption ??TimeAggregationOptions.SUM]} of`@@ -299,7 +299,7 @@ function ExpandedView({<Typography.Text strong>{`${absoluteValue} is the ${TIME_AGGREGATION_OPTIONS[- metricInspectionOptions.timeAggregationOption ??+ metricInspectionAppliedOptions.timeAggregationOption ??TimeAggregationOptions.SUM]} of`}diff --git a/frontend/src/container/MetricsExplorer/Inspect/GraphView.tsx b/frontend/src/container/MetricsExplorer/Inspect/GraphView.tsxindex 040717aa4e..5d25dcaf20 100644--- a/frontend/src/container/MetricsExplorer/Inspect/GraphView.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/GraphView.tsx@@ -13,9 +13,10 @@ import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import { formatNumberIntoHumanReadableFormat } from '../Summary/utils';import { METRIC_TYPE_TO_COLOR_MAP, METRIC_TYPE_TO_ICON_MAP } from './constants';import GraphPopover from './GraphPopover';+import HoverPopover from './HoverPopover';import TableView from './TableView';import { GraphPopoverOptions, GraphViewProps } from './types';-import { HoverPopover, onGraphClick, onGraphHover } from './utils';+import { onGraphClick, onGraphHover } from './utils';function GraphView({inspectMetricsTimeSeries,@@ -29,7 +30,7 @@ function GraphView({popoverOptions,setShowExpandedView,setExpandedViewOptions,- metricInspectionOptions,+ metricInspectionAppliedOptions,isInspectMetricsRefetching,}: GraphViewProps): JSX.Element {const isDarkMode = useIsDarkMode();@@ -233,7 +234,7 @@ function GraphView({inspectMetricsTimeSeries={inspectMetricsTimeSeries}setShowExpandedView={setShowExpandedView}setExpandedViewOptions={setExpandedViewOptions}- metricInspectionOptions={metricInspectionOptions}+ metricInspectionAppliedOptions={metricInspectionAppliedOptions}isInspectMetricsRefetching={isInspectMetricsRefetching}/>)}@@ -255,7 +256,7 @@ function GraphView({<HoverPopoveroptions={hoverPopoverOptions}step={inspectionStep}- metricInspectionOptions={metricInspectionOptions}+ metricInspectionAppliedOptions={metricInspectionAppliedOptions}/>)}</div>diff --git a/frontend/src/container/MetricsExplorer/Inspect/HoverPopover.tsx b/frontend/src/container/MetricsExplorer/Inspect/HoverPopover.tsxnew file mode 100644index 0000000000..4abd16c3be--- /dev/null+++ b/frontend/src/container/MetricsExplorer/Inspect/HoverPopover.tsx@@ -0,0 +1,111 @@+import { useMemo } from 'react';+import { Card, Typography } from 'antd';++import {+ GraphPopoverOptions,+ InspectionStep,+ MetricInspectionOptions,+} from './types';+import { TimeSeriesLabelProps } from './types';+import { formatTimestampToFullDateTime } from './utils';++function TimeSeriesLabel({+ timeSeries,+ textColor,+}: TimeSeriesLabelProps): JSX.Element {+ return (+ <>+ {Object.entries(timeSeries?.labels ?? {}).map(([key, value]) => (+ <span key={key}>+ <Typography.Text style={{ color: textColor, fontWeight: 600 }}>+ {key}+ </Typography.Text>+ : {value}{' '}+ </span>+ ))}+ </>+ );+}++function HoverPopover({+ options,+ step,+ metricInspectionAppliedOptions,+}: {+ options: GraphPopoverOptions;+ step: InspectionStep;+ metricInspectionAppliedOptions: MetricInspectionOptions;+}): JSX.Element {+ const closestTimestamp = useMemo(() => {+ if (!options.timeSeries) {+ return options.timestamp;+ }+ return options.timeSeries?.values.reduce((prev, curr) => {+ const prevDiff = Math.abs(prev.timestamp - options.timestamp);+ const currDiff = Math.abs(curr.timestamp - options.timestamp);+ return prevDiff < currDiff ? prev : curr;+ }).timestamp;+ }, [options.timeSeries, options.timestamp]);++ const closestValue = useMemo(() => {+ if (!options.timeSeries) {+ return options.value;+ }+ const index = options.timeSeries.values.findIndex(+ (value) => value.timestamp === closestTimestamp,+ );+ return index !== undefined && index >= 0+ ? options.timeSeries?.values[index].value+ : null;+ }, [options.timeSeries, closestTimestamp, options.value]);++ const title = useMemo(() => {+ if (+ step === InspectionStep.COMPLETED &&+ metricInspectionAppliedOptions.spaceAggregationLabels.length === 0+ ) {+ return undefined;+ }+ if (step === InspectionStep.COMPLETED && options.timeSeries?.title) {+ return options.timeSeries.title;+ }+ if (!options.timeSeries) {+ return undefined;+ }+ return (+ <TimeSeriesLabel+ timeSeries={options.timeSeries}+ textColor={options.timeSeries?.strokeColor}+ />+ );+ }, [step, options.timeSeries, metricInspectionAppliedOptions]);++ return (+ <Card+ className="hover-popover-card"+ style={{+ top: options.y + 10,+ left: options.x + 10,+ }}+ >+ <div className="hover-popover-row">+ <Typography.Text>+ {formatTimestampToFullDateTime(closestTimestamp ?? 0)}+ </Typography.Text>+ <Typography.Text>{Number(closestValue).toFixed(2)}</Typography.Text>+ </div>+ {options.timeSeries && (+ <Typography.Text+ style={{+ color: options.timeSeries?.strokeColor,+ fontWeight: 200,+ }}+ >+ {title}+ </Typography.Text>+ )}+ </Card>+ );+}++export default HoverPopover;diff --git a/frontend/src/container/MetricsExplorer/Inspect/Inspect.styles.scss b/frontend/src/container/MetricsExplorer/Inspect/Inspect.styles.scssindex 721049f6d6..dc48c7f31e 100644--- a/frontend/src/container/MetricsExplorer/Inspect/Inspect.styles.scss+++ b/frontend/src/container/MetricsExplorer/Inspect/Inspect.styles.scss@@ -122,6 +122,10 @@gap: 4px;.inspect-metrics-query-builder-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+.query-builder-button-label {display: flex;align-items: center;@@ -257,6 +261,21 @@.completed-checklist-container {margin-left: 20px;++ .completed-checklist-item,+ .whats-next-checklist-item {+ .completed-checklist-item-title,+ .whats-next-checklist-item-title {+ display: flex;+ align-items: center;+ gap: 4px;+ .ant-typography {+ display: flex;+ align-items: center;+ gap: 4px;+ }+ }+ }}.completed-message-container {diff --git a/frontend/src/container/MetricsExplorer/Inspect/Inspect.tsx b/frontend/src/container/MetricsExplorer/Inspect/Inspect.tsxindex 39220b16c5..153919dffe 100644--- a/frontend/src/container/MetricsExplorer/Inspect/Inspect.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/Inspect.tsx@@ -9,6 +9,7 @@ import { useQueryOperations } from 'hooks/queryBuilder/useQueryBuilderOperationsimport { useIsDarkMode } from 'hooks/useDarkMode';import { Compass } from 'lucide-react';import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';+import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';@@ -31,7 +32,12 @@ function Inspect({onClose,}: InspectProps): JSX.Element {const isDarkMode = useIsDarkMode();- const [metricName, setMetricName] = useState<string | null>(defaultMetricName);+ const [currentMetricName, setCurrentMetricName] = useState<string>(+ defaultMetricName,+ );+ const [appliedMetricName, setAppliedMetricName] = useState<string>(+ defaultMetricName,+ );const [popoverOptions,setPopoverOptions,@@ -42,9 +48,12 @@ function Inspect({] = useState<GraphPopoverOptions | null>(null);const [showExpandedView, setShowExpandedView] = useState(false);- const { data: metricDetailsData } = useGetMetricDetails(metricName ?? '', {- enabled: !!metricName,- });+ const { data: metricDetailsData } = useGetMetricDetails(+ appliedMetricName ?? '',+ {+ enabled: !!appliedMetricName,+ },+ );const { currentQuery } = useQueryBuilder();const { handleChangeQueryData } = useQueryOperations({@@ -97,25 +106,16 @@ function Inspect({aggregatedTimeSeries,timeAggregatedSeriesMap,reset,- } = useInspectMetrics(metricName);+ } = useInspectMetrics(appliedMetricName);const handleDispatchMetricInspectionOptions = useCallback((action: MetricInspectionAction): void => {dispatchMetricInspectionOptions(action);logEvent(MetricsExplorerEvents.InspectQueryChanged, {[MetricsExplorerEventKeys.Modal]: 'inspect',- [MetricsExplorerEventKeys.Filters]: metricInspectionOptions.filters,- [MetricsExplorerEventKeys.TimeAggregationInterval]:- metricInspectionOptions.timeAggregationInterval,- [MetricsExplorerEventKeys.TimeAggregationOption]:- metricInspectionOptions.timeAggregationOption,- [MetricsExplorerEventKeys.SpaceAggregationOption]:- metricInspectionOptions.spaceAggregationOption,- [MetricsExplorerEventKeys.SpaceAggregationLabels]:- metricInspectionOptions.spaceAggregationLabels,});},- [dispatchMetricInspectionOptions, metricInspectionOptions],+ [dispatchMetricInspectionOptions],);const selectedMetricType = useMemo(@@ -128,18 +128,39 @@ function Inspect({[metricDetailsData],);+ const aggregateAttribute = useMemo(+ () => ({+ key: currentMetricName ?? '',+ dataType: DataTypes.String,+ type: selectedMetricType as string,+ isColumn: true,+ isJSON: false,+ id: `${currentMetricName}--${DataTypes.String}--${selectedMetricType}--true`,+ }),+ [currentMetricName, selectedMetricType],+ );++ const [currentQueryData, setCurrentQueryData] = useState<IBuilderQuery>({+ ...searchQuery,+ aggregateAttribute,+ });++ useEffect(() => {+ if (searchQuery) {+ setCurrentQueryData({+ ...searchQuery,+ aggregateAttribute,+ });+ }+ }, [aggregateAttribute, searchQuery]);+const resetInspection = useCallback(() => {setShowExpandedView(false);setPopoverOptions(null);setExpandedViewOptions(null);+ setCurrentQueryData(searchQuery as IBuilderQuery);reset();- }, [reset]);-- // Reset inspection when the selected metric changes- useEffect(() => {- resetInspection();- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [metricName]);+ }, [reset, searchQuery]);// Hide expanded view whenever inspection step changesuseEffect(() => {@@ -193,7 +214,7 @@ function Inspect({inspectMetricsTimeSeries={aggregatedTimeSeries}formattedInspectMetricsTimeSeries={formattedInspectMetricsTimeSeries}resetInspection={resetInspection}- metricName={metricName}+ metricName={appliedMetricName}metricUnit={selectedMetricUnit}metricType={selectedMetricType}spaceAggregationSeriesMap={spaceAggregationSeriesMap}@@ -203,19 +224,20 @@ function Inspect({showExpandedView={showExpandedView}setExpandedViewOptions={setExpandedViewOptions}popoverOptions={popoverOptions}- metricInspectionOptions={metricInspectionOptions}+ metricInspectionAppliedOptions={metricInspectionOptions.appliedOptions}isInspectMetricsRefetching={isInspectMetricsRefetching}/><QueryBuilder- metricName={metricName}- metricType={selectedMetricType}- setMetricName={setMetricName}+ currentMetricName={currentMetricName}+ setCurrentMetricName={setCurrentMetricName}+ setAppliedMetricName={setAppliedMetricName}spaceAggregationLabels={spaceAggregationLabels}- metricInspectionOptions={metricInspectionOptions}+ currentMetricInspectionOptions={metricInspectionOptions.currentOptions}dispatchMetricInspectionOptions={handleDispatchMetricInspectionOptions}inspectionStep={inspectionStep}inspectMetricsTimeSeries={inspectMetricsTimeSeries}- searchQuery={searchQuery as IBuilderQuery}+ currentQuery={currentQueryData}+ setCurrentQuery={setCurrentQueryData}/></div><div className="inspect-metrics-content-second-col">@@ -228,7 +250,7 @@ function Inspect({options={expandedViewOptions}spaceAggregationSeriesMap={spaceAggregationSeriesMap}step={inspectionStep}- metricInspectionOptions={metricInspectionOptions}+ metricInspectionAppliedOptions={metricInspectionOptions.appliedOptions}timeAggregatedSeriesMap={timeAggregatedSeriesMap}/>)}@@ -244,17 +266,21 @@ function Inspect({aggregatedTimeSeries,formattedInspectMetricsTimeSeries,resetInspection,- metricName,+ appliedMetricName,selectedMetricUnit,selectedMetricType,spaceAggregationSeriesMap,inspectionStep,showExpandedView,popoverOptions,- metricInspectionOptions,+ metricInspectionOptions.appliedOptions,+ metricInspectionOptions.currentOptions,+ currentMetricName,+ setCurrentMetricName,+ setAppliedMetricName,spaceAggregationLabels,handleDispatchMetricInspectionOptions,- searchQuery,+ currentQueryData,expandedViewOptions,timeAggregatedSeriesMap,]);diff --git a/frontend/src/container/MetricsExplorer/Inspect/MetricFilters.tsx b/frontend/src/container/MetricsExplorer/Inspect/MetricFilters.tsxnew file mode 100644index 0000000000..9c3713b74a--- /dev/null+++ b/frontend/src/container/MetricsExplorer/Inspect/MetricFilters.tsx@@ -0,0 +1,57 @@+import { useCallback } from 'react';+import { Typography } from 'antd';+import logEvent from 'api/common/logEvent';+import QuerySearch from 'components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch';+import { convertExpressionToFilters } from 'components/QueryBuilderV2/utils';+import { DataSource } from 'types/common/queryBuilder';++import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';+import { MetricFiltersProps } from './types';++function MetricFilters({+ dispatchMetricInspectionOptions,+ currentQuery,+ setCurrentQuery,+}: MetricFiltersProps): JSX.Element {+ const handleOnChange = useCallback(+ (expression: string): void => {+ logEvent(MetricsExplorerEvents.FilterApplied, {+ [MetricsExplorerEventKeys.Modal]: 'inspect',+ });+ const tagFilter = {+ items: convertExpressionToFilters(expression),+ op: 'AND',+ };+ setCurrentQuery({+ ...currentQuery,+ filters: tagFilter,+ filter: {+ ...currentQuery.filter,+ expression,+ },+ expression,+ });+ dispatchMetricInspectionOptions({+ type: 'SET_FILTERS',+ payload: tagFilter,+ });+ },+ [currentQuery, dispatchMetricInspectionOptions, setCurrentQuery],+ );++ return (+ <div+ data-testid="metric-filters"+ className="inspect-metrics-input-group metric-filters"+ >+ <Typography.Text>Where</Typography.Text>+ <QuerySearch+ queryData={currentQuery}+ onChange={handleOnChange}+ dataSource={DataSource.METRICS}+ />+ </div>+ );+}++export default MetricFilters;diff --git a/frontend/src/container/MetricsExplorer/Inspect/MetricNameSearch.tsx b/frontend/src/container/MetricsExplorer/Inspect/MetricNameSearch.tsxnew file mode 100644index 0000000000..093911e140--- /dev/null+++ b/frontend/src/container/MetricsExplorer/Inspect/MetricNameSearch.tsx@@ -0,0 +1,40 @@+import { useState } from 'react';+import { Typography } from 'antd';+import { initialQueriesMap } from 'constants/queryBuilder';+import { AggregatorFilter } from 'container/QueryBuilder/filters';+import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';+import { DataSource } from 'types/common/queryBuilder';++import { MetricNameSearchProps } from './types';++function MetricNameSearch({+ currentMetricName,+ setCurrentMetricName,+}: MetricNameSearchProps): JSX.Element {+ const [searchText, setSearchText] = useState(currentMetricName);++ const handleSetMetricName = (value: BaseAutocompleteData): void => {+ setCurrentMetricName(value.key);+ };++ const handleChange = (value: BaseAutocompleteData): void => {+ setSearchText(value.key);+ };++ return (+ <div+ data-testid="metric-name-search"+ className="inspect-metrics-input-group metric-name-search"+ >+ <Typography.Text>From</Typography.Text>+ <AggregatorFilter+ defaultValue={searchText ?? ''}+ query={initialQueriesMap[DataSource.METRICS].builder.queryData[0]}+ onSelect={handleSetMetricName}+ onChange={handleChange}+ />+ </div>+ );+}++export default MetricNameSearch;diff --git a/frontend/src/container/MetricsExplorer/Inspect/MetricSpaceAggregation.tsx b/frontend/src/container/MetricsExplorer/Inspect/MetricSpaceAggregation.tsxnew file mode 100644index 0000000000..cc7e53de7b--- /dev/null+++ b/frontend/src/container/MetricsExplorer/Inspect/MetricSpaceAggregation.tsx@@ -0,0 +1,73 @@+import { Typography } from 'antd';+import { Select } from 'antd';+import classNames from 'classnames';++import { SPACE_AGGREGATION_OPTIONS } from './constants';+import { InspectionStep } from './types';+import { MetricSpaceAggregationProps } from './types';++function MetricSpaceAggregation({+ spaceAggregationLabels,+ currentMetricInspectionOptions,+ dispatchMetricInspectionOptions,+ inspectionStep,+}: MetricSpaceAggregationProps): JSX.Element {+ return (+ <div+ data-testid="metric-space-aggregation"+ className="metric-space-aggregation"+ >+ <div+ className={classNames('metric-space-aggregation-header', {+ 'selected-step': inspectionStep === InspectionStep.SPACE_AGGREGATION,+ })}+ >+ <Typography.Text>AGGREGATE BY LABELS</Typography.Text>+ </div>+ <div className="metric-space-aggregation-content">+ <div className="metric-space-aggregation-content-left">+ <Select+ value={currentMetricInspectionOptions.spaceAggregationOption}+ placeholder="Select option"+ onChange={(value): void => {+ dispatchMetricInspectionOptions({+ type: 'SET_SPACE_AGGREGATION_OPTION',+ payload: value,+ });+ }}+ style={{ width: 130 }}+ disabled={inspectionStep === InspectionStep.TIME_AGGREGATION}+ >+ {/* eslint-disable-next-line sonarjs/no-identical-functions */}+ {Object.entries(SPACE_AGGREGATION_OPTIONS).map(([key, value]) => (+ <Select.Option key={key} value={key}>+ {value}+ </Select.Option>+ ))}+ </Select>+ </div>+ <Select+ mode="multiple"+ style={{ width: '100%' }}+ placeholder="Search for attributes..."+ value={currentMetricInspectionOptions.spaceAggregationLabels}+ onChange={(value): void => {+ dispatchMetricInspectionOptions({+ type: 'SET_SPACE_AGGREGATION_LABELS',+ payload: value,+ });+ }}+ disabled={inspectionStep === InspectionStep.TIME_AGGREGATION}+ >+ {spaceAggregationLabels.map((label) => (+ <Select.Option key={label} value={label}>+ {label}+ </Select.Option>+ ))}+ </Select>+ </div>+ </div>+ );+}++export default MetricSpaceAggregation;diff --git a/frontend/src/container/MetricsExplorer/Inspect/MetricTimeAggregation.tsx b/frontend/src/container/MetricsExplorer/Inspect/MetricTimeAggregation.tsxnew file mode 100644index 0000000000..7e8fb49e17--- /dev/null+++ b/frontend/src/container/MetricsExplorer/Inspect/MetricTimeAggregation.tsx@@ -0,0 +1,80 @@+import { Input, Typography } from 'antd';+import { Select } from 'antd';+import classNames from 'classnames';++import { TIME_AGGREGATION_OPTIONS } from './constants';+import { InspectionStep } from './types';+import { MetricTimeAggregationProps } from './types';+import { getDefaultTimeAggregationInterval } from './utils';++function MetricTimeAggregation({+ currentMetricInspectionOptions,+ dispatchMetricInspectionOptions,+ inspectionStep,+ inspectMetricsTimeSeries,+}: MetricTimeAggregationProps): JSX.Element {+ return (+ <div+ data-testid="metric-time-aggregation"+ className="metric-time-aggregation"+ >+ <div+ className={classNames('metric-time-aggregation-header', {+ 'selected-step': inspectionStep === InspectionStep.TIME_AGGREGATION,+ })}+ >+ <Typography.Text>AGGREGATE BY TIME</Typography.Text>+ </div>+ <div className="metric-time-aggregation-content">+ <div className="inspect-metrics-input-group">+ <Typography.Text>Align with</Typography.Text>+ <Select+ value={currentMetricInspectionOptions.timeAggregationOption}+ onChange={(value): void => {+ dispatchMetricInspectionOptions({+ type: 'SET_TIME_AGGREGATION_OPTION',+ payload: value,+ });+ // set the time aggregation interval to the default value if it is not set+ if (!currentMetricInspectionOptions.timeAggregationInterval) {+ dispatchMetricInspectionOptions({+ type: 'SET_TIME_AGGREGATION_INTERVAL',+ payload: getDefaultTimeAggregationInterval(+ inspectMetricsTimeSeries[0],+ ),+ });+ }+ }}+ style={{ width: 130 }}+ placeholder="Select option"+ >+ {Object.entries(TIME_AGGREGATION_OPTIONS).map(([key, value]) => (+ <Select.Option key={key} value={key}>+ {value}+ </Select.Option>+ ))}+ </Select>+ </div>+ <div className="inspect-metrics-input-group">+ <Typography.Text>aggregated every</Typography.Text>+ <Input+ type="number"+ className="no-arrows-input"+ value={currentMetricInspectionOptions.timeAggregationInterval}+ placeholder="Select interval..."+ suffix="seconds"+ onChange={(e): void => {+ dispatchMetricInspectionOptions({+ type: 'SET_TIME_AGGREGATION_INTERVAL',+ payload: parseInt(e.target.value, 10),+ });+ }}+ onWheel={(e): void => (e.target as HTMLInputElement).blur()}+ />+ </div>+ </div>+ </div>+ );+}++export default MetricTimeAggregation;diff --git a/frontend/src/container/MetricsExplorer/Inspect/QueryBuilder.tsx b/frontend/src/container/MetricsExplorer/Inspect/QueryBuilder.tsxindex 6f00d8c3a3..4327fb4e19 100644--- a/frontend/src/container/MetricsExplorer/Inspect/QueryBuilder.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/QueryBuilder.tsx@@ -1,25 +1,33 @@+import { useCallback } from 'react';import { Button, Card } from 'antd';+import RunQueryBtn from 'container/QueryBuilder/components/RunQueryBtn/RunQueryBtn';import { Atom } from 'lucide-react';+import MetricFilters from './MetricFilters';+import MetricNameSearch from './MetricNameSearch';+import MetricSpaceAggregation from './MetricSpaceAggregation';+import MetricTimeAggregation from './MetricTimeAggregation';import { QueryBuilderProps } from './types';-import {- MetricFilters,- MetricNameSearch,- MetricSpaceAggregation,- MetricTimeAggregation,-} from './utils';function QueryBuilder({- metricName,- setMetricName,+ currentMetricName,+ setCurrentMetricName,+ setAppliedMetricName,spaceAggregationLabels,- metricInspectionOptions,+ currentMetricInspectionOptions,dispatchMetricInspectionOptions,inspectionStep,inspectMetricsTimeSeries,- searchQuery,- metricType,+ currentQuery,+ setCurrentQuery,}: QueryBuilderProps): JSX.Element {+ const applyInspectionOptions = useCallback(() => {+ setAppliedMetricName(currentMetricName ?? '');+ dispatchMetricInspectionOptions({+ type: 'APPLY_METRIC_INSPECTION_OPTIONS',+ });+ }, [currentMetricName, setAppliedMetricName, dispatchMetricInspectionOptions]);+return (<div className="inspect-metrics-query-builder"><div className="inspect-metrics-query-builder-header">@@ -31,25 +39,28 @@ function QueryBuilder({>Query Builder</Button>+ <RunQueryBtn onStageRunQuery={applyInspectionOptions} /></div><Card className="inspect-metrics-query-builder-content">- <MetricNameSearch metricName={metricName} setMetricName={setMetricName} />+ <MetricNameSearch+ currentMetricName={currentMetricName}+ setCurrentMetricName={setCurrentMetricName}+ /><MetricFiltersdispatchMetricInspectionOptions={dispatchMetricInspectionOptions}- searchQuery={searchQuery}- metricName={metricName}- metricType={metricType || null}+ currentQuery={currentQuery}+ setCurrentQuery={setCurrentQuery}/><MetricTimeAggregationinspectionStep={inspectionStep}- metricInspectionOptions={metricInspectionOptions}+ currentMetricInspectionOptions={currentMetricInspectionOptions}dispatchMetricInspectionOptions={dispatchMetricInspectionOptions}inspectMetricsTimeSeries={inspectMetricsTimeSeries}/><MetricSpaceAggregationinspectionStep={inspectionStep}spaceAggregationLabels={spaceAggregationLabels}- metricInspectionOptions={metricInspectionOptions}+ currentMetricInspectionOptions={currentMetricInspectionOptions}dispatchMetricInspectionOptions={dispatchMetricInspectionOptions}/></Card>diff --git a/frontend/src/container/MetricsExplorer/Inspect/TableView.tsx b/frontend/src/container/MetricsExplorer/Inspect/TableView.tsxindex 70fcbc2ed9..8c0bd6d3f1 100644--- a/frontend/src/container/MetricsExplorer/Inspect/TableView.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/TableView.tsx@@ -11,13 +11,13 @@ function TableView({setShowExpandedView,setExpandedViewOptions,isInspectMetricsRefetching,- metricInspectionOptions,+ metricInspectionAppliedOptions,}: TableViewProps): JSX.Element {const isSpaceAggregatedWithoutLabel = useMemo(() =>- !!metricInspectionOptions.spaceAggregationOption &&- metricInspectionOptions.spaceAggregationLabels.length === 0,- [metricInspectionOptions],+ !!metricInspectionAppliedOptions.spaceAggregationOption &&+ metricInspectionAppliedOptions.spaceAggregationLabels.length === 0,+ [metricInspectionAppliedOptions],);const labelKeys = useMemo(() => {if (isSpaceAggregatedWithoutLabel) {diff --git a/frontend/src/container/MetricsExplorer/Inspect/TimeSeriesLabel.tsx b/frontend/src/container/MetricsExplorer/Inspect/TimeSeriesLabel.tsxnew file mode 100644index 0000000000..33d68455fa--- /dev/null+++ b/frontend/src/container/MetricsExplorer/Inspect/TimeSeriesLabel.tsx@@ -0,0 +1,23 @@+import { Typography } from 'antd';++import { TimeSeriesLabelProps } from './types';++function TimeSeriesLabel({+ timeSeries,+ textColor,+}: TimeSeriesLabelProps): JSX.Element {+ return (+ <>+ {Object.entries(timeSeries?.labels ?? {}).map(([key, value]) => (+ <span key={key}>+ <Typography.Text style={{ color: textColor, fontWeight: 600 }}>+ {key}+ </Typography.Text>+ : {value}{' '}+ </span>+ ))}+ </>+ );+}++export default TimeSeriesLabel;diff --git a/frontend/src/container/MetricsExplorer/Inspect/__tests__/ExpandedView.test.tsx b/frontend/src/container/MetricsExplorer/Inspect/__tests__/ExpandedView.test.tsxindex 0831fba2a1..de4a5af8f3 100644--- a/frontend/src/container/MetricsExplorer/Inspect/__tests__/ExpandedView.test.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/__tests__/ExpandedView.test.tsx@@ -62,7 +62,7 @@ describe('ExpandedView', () => {],]);- const mockMetricInspectionOptions: MetricInspectionOptions = {+ const mockMetricInspectionAppliedOptions: MetricInspectionOptions = {timeAggregationOption: TimeAggregationOptions.MAX,timeAggregationInterval: 60,spaceAggregationOption: SpaceAggregationOptions.MAX_BY,@@ -79,7 +79,7 @@ describe('ExpandedView', () => {options={mockOptions}spaceAggregationSeriesMap={mockSpaceAggregationSeriesMap}step={InspectionStep.TIME_AGGREGATION}- metricInspectionOptions={mockMetricInspectionOptions}+ metricInspectionAppliedOptions={mockMetricInspectionAppliedOptions}timeAggregatedSeriesMap={mockTimeAggregatedSeriesMap}/>,);@@ -96,8 +96,8 @@ describe('ExpandedView', () => {options={mockOptions}spaceAggregationSeriesMap={mockSpaceAggregationSeriesMap}step={InspectionStep.SPACE_AGGREGATION}- metricInspectionOptions={{- ...mockMetricInspectionOptions,+ metricInspectionAppliedOptions={{+ ...mockMetricInspectionAppliedOptions,timeAggregationInterval: TIME_AGGREGATION_INTERVAL,}}timeAggregatedSeriesMap={mockTimeAggregatedSeriesMap}@@ -112,7 +112,7 @@ describe('ExpandedView', () => {screen.getByText(`42.123 is the ${TIME_AGGREGATION_OPTIONS[- mockMetricInspectionOptions.timeAggregationOption as TimeAggregationOptions+ mockMetricInspectionAppliedOptions.timeAggregationOption as TimeAggregationOptions]} of`,),@@ -127,7 +127,7 @@ describe('ExpandedView', () => {options={mockOptions}spaceAggregationSeriesMap={mockSpaceAggregationSeriesMap}step={InspectionStep.COMPLETED}- metricInspectionOptions={mockMetricInspectionOptions}+ metricInspectionAppliedOptions={mockMetricInspectionAppliedOptions}timeAggregatedSeriesMap={mockTimeAggregatedSeriesMap}/>,);@@ -139,7 +139,7 @@ describe('ExpandedView', () => {screen.getByText(`42.123 is the ${SPACE_AGGREGATION_OPTIONS_FOR_EXPANDED_VIEW[- mockMetricInspectionOptions.spaceAggregationOption as SpaceAggregationOptions+ mockMetricInspectionAppliedOptions.spaceAggregationOption as SpaceAggregationOptions]} of`,),@@ -153,7 +153,7 @@ describe('ExpandedView', () => {options={mockOptions}spaceAggregationSeriesMap={mockSpaceAggregationSeriesMap}step={InspectionStep.TIME_AGGREGATION}- metricInspectionOptions={mockMetricInspectionOptions}+ metricInspectionAppliedOptions={mockMetricInspectionAppliedOptions}timeAggregatedSeriesMap={mockTimeAggregatedSeriesMap}/>,);diff --git a/frontend/src/container/MetricsExplorer/Inspect/__tests__/GraphView.test.tsx b/frontend/src/container/MetricsExplorer/Inspect/__tests__/GraphView.test.tsxindex f807d8bbc3..4a24267045 100644--- a/frontend/src/container/MetricsExplorer/Inspect/__tests__/GraphView.test.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/__tests__/GraphView.test.tsx@@ -54,7 +54,7 @@ describe('GraphView', () => {setExpandedViewOptions: jest.fn(),resetInspection: jest.fn(),showExpandedView: false,- metricInspectionOptions: {+ metricInspectionAppliedOptions: {timeAggregationInterval: 60,spaceAggregationOption: SpaceAggregationOptions.MAX_BY,spaceAggregationLabels: ['host_name'],diff --git a/frontend/src/container/MetricsExplorer/Inspect/__tests__/QueryBuilder.test.tsx b/frontend/src/container/MetricsExplorer/Inspect/__tests__/QueryBuilder.test.tsxindex d667989c0c..c489315370 100644--- a/frontend/src/container/MetricsExplorer/Inspect/__tests__/QueryBuilder.test.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/__tests__/QueryBuilder.test.tsx@@ -2,6 +2,7 @@import { QueryClient, QueryClientProvider } from 'react-query';import { Provider } from 'react-redux';import { render, screen } from '@testing-library/react';+import userEvent from '@testing-library/user-event';import { MetricType } from 'api/metricsExplorer/getMetricsList';import * as appContextHooks from 'providers/App/App';import store from 'store';@@ -22,6 +23,27 @@ jest.mock('react-router-dom', () => ({}),}));+jest.mock('container/QueryBuilder/filters', () => ({+ AggregatorFilter: ({ onSelect, onChange, defaultValue }: any): JSX.Element => (+ <div data-testid="mock-aggregator-filter">+ <input+ data-testid="metric-name-input"+ defaultValue={defaultValue}+ onChange={(e: React.ChangeEvent<HTMLInputElement>): void =>+ onChange({ key: e.target.value })+ }+ />+ <button+ type="button"+ data-testid="select-metric-button"+ onClick={(): void => onSelect({ key: 'test_metric_2' })}+ >+ Select Metric+ </button>+ </div>+ ),+}));+jest.spyOn(appContextHooks, 'useAppContext').mockReturnValue({user: {role: 'admin',@@ -48,12 +70,16 @@ jest.spyOn(appContextHooks, 'useAppContext').mockReturnValue({const queryClient = new QueryClient();+const mockSetCurrentMetricName = jest.fn();+const mockSetAppliedMetricName = jest.fn();+describe('QueryBuilder', () => {const defaultProps = {- metricName: 'test_metric',- setMetricName: jest.fn(),+ currentMetricName: 'test_metric',+ setCurrentMetricName: mockSetCurrentMetricName,+ setAppliedMetricName: mockSetAppliedMetricName,spaceAggregationLabels: ['label1', 'label2'],- metricInspectionOptions: {+ currentMetricInspectionOptions: {timeAggregationInterval: 60,timeAggregationOption: TimeAggregationOptions.AVG,spaceAggregationLabels: [],@@ -67,19 +93,20 @@ describe('QueryBuilder', () => {metricType: MetricType.SUM,inspectionStep: InspectionStep.TIME_AGGREGATION,inspectMetricsTimeSeries: [],- searchQuery: {+ currentQuery: {filters: {items: [],op: 'and',},} as any,+ setCurrentQuery: jest.fn(),};beforeEach(() => {jest.clearAllMocks();});- it('renders query builder header', () => {+ it('renders query builder with all components', () => {render(<QueryClientProvider client={queryClient}><Provider store={store}>@@ -88,31 +115,15 @@ describe('QueryBuilder', () => {</QueryClientProvider>,);expect(screen.getByText('Query Builder')).toBeInTheDocument();- });-- it('renders metric name search component', () => {- render(- <QueryClientProvider client={queryClient}>- <Provider store={store}>- <QueryBuilder {...defaultProps} />- </Provider>- </QueryClientProvider>,- );expect(screen.getByTestId('metric-name-search')).toBeInTheDocument();- });-- it('renders metric filters component', () => {- render(- <QueryClientProvider client={queryClient}>- <Provider store={store}>- <QueryBuilder {...defaultProps} />- </Provider>- </QueryClientProvider>,- );expect(screen.getByTestId('metric-filters')).toBeInTheDocument();+ expect(screen.getByTestId('metric-time-aggregation')).toBeInTheDocument();+ expect(screen.getByTestId('metric-space-aggregation')).toBeInTheDocument();});- it('renders time aggregation component', () => {+ it('should call setCurrentMetricName when metric name is selected', async () => {+ const user = userEvent.setup();+render(<QueryClientProvider client={queryClient}><Provider store={store}>@@ -120,10 +131,21 @@ describe('QueryBuilder', () => {</Provider></QueryClientProvider>,);- expect(screen.getByTestId('metric-time-aggregation')).toBeInTheDocument();++ const metricNameSearch = screen.getByTestId('metric-name-search');+ expect(metricNameSearch).toBeInTheDocument();++ expect(screen.getByText('From')).toBeInTheDocument();++ const selectButton = screen.getByTestId('select-metric-button');+ await user.click(selectButton);++ expect(mockSetCurrentMetricName).toHaveBeenCalledWith('test_metric_2');});- it('renders space aggregation component', () => {+ it('should call setAppliedMetricName and apply inspection options when query is applied', async () => {+ const user = userEvent.setup();+render(<QueryClientProvider client={queryClient}><Provider store={store}>@@ -131,6 +153,15 @@ describe('QueryBuilder', () => {</Provider></QueryClientProvider>,);- expect(screen.getByTestId('metric-space-aggregation')).toBeInTheDocument();++ const applyQueryButton = screen.getByText('Run Query');+ await user.click(applyQueryButton);++ expect(mockSetCurrentMetricName).toHaveBeenCalledTimes(0);+ expect(mockSetAppliedMetricName).toHaveBeenCalledWith('test_metric');++ expect(defaultProps.dispatchMetricInspectionOptions).toHaveBeenCalledWith({+ type: 'APPLY_METRIC_INSPECTION_OPTIONS',+ });});});diff --git a/frontend/src/container/MetricsExplorer/Inspect/__tests__/TableView.test.tsx b/frontend/src/container/MetricsExplorer/Inspect/__tests__/TableView.test.tsxindex cc1e2fb5e0..6913f95f55 100644--- a/frontend/src/container/MetricsExplorer/Inspect/__tests__/TableView.test.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/__tests__/TableView.test.tsx@@ -49,7 +49,7 @@ describe('TableView', () => {inspectMetricsTimeSeries: mockTimeSeries,setShowExpandedView: jest.fn(),setExpandedViewOptions: jest.fn(),- metricInspectionOptions: {+ metricInspectionAppliedOptions: {timeAggregationInterval: 60,timeAggregationOption: TimeAggregationOptions.MAX,spaceAggregationOption: SpaceAggregationOptions.MAX_BY,diff --git a/frontend/src/container/MetricsExplorer/Inspect/constants.ts b/frontend/src/container/MetricsExplorer/Inspect/constants.tsindex f2cfcfba4d..6279acd276 100644--- a/frontend/src/container/MetricsExplorer/Inspect/constants.ts+++ b/frontend/src/container/MetricsExplorer/Inspect/constants.ts@@ -11,7 +11,7 @@ import {} from 'lucide-react';import {- MetricInspectionOptions,+ MetricInspectionState,SpaceAggregationOptions,TimeAggregationOptions,} from './types';@@ -71,14 +71,26 @@ export const SPACE_AGGREGATION_OPTIONS_FOR_EXPANDED_VIEW: Record<[SpaceAggregationOptions.AVG_BY]: 'Avg',};-export const INITIAL_INSPECT_METRICS_OPTIONS: MetricInspectionOptions = {- timeAggregationOption: undefined,- timeAggregationInterval: undefined,- spaceAggregationOption: undefined,- spaceAggregationLabels: [],- filters: {- items: [],- op: 'AND',+export const INITIAL_INSPECT_METRICS_OPTIONS: MetricInspectionState = {+ currentOptions: {+ timeAggregationOption: undefined,+ timeAggregationInterval: undefined,+ spaceAggregationOption: undefined,+ spaceAggregationLabels: [],+ filters: {+ items: [],+ op: 'AND',+ },+ },+ appliedOptions: {+ timeAggregationOption: undefined,+ timeAggregationInterval: undefined,+ spaceAggregationOption: undefined,+ spaceAggregationLabels: [],+ filters: {+ items: [],+ op: 'AND',+ },},};diff --git a/frontend/src/container/MetricsExplorer/Inspect/types.ts b/frontend/src/container/MetricsExplorer/Inspect/types.tsindex eda878574d..5f147e00ce 100644--- a/frontend/src/container/MetricsExplorer/Inspect/types.ts+++ b/frontend/src/container/MetricsExplorer/Inspect/types.ts@@ -7,7 +7,7 @@ import {import { AlignedData } from 'uplot';export type InspectProps = {- metricName: string | null;+ metricName: string;isOpen: boolean;onClose: () => void;};@@ -19,7 +19,7 @@ export interface UseInspectMetricsReturnData {isInspectMetricsError: boolean;formattedInspectMetricsTimeSeries: AlignedData;spaceAggregationLabels: string[];- metricInspectionOptions: MetricInspectionOptions;+ metricInspectionOptions: MetricInspectionState;dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;inspectionStep: InspectionStep;isInspectMetricsRefetching: boolean;@@ -43,36 +43,36 @@ export interface GraphViewProps {showExpandedView: boolean;setShowExpandedView: (showExpandedView: boolean) => void;setExpandedViewOptions: (options: GraphPopoverOptions | null) => void;- metricInspectionOptions: MetricInspectionOptions;+ metricInspectionAppliedOptions: MetricInspectionOptions;isInspectMetricsRefetching: boolean;}export interface QueryBuilderProps {- metricName: string | null;- setMetricName: (metricName: string) => void;- metricType: MetricType | undefined;+ currentMetricName: string | null;+ setCurrentMetricName: (metricName: string) => void;+ setAppliedMetricName: (metricName: string) => void;spaceAggregationLabels: string[];- metricInspectionOptions: MetricInspectionOptions;+ currentMetricInspectionOptions: MetricInspectionOptions;dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;inspectionStep: InspectionStep;inspectMetricsTimeSeries: InspectMetricsSeries[];- searchQuery: IBuilderQuery;+ currentQuery: IBuilderQuery;+ setCurrentQuery: (query: IBuilderQuery) => void;}export interface MetricNameSearchProps {- metricName: string | null;- setMetricName: (metricName: string) => void;+ currentMetricName: string | null;+ setCurrentMetricName: (metricName: string) => void;}export interface MetricFiltersProps {- searchQuery: IBuilderQuery;dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;- metricName: string | null;- metricType: MetricType | null;+ currentQuery: IBuilderQuery;+ setCurrentQuery: (query: IBuilderQuery) => void;}export interface MetricTimeAggregationProps {- metricInspectionOptions: MetricInspectionOptions;+ currentMetricInspectionOptions: MetricInspectionOptions;dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;inspectionStep: InspectionStep;inspectMetricsTimeSeries: InspectMetricsSeries[];@@ -80,7 +80,7 @@ export interface MetricTimeAggregationProps {export interface MetricSpaceAggregationProps {spaceAggregationLabels: string[];- metricInspectionOptions: MetricInspectionOptions;+ currentMetricInspectionOptions: MetricInspectionOptions;dispatchMetricInspectionOptions: (action: MetricInspectionAction) => void;inspectionStep: InspectionStep;}@@ -109,13 +109,19 @@ export interface MetricInspectionOptions {filters: TagFilter;}+export interface MetricInspectionState {+ currentOptions: MetricInspectionOptions;+ appliedOptions: MetricInspectionOptions;+}+export type MetricInspectionAction =| { type: 'SET_TIME_AGGREGATION_OPTION'; payload: TimeAggregationOptions }| { type: 'SET_TIME_AGGREGATION_INTERVAL'; payload: number }| { type: 'SET_SPACE_AGGREGATION_OPTION'; payload: SpaceAggregationOptions }| { type: 'SET_SPACE_AGGREGATION_LABELS'; payload: string[] }| { type: 'SET_FILTERS'; payload: TagFilter }- | { type: 'RESET_INSPECTION' };+ | { type: 'RESET_INSPECTION' }+ | { type: 'APPLY_METRIC_INSPECTION_OPTIONS' };export enum InspectionStep {TIME_AGGREGATION = 1,@@ -156,7 +162,7 @@ export interface ExpandedViewProps {options: GraphPopoverOptions | null;spaceAggregationSeriesMap: Map<string, InspectMetricsSeries[]>;step: InspectionStep;- metricInspectionOptions: MetricInspectionOptions;+ metricInspectionAppliedOptions: MetricInspectionOptions;timeAggregatedSeriesMap: Map<number, GraphPopoverData[]>;}@@ -165,7 +171,7 @@ export interface TableViewProps {inspectMetricsTimeSeries: InspectMetricsSeries[];setShowExpandedView: (showExpandedView: boolean) => void;setExpandedViewOptions: (options: GraphPopoverOptions | null) => void;- metricInspectionOptions: MetricInspectionOptions;+ metricInspectionAppliedOptions: MetricInspectionOptions;isInspectMetricsRefetching: boolean;}@@ -174,3 +180,8 @@ export interface TableViewDataItem {values: JSX.Element;key: number;}++export interface TimeSeriesLabelProps {+ timeSeries: InspectMetricsSeries | undefined;+ textColor: string | undefined;+}diff --git a/frontend/src/container/MetricsExplorer/Inspect/useInspectMetrics.ts b/frontend/src/container/MetricsExplorer/Inspect/useInspectMetrics.tsindex ccdeecc88a..b3bcbe36ca 100644--- a/frontend/src/container/MetricsExplorer/Inspect/useInspectMetrics.ts+++ b/frontend/src/container/MetricsExplorer/Inspect/useInspectMetrics.ts@@ -10,7 +10,7 @@ import {GraphPopoverData,InspectionStep,MetricInspectionAction,- MetricInspectionOptions,+ MetricInspectionState,UseInspectMetricsReturnData,} from './types';import {@@ -20,37 +20,62 @@ import {} from './utils';const metricInspectionReducer = (- state: MetricInspectionOptions,+ state: MetricInspectionState,action: MetricInspectionAction,-): MetricInspectionOptions => {+): MetricInspectionState => {switch (action.type) {case 'SET_TIME_AGGREGATION_OPTION':return {...state,- timeAggregationOption: action.payload,+ currentOptions: {+ ...state.currentOptions,+ timeAggregationOption: action.payload,+ },};case 'SET_TIME_AGGREGATION_INTERVAL':return {...state,- timeAggregationInterval: action.payload,+ currentOptions: {+ ...state.currentOptions,+ timeAggregationInterval: action.payload,+ },};case 'SET_SPACE_AGGREGATION_OPTION':return {...state,- spaceAggregationOption: action.payload,+ currentOptions: {+ ...state.currentOptions,+ spaceAggregationOption: action.payload,+ },};case 'SET_SPACE_AGGREGATION_LABELS':return {...state,- spaceAggregationLabels: action.payload,+ currentOptions: {+ ...state.currentOptions,+ spaceAggregationLabels: action.payload,+ },};case 'SET_FILTERS':return {...state,- filters: action.payload,+ currentOptions: {+ ...state.currentOptions,+ filters: action.payload,+ },+ };+ case 'APPLY_METRIC_INSPECTION_OPTIONS':+ return {+ ...state,+ appliedOptions: {+ ...state.appliedOptions,+ ...state.currentOptions,+ },};case 'RESET_INSPECTION':- return { ...INITIAL_INSPECT_METRICS_OPTIONS };+ return {+ ...INITIAL_INSPECT_METRICS_OPTIONS,+ };default:return state;}@@ -84,7 +109,7 @@ export function useInspectMetrics(metricName: metricName ?? '',start,end,- filters: metricInspectionOptions.filters,+ filters: metricInspectionOptions.appliedOptions.filters,},{enabled: !!metricName,@@ -117,13 +142,26 @@ export function useInspectMetrics();// Evaluate inspection step- const inspectionStep = useMemo(() => {- if (metricInspectionOptions.spaceAggregationOption) {+ const currentInspectionStep = useMemo(() => {+ if (metricInspectionOptions.currentOptions.spaceAggregationOption) {return InspectionStep.COMPLETED;}if (- metricInspectionOptions.timeAggregationOption &&- metricInspectionOptions.timeAggregationInterval+ metricInspectionOptions.currentOptions.timeAggregationOption &&+ metricInspectionOptions.currentOptions.timeAggregationInterval+ ) {+ return InspectionStep.SPACE_AGGREGATION;+ }+ return InspectionStep.TIME_AGGREGATION;+ }, [metricInspectionOptions]);++ const appliedInspectionStep = useMemo(() => {+ if (metricInspectionOptions.appliedOptions.spaceAggregationOption) {+ return InspectionStep.COMPLETED;+ }+ if (+ metricInspectionOptions.appliedOptions.timeAggregationOption &&+ metricInspectionOptions.appliedOptions.timeAggregationInterval) {return InspectionStep.SPACE_AGGREGATION;}@@ -149,23 +187,26 @@ export function useInspectMetrics(// Apply time aggregation once required options are setif (- inspectionStep >= InspectionStep.SPACE_AGGREGATION &&- metricInspectionOptions.timeAggregationOption &&- metricInspectionOptions.timeAggregationInterval+ appliedInspectionStep >= InspectionStep.SPACE_AGGREGATION &&+ metricInspectionOptions.appliedOptions.timeAggregationOption &&+ metricInspectionOptions.appliedOptions.timeAggregationInterval) {const {timeAggregatedSeries,timeAggregatedSeriesMap,- } = applyTimeAggregation(inspectMetricsTimeSeries, metricInspectionOptions);+ } = applyTimeAggregation(+ inspectMetricsTimeSeries,+ metricInspectionOptions.appliedOptions,+ );timeSeries = timeAggregatedSeries;setTimeAggregatedSeriesMap(timeAggregatedSeriesMap);setAggregatedTimeSeries(timeSeries);}// Apply space aggregation- if (inspectionStep === InspectionStep.COMPLETED) {+ if (appliedInspectionStep === InspectionStep.COMPLETED) {const { aggregatedSeries, spaceAggregatedSeriesMap } = applySpaceAggregation(timeSeries,- metricInspectionOptions,+ metricInspectionOptions.appliedOptions,);timeSeries = aggregatedSeries;setSpaceAggregatedSeriesMap(spaceAggregatedSeriesMap);@@ -186,7 +227,7 @@ export function useInspectMetrics(const rawData = [timestamps, ...timeseriesArray];return rawData.map((series) => new Float64Array(series));- }, [inspectMetricsTimeSeries, inspectionStep, metricInspectionOptions]);+ }, [inspectMetricsTimeSeries, appliedInspectionStep, metricInspectionOptions]);const spaceAggregationLabels = useMemo(() => {const labels = new Set<string>();@@ -216,7 +257,7 @@ export function useInspectMetrics(spaceAggregationLabels,metricInspectionOptions,dispatchMetricInspectionOptions,- inspectionStep,+ inspectionStep: currentInspectionStep,isInspectMetricsRefetching,spaceAggregatedSeriesMap,aggregatedTimeSeries,diff --git a/frontend/src/container/MetricsExplorer/Inspect/utils.tsx b/frontend/src/container/MetricsExplorer/Inspect/utils.tssimilarity index 58%rename from frontend/src/container/MetricsExplorer/Inspect/utils.tsxrename to frontend/src/container/MetricsExplorer/Inspect/utils.tsindex 6275b8e227..85b45c54e1 100644--- a/frontend/src/container/MetricsExplorer/Inspect/utils.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/utils.ts@@ -1,36 +1,12 @@/* eslint-disable no-nested-ternary */-import { useMemo, useState } from 'react';-import { Card, Input, Select, Typography } from 'antd';-import logEvent from 'api/common/logEvent';import { MetrictypesTypeDTO } from 'api/generated/services/sigNoz.schemas';import { InspectMetricsSeries } from 'api/metricsExplorer/getInspectMetricsDetails';-import classNames from 'classnames';-import { initialQueriesMap } from 'constants/queryBuilder';-import { AggregatorFilter } from 'container/QueryBuilder/filters';-import QueryBuilderSearch from 'container/QueryBuilder/filters/QueryBuilderSearch';-import { useQueryOperations } from 'hooks/queryBuilder/useQueryBuilderOperations';-import { HardHat } from 'lucide-react';-import {- BaseAutocompleteData,- DataTypes,-} from 'types/api/queryBuilder/queryAutocompleteResponse';import { TagFilter } from 'types/api/queryBuilder/queryBuilderData';-import { DataSource } from 'types/common/queryBuilder';-import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';-import {- SPACE_AGGREGATION_OPTIONS,- TIME_AGGREGATION_OPTIONS,-} from './constants';import {GraphPopoverData,GraphPopoverOptions,- InspectionStep,- MetricFiltersProps,MetricInspectionOptions,- MetricNameSearchProps,- MetricSpaceAggregationProps,- MetricTimeAggregationProps,SpaceAggregationOptions,TimeAggregationOptions,} from './types';@@ -72,220 +48,6 @@ export function getDefaultTimeAggregationInterval(return Math.max(60, reportingInterval);}-export function MetricNameSearch({- metricName,- setMetricName,-}: MetricNameSearchProps): JSX.Element {- const [searchText, setSearchText] = useState(metricName);-- const handleSetMetricName = (value: BaseAutocompleteData): void => {- setMetricName(value.key);- };-- const handleChange = (value: BaseAutocompleteData): void => {- setSearchText(value.key);- };-- return (- <div- data-testid="metric-name-search"- className="inspect-metrics-input-group metric-name-search"- >- <Typography.Text>From</Typography.Text>- <AggregatorFilter- defaultValue={searchText ?? ''}- query={initialQueriesMap[DataSource.METRICS].builder.queryData[0]}- onSelect={handleSetMetricName}- onChange={handleChange}- />- </div>- );-}--export function MetricFilters({- dispatchMetricInspectionOptions,- searchQuery,- metricName,- metricType,-}: MetricFiltersProps): JSX.Element {- const { handleChangeQueryData } = useQueryOperations({- index: 0,- query: searchQuery,- entityVersion: '',- });-- const aggregateAttribute = useMemo(- () => ({- key: metricName ?? '',- dataType: DataTypes.String,- type: metricType,- id: `${metricName}--${DataTypes.String}--${metricType}--true`,- }),- [metricName, metricType],- );-- return (- <div- data-testid="metric-filters"- className="inspect-metrics-input-group metric-filters"- >- <Typography.Text>Where</Typography.Text>- <QueryBuilderSearch- query={{- ...searchQuery,- aggregateAttribute,- }}- onChange={(value): void => {- handleChangeQueryData('filters', value);- logEvent(MetricsExplorerEvents.FilterApplied, {- [MetricsExplorerEventKeys.Modal]: 'inspect',- });- dispatchMetricInspectionOptions({- type: 'SET_FILTERS',- payload: value,- });- }}- suffixIcon={<HardHat size={16} />}- disableNavigationShortcuts- />- </div>- );-}--export function MetricTimeAggregation({- metricInspectionOptions,- dispatchMetricInspectionOptions,- inspectionStep,- inspectMetricsTimeSeries,-}: MetricTimeAggregationProps): JSX.Element {- return (- <div- data-testid="metric-time-aggregation"- className="metric-time-aggregation"- >- <div- className={classNames('metric-time-aggregation-header', {- 'selected-step': inspectionStep === InspectionStep.TIME_AGGREGATION,- })}- >- <Typography.Text>AGGREGATE BY TIME</Typography.Text>- </div>- <div className="metric-time-aggregation-content">- <div className="inspect-metrics-input-group">- <Typography.Text>Align with</Typography.Text>- <Select- value={metricInspectionOptions.timeAggregationOption}- onChange={(value): void => {- dispatchMetricInspectionOptions({- type: 'SET_TIME_AGGREGATION_OPTION',- payload: value,- });- // set the time aggregation interval to the default value if it is not set- if (!metricInspectionOptions.timeAggregationInterval) {- dispatchMetricInspectionOptions({- type: 'SET_TIME_AGGREGATION_INTERVAL',- payload: getDefaultTimeAggregationInterval(- inspectMetricsTimeSeries[0],- ),- });- }- }}- style={{ width: 130 }}- placeholder="Select option"- >- {Object.entries(TIME_AGGREGATION_OPTIONS).map(([key, value]) => (- <Select.Option key={key} value={key}>- {value}- </Select.Option>- ))}- </Select>- </div>- <div className="inspect-metrics-input-group">- <Typography.Text>aggregated every</Typography.Text>- <Input- type="number"- className="no-arrows-input"- value={metricInspectionOptions.timeAggregationInterval}- placeholder="Select interval..."- suffix="seconds"- onChange={(e): void => {- dispatchMetricInspectionOptions({- type: 'SET_TIME_AGGREGATION_INTERVAL',- payload: parseInt(e.target.value, 10),- });- }}- onWheel={(e): void => (e.target as HTMLInputElement).blur()}- />- </div>- </div>- </div>- );-}--export function MetricSpaceAggregation({- spaceAggregationLabels,- metricInspectionOptions,- dispatchMetricInspectionOptions,- inspectionStep,-}: MetricSpaceAggregationProps): JSX.Element {- return (- <div- data-testid="metric-space-aggregation"- className="metric-space-aggregation"- >- <div- className={classNames('metric-space-aggregation-header', {- 'selected-step': inspectionStep === InspectionStep.SPACE_AGGREGATION,- })}- >- <Typography.Text>AGGREGATE BY LABELS</Typography.Text>- </div>- <div className="metric-space-aggregation-content">- <div className="metric-space-aggregation-content-left">- <Select- value={metricInspectionOptions.spaceAggregationOption}- placeholder="Select option"- onChange={(value): void => {- dispatchMetricInspectionOptions({- type: 'SET_SPACE_AGGREGATION_OPTION',- payload: value,- });- }}- style={{ width: 130 }}- disabled={inspectionStep === InspectionStep.TIME_AGGREGATION}- >- {/* eslint-disable-next-line sonarjs/no-identical-functions */}- {Object.entries(SPACE_AGGREGATION_OPTIONS).map(([key, value]) => (- <Select.Option key={key} value={key}>- {value}- </Select.Option>- ))}- </Select>- </div>- <Select- mode="multiple"- style={{ width: '100%' }}- placeholder="Search for attributes..."- value={metricInspectionOptions.spaceAggregationLabels}- onChange={(value): void => {- dispatchMetricInspectionOptions({- type: 'SET_SPACE_AGGREGATION_LABELS',- payload: value,- });- }}- disabled={inspectionStep === InspectionStep.TIME_AGGREGATION}- >- {spaceAggregationLabels.map((label) => (- <Select.Option key={label} value={label}>- {label}- </Select.Option>- ))}- </Select>- </div>- </div>- );-}-export function applyFilters(inspectMetricsTimeSeries: InspectMetricsSeries[],filters: TagFilter,@@ -322,7 +84,7 @@ export function applyFilters(export function applyTimeAggregation(inspectMetricsTimeSeries: InspectMetricsSeries[],- metricInspectionOptions: MetricInspectionOptions,+ metricInspectionAppliedOptions: MetricInspectionOptions,): {timeAggregatedSeries: InspectMetricsSeries[];timeAggregatedSeriesMap: Map<number, GraphPopoverData[]>;@@ -330,7 +92,7 @@ export function applyTimeAggregation(const {timeAggregationOption,timeAggregationInterval,- } = metricInspectionOptions;+ } = metricInspectionAppliedOptions;if (!timeAggregationInterval) {return {@@ -415,7 +177,7 @@ export function applyTimeAggregation(export function applySpaceAggregation(inspectMetricsTimeSeries: InspectMetricsSeries[],- metricInspectionOptions: MetricInspectionOptions,+ metricInspectionAppliedOptions: MetricInspectionOptions,): {aggregatedSeries: InspectMetricsSeries[];spaceAggregatedSeriesMap: Map<string, InspectMetricsSeries[]>;@@ -425,7 +187,7 @@ export function applySpaceAggregation(inspectMetricsTimeSeries.forEach((series) => {// Create composite key from selected labels- const key = metricInspectionOptions.spaceAggregationLabels+ const key = metricInspectionAppliedOptions.spaceAggregationLabels.map((label) => `${label}:${series.labels[label]}`).join(',');@@ -460,7 +222,7 @@ export function applySpaceAggregation(([timestamp, values]) => {let aggregatedValue: number;- switch (metricInspectionOptions.spaceAggregationOption) {+ switch (metricInspectionAppliedOptions.spaceAggregationOption) {case SpaceAggregationOptions.SUM_BY:aggregatedValue = values.reduce((sum, val) => sum + val, 0);break;@@ -695,103 +457,6 @@ export const formatTimestampToFullDateTime = (return `${datePart} ⎯ ${timePart}`;};-export function getTimeSeriesLabel(- timeSeries: InspectMetricsSeries | null,- textColor: string | undefined,-): JSX.Element {- return (- <>- {Object.entries(timeSeries?.labels ?? {}).map(([key, value]) => (- <span key={key}>- <Typography.Text style={{ color: textColor, fontWeight: 600 }}>- {key}- </Typography.Text>- : {value}{' '}- </span>- ))}- </>- );-}--export function HoverPopover({- options,- step,- metricInspectionOptions,-}: {- options: GraphPopoverOptions;- step: InspectionStep;- metricInspectionOptions: MetricInspectionOptions;-}): JSX.Element {- const closestTimestamp = useMemo(() => {- if (!options.timeSeries) {- return options.timestamp;- }- return options.timeSeries?.values.reduce((prev, curr) => {- const prevDiff = Math.abs(prev.timestamp - options.timestamp);- const currDiff = Math.abs(curr.timestamp - options.timestamp);- return prevDiff < currDiff ? prev : curr;- }).timestamp;- }, [options.timeSeries, options.timestamp]);-- const closestValue = useMemo(() => {- if (!options.timeSeries) {- return options.value;- }- const index = options.timeSeries.values.findIndex(- (value) => value.timestamp === closestTimestamp,- );- return index !== undefined && index >= 0- ? options.timeSeries?.values[index].value- : null;- }, [options.timeSeries, closestTimestamp, options.value]);-- const title = useMemo(() => {- if (- step === InspectionStep.COMPLETED &&- metricInspectionOptions.spaceAggregationLabels.length === 0- ) {- return undefined;- }- if (step === InspectionStep.COMPLETED && options.timeSeries?.title) {- return options.timeSeries.title;- }- if (!options.timeSeries) {- return undefined;- }- return getTimeSeriesLabel(- options.timeSeries,- options.timeSeries?.strokeColor,- );- }, [step, options.timeSeries, metricInspectionOptions]);-- return (- <Card- className="hover-popover-card"- style={{- top: options.y + 10,- left: options.x + 10,- }}- >- <div className="hover-popover-row">- <Typography.Text>- {formatTimestampToFullDateTime(closestTimestamp ?? 0)}- </Typography.Text>- <Typography.Text>{Number(closestValue).toFixed(2)}</Typography.Text>- </div>- {options.timeSeries && (- <Typography.Text- style={{- color: options.timeSeries?.strokeColor,- fontWeight: 200,- }}- >- {title}- </Typography.Text>- )}- </Card>- );-}-export function onGraphHover(e: MouseEvent,u: uPlot,diff --git a/frontend/src/container/MetricsExplorer/Summary/Summary.tsx b/frontend/src/container/MetricsExplorer/Summary/Summary.tsxindex 37aaba7331..7f6e65d456 100644--- a/frontend/src/container/MetricsExplorer/Summary/Summary.tsx+++ b/frontend/src/container/MetricsExplorer/Summary/Summary.tsx@@ -342,7 +342,7 @@ function Summary(): JSX.Element {openInspectModal={openInspectModal}/>)}- {isInspectModalOpen && (+ {isInspectModalOpen && selectedMetricName && (<InspectModalisOpen={isInspectModalOpen}onClose={closeInspectModal}