Skip to content

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.

feat(query-builder): field placeholders, default row limit and synced fields (#13113)

Abhi kumar9ec39f249462
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/MerticsAggregateSection/MetricsAggregateSection.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/MerticsAggregateSection/MetricsAggregateSection.tsx
index fe1b21e397..a1b11e6fb1 100644
--- a/frontend/src/components/QueryBuilderV2/QueryV2/MerticsAggregateSection/MetricsAggregateSection.tsx
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/MerticsAggregateSection/MetricsAggregateSection.tsx
@@ -10,6 +10,13 @@ import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
import { MetricAggregation } from 'types/api/v5/queryRange';
import { useQueryBuilderV2Context } from '../../QueryBuilderV2Context';
+import {
+ QueryBuilderField,
+ type QueryBuilderFieldsConfig,
+} from '../../queryBuilderFields.types';
+import { resolveQueryBuilderField } from '../../queryBuilderFields.utils';
+
+import { BUILT_IN_PLACEHOLDERS } from './constants';
import './MetricsAggregateSection.styles.scss';
@@ -18,13 +25,18 @@ const MetricsAggregateSection = memo(function MetricsAggregateSection({
index,
version,
panelType,
+ fieldsConfig,
}: {
query: IBuilderQuery;
index: number;
version: string;
panelType: PANEL_TYPES | null;
+ fieldsConfig?: QueryBuilderFieldsConfig;
}): JSX.Element {
const { setAggregationOptions } = useQueryBuilderV2Context();
+ const placeholderOf = (key: keyof typeof BUILT_IN_PLACEHOLDERS): string =>
+ resolveQueryBuilderField(key, fieldsConfig).placeholder ??
+ BUILT_IN_PLACEHOLDERS[key];
const {
operators,
spaceAggregationOptions,
@@ -152,7 +164,7 @@ const MetricsAggregateSection = memo(function MetricsAggregateSection({
<InputWithLabel
onChange={handleChangeAggregateEvery}
label="Seconds"
- placeholder="Auto"
+ placeholder={placeholderOf(QueryBuilderField.StepInterval)}
labelAfter
initialValue={query?.stepInterval ?? null}
/>
@@ -204,6 +216,7 @@ const MetricsAggregateSection = memo(function MetricsAggregateSection({
disabled={!queryAggregation.metricName}
query={query}
onChange={handleChangeGroupByKeys}
+ placeholder={placeholderOf(QueryBuilderField.GroupBy)}
/>
</div>
</div>
@@ -240,6 +253,7 @@ const MetricsAggregateSection = memo(function MetricsAggregateSection({
disabled={!queryAggregation.metricName}
query={query}
onChange={handleChangeGroupByKeys}
+ placeholder={placeholderOf(QueryBuilderField.GroupBy)}
/>
</div>
</div>
@@ -273,7 +287,7 @@ const MetricsAggregateSection = memo(function MetricsAggregateSection({
<InputWithLabel
onChange={handleChangeAggregateEvery}
label="Seconds"
- placeholder="Auto"
+ placeholder={placeholderOf(QueryBuilderField.StepInterval)}
labelAfter
initialValue={query?.stepInterval ?? null}
className="histogram-every-input"
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/MerticsAggregateSection/constants.ts b/frontend/src/components/QueryBuilderV2/QueryV2/MerticsAggregateSection/constants.ts
new file mode 100644
index 0000000000..c26a224305
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/MerticsAggregateSection/constants.ts
@@ -0,0 +1,9 @@
+import { QueryBuilderField } from '../../queryBuilderFields.types';
+import { STEP_INTERVAL_PLACEHOLDER } from '../../queryBuilderFields.utils';
+import { ADD_ON_DEFINITIONS } from '../QueryAddOns/constants';
+
+export const BUILT_IN_PLACEHOLDERS = {
+ [QueryBuilderField.StepInterval]: STEP_INTERVAL_PLACEHOLDER,
+ [QueryBuilderField.GroupBy]:
+ ADD_ON_DEFINITIONS[QueryBuilderField.GroupBy].placeholder,
+} as const;
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/HavingFilter/HavingFilter.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/HavingFilter/HavingFilter.tsx
index fd1dda9153..210c83f0dc 100644
--- a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/HavingFilter/HavingFilter.tsx
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/HavingFilter/HavingFilter.tsx
@@ -88,10 +88,12 @@ function HavingFilter({
onClose,
onChange,
queryData,
+ placeholder = 'Type Having query like count() > 10 ...',
}: {
onClose: () => void;
onChange: (value: string) => void;
queryData: IBuilderQuery;
+ placeholder?: string;
}): JSX.Element {
const isDarkMode = useIsDarkMode();
const { getAggregationOptions } = useQueryBuilderV2Context();
@@ -345,7 +347,7 @@ function HavingFilter({
},
]),
]}
- placeholder="Type Having query like count() > 10 ..."
+ placeholder={placeholder}
basicSetup={{
lineNumbers: false,
autocompletion: true,
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/QueryAddOns.styles.scss b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/QueryAddOns.styles.scss
index c66b8b8126..05cb3036ec 100644
--- a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/QueryAddOns.styles.scss
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/QueryAddOns.styles.scss
@@ -343,8 +343,29 @@
font-size: 12px !important;
}
- input {
+ // Not select search inputs: they would grow the select past 36px.
+ .input-with-label input {
min-height: 36px;
}
+
+ .input-with-label,
+ .periscope-input-with-label {
+ min-height: 36px;
+
+ .label {
+ min-width: 80px;
+ }
+
+ // `ghost` strips the border.
+ .close-btn.periscope-btn {
+ border: 1px solid var(--input-with-label-border-color, var(--l2-border));
+ background: var(--input-with-label-background-color, var(--l2-background));
+ }
+ }
+
+ .periscope-input-with-label .input .ant-select-selection-placeholder {
+ color: var(--query-builder-v2-placeholder-color, var(--l3-foreground));
+ font-size: 12px;
+ }
}
}
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/QueryAddOns.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/QueryAddOns.tsx
index 86e2709060..af892f2a8d 100644
--- a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/QueryAddOns.tsx
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/QueryAddOns.tsx
@@ -1,22 +1,17 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
-import { Button, Tooltip } from 'antd';
+import { Button } from 'antd';
import cx from 'classnames';
import { ToggleGroupSimple } from '@signozhq/ui/toggle-group';
+import { TooltipSimple } from '@signozhq/ui/tooltip';
import InputWithLabel from 'components/InputWithLabel/InputWithLabel';
-import { ATTRIBUTE_TYPES, PANEL_TYPES } from 'constants/queryBuilder';
+import { PANEL_TYPES } from 'constants/queryBuilder';
import { GroupByFilter } from 'container/QueryBuilder/filters/GroupByFilter/GroupByFilter';
import { OrderByFilter } from 'container/QueryBuilder/filters/OrderByFilter/OrderByFilter';
import { ReduceToFilter } from 'container/QueryBuilder/filters/ReduceToFilter/ReduceToFilter';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { useQueryOperations } from 'hooks/queryBuilder/useQueryBuilderOperations';
import { get, isEmpty } from 'lodash-es';
-import {
- BarChart,
- ChevronUp,
- ExternalLink,
- Grid3X3,
- ScrollText,
-} from '@signozhq/icons';
+import { ChevronUp } from '@signozhq/icons';
import { Querybuildertypesv5BucketOptionsDTO } from 'api/generated/services/sigNoz.schemas';
import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
import { MetricAggregation } from 'types/api/v5/queryRange';
@@ -34,162 +29,20 @@ import {
import BucketOptions from './BucketOptions/BucketOptions';
import HavingFilter from './HavingFilter/HavingFilter';
-import { buildDefaultLegendFromGroupBy } from './utils';
+import {
+ ADD_ON_DEFINITIONS,
+ BASE_ADD_ONS,
+ BUCKET_OPTIONS,
+ HISTOGRAM_ATTRIBUTE_TYPES,
+ type InputAddOnField,
+ REDUCE_TO,
+} from './constants';
+import TooltipContent from './TooltipContent';
+import type { AddOn } from './types';
+import { buildDefaultLegendFromGroupBy, hasValue } from './utils';
import './QueryAddOns.styles.scss';
-interface AddOn {
- icon: React.ReactNode;
- label: string;
- key: QueryBuilderField;
- description?: string;
- docLink?: string;
-}
-
-/** Fields the add-on bar does not own: each has its own control elsewhere in the query. */
-type NonAddOnField =
- | QueryBuilderField.Aggregation
- | QueryBuilderField.StepInterval
- | QueryBuilderField.Functions
- | QueryBuilderField.Formula
- | QueryBuilderField.AdditionalQueries;
-
-// Omit rather than Partial, so a field added to the enum has to be placed on one side.
-const ADD_ONS_KEYS_TO_QUERY_PATH: Omit<
- Record<QueryBuilderField, string>,
- NonAddOnField
-> = {
- [QueryBuilderField.GroupBy]: 'groupBy',
- [QueryBuilderField.Having]: 'having.expression',
- [QueryBuilderField.OrderBy]: 'orderBy',
- [QueryBuilderField.Limit]: 'limit',
- [QueryBuilderField.Legend]: 'legend',
- [QueryBuilderField.ReduceTo]: 'reduceTo',
- [QueryBuilderField.BucketOptions]: 'bucketOptions',
-};
-
-const ADD_ONS: AddOn[] = [
- {
- icon: <BarChart size={14} />,
- label: 'Group By',
- key: QueryBuilderField.GroupBy,
- description:
- 'Break down data by attributes like service name, endpoint, status code, or region. Essential for spotting patterns and comparing performance across different segments.',
- docLink: 'https://signoz.io/docs/querying/aggregation-grouping/#grouping',
- },
- {
- icon: <ScrollText size={14} />,
- label: 'Having',
- key: QueryBuilderField.Having,
- description:
- 'Filter grouped results based on aggregate conditions. Show only groups meeting specific criteria, like error rates > 5% or p99 latency > 500',
- docLink:
- 'https://signoz.io/docs/querying/result-manipulation/#conditional-filtering-with-having',
- },
- {
- icon: <ScrollText size={14} />,
- label: 'Order By',
- key: QueryBuilderField.OrderBy,
- description:
- 'Sort results to surface what matters most. Quickly identify slowest operations, most frequent errors, or highest resource consumers.',
- docLink:
- 'https://signoz.io/docs/querying/result-manipulation/#sorting--limiting',
- },
- {
- icon: <ScrollText size={14} />,
- label: 'Limit',
- key: QueryBuilderField.Limit,
- description:
- 'Show only the top/bottom N results. Perfect for focusing on outliers, reducing noise, and improving dashboard performance.',
- docLink:
- 'https://signoz.io/docs/querying/result-manipulation/#how-limit-works-for-time-series',
- },
- {
- icon: <ScrollText size={14} />,
- label: 'Legend format',
- key: QueryBuilderField.Legend,
- description:
- 'Customize series labels using variables like {{service.name}}-{{endpoint}}. Makes charts readable at a glance during incident investigation.',
- docLink:
- 'https://signoz.io/docs/querying/aggregation-grouping/#legend-formatting',
- },
-];
-
-const REDUCE_TO: AddOn = {
- icon: <ScrollText size={14} />,
- label: 'Reduce to',
- key: QueryBuilderField.ReduceTo,
- description:
- 'Apply mathematical operations like sum, average, min, max, or percentiles to reduce multiple time series into a single value.',
- docLink:
- 'https://signoz.io/docs/userguide/query-builder-v5/#result-manipulation',
-};
-
-// Offered only by a heatmap over metrics: the bucket axis is what a heatmap plots
-// against, and no other panel type sends one. A histogram brings its own buckets.
-const HISTOGRAM_ATTRIBUTE_TYPES = new Set<string>([
- ATTRIBUTE_TYPES.HISTOGRAM,
- ATTRIBUTE_TYPES.EXPONENTIAL_HISTOGRAM,
-]);
-
-const BUCKET_OPTIONS: AddOn = {
- icon: <Grid3X3 size={14} />,
- label: 'Bucket by',
- key: QueryBuilderField.BucketOptions,
- description:
- 'Choose how the bucket axis is spaced — logarithmically, so every band is the same height and the tail stays readable, or linearly up to a max value. Left to Auto, the query picks the finest log axis it can return.',
- docLink: 'https://signoz.io/docs/userguide/query-builder-v5/',
-};
-
-const hasValue = (value: unknown): boolean =>
- value != null && value !== '' && !(Array.isArray(value) && value.length === 0);
-
-// Custom tooltip content component
-function TooltipContent({
- label,
- description,
- docLink,
-}: {
- label: string;
- description?: string;
- docLink?: string;
-}): JSX.Element {
- return (
- <div
- style={{
- display: 'flex',
- flexDirection: 'column',
- gap: '8px',
- maxWidth: '300px',
- }}
- >
- <strong style={{ fontSize: '14px' }}>{label}</strong>
- {description && (
- <span style={{ fontSize: '12px', lineHeight: '1.5' }}>{description}</span>
- )}
- {docLink && (
- <a
- href={docLink}
- target="_blank"
- rel="noopener noreferrer"
- onClick={(e): void => e.stopPropagation()}
- style={{
- display: 'flex',
- alignItems: 'center',
- gap: '4px',
- color: '#4096ff',
- fontSize: '12px',
- marginTop: '4px',
- }}
- >
- Learn more
- <ExternalLink size={12} />
- </a>
- )}
- </div>
- );
-}
-
function QueryAddOns({
query,
version,
@@ -227,12 +80,16 @@ function QueryAddOns({
let addOns: AddOn[];
if (panelType === PANEL_TYPES.VALUE) {
- addOns = ADD_ONS.filter((addOn) => addOn.key === QueryBuilderField.Legend);
+ addOns = BASE_ADD_ONS.filter(
+ (addOn) => addOn.key === QueryBuilderField.Legend,
+ );
} else if (query.dataSource === DataSource.METRICS) {
// Group by for metrics is offered by MetricsAggregateSection instead.
- addOns = ADD_ONS.filter((addOn) => addOn.key !== QueryBuilderField.GroupBy);
+ addOns = BASE_ADD_ONS.filter(
+ (addOn) => addOn.key !== QueryBuilderField.GroupBy,
+ );
} else {
- addOns = [...ADD_ONS];
+ addOns = [...BASE_ADD_ONS];
}
if (showReduceTo) {
@@ -288,6 +145,12 @@ function QueryAddOns({
[resolvedFields],
);
+ const placeholderOf = useCallback(
+ (key: InputAddOnField): string =>
+ resolvedFields.get(key)?.placeholder ?? ADD_ON_DEFINITIONS[key].placeholder,
+ [resolvedFields],
+ );
+
const isDisabled = useCallback(
(key: QueryBuilderField): boolean =>
Boolean(resolvedFields.get(key)?.disabled),
@@ -306,12 +169,6 @@ function QueryAddOns({
if (!initializedRef.current || hasAvailabilityItemsChanged) {
initializedRef.current = true;
- const activeAddOnKeys = new Set(
- Object.entries(ADD_ONS_KEYS_TO_QUERY_PATH)
- .filter(([, path]) => hasValue(get(query, path)))
- .map(([key]) => key as QueryBuilderField),
- );
-
// Initial seeding from query values on mount. A disabled field never opens.
setSelectedViews(
offeredAddOns.filter((addOn) => {
@@ -319,7 +176,7 @@ function QueryAddOns({
return (
resolved?.pinned ||
- (activeAddOnKeys.has(addOn.key) && !resolved?.disabled)
+ (hasValue(get(query, addOn.queryPath)) && !resolved?.disabled)
);
}),
);
@@ -448,7 +305,7 @@ function QueryAddOns({
{selectedViews.find((view) => view.key === QueryBuilderField.GroupBy) && (
<div className="add-on-content" data-testid="group-by-content">
<div className="periscope-input-with-label">
- <Tooltip
+ <TooltipSimple
title={
<TooltipContent
label="Group By"
@@ -456,13 +313,13 @@ function QueryAddOns({
docLink="https://signoz.io/docs/querying/aggregation-grouping/#grouping"
/>
}
- placement="top"
- mouseEnterDelay={0.5}
+ arrow
+ delayDuration={500}
>
<div className="label" style={{ cursor: 'help' }}>
Group By
</div>
- </Tooltip>
+ </TooltipSimple>
<div className="input">
<GroupByFilter
disabled={
@@ -471,6 +328,7 @@ function QueryAddOns({
}
query={query}
onChange={handleChangeGroupByKeys}
+ placeholder={placeholderOf(QueryBuilderField.GroupBy)}
/>
</div>
{!isPinned(QueryBuilderField.GroupBy) && (
@@ -486,7 +344,7 @@ function QueryAddOns({
{selectedViews.find((view) => view.key === QueryBuilderField.Having) && (
<div className="add-on-content" data-testid="having-content">
<div className="periscope-input-with-label">
- <Tooltip
+ <TooltipSimple
title={
<TooltipContent
label="Having"
@@ -494,18 +352,19 @@ function QueryAddOns({
docLink="https://signoz.io/docs/querying/result-manipulation/#conditional-filtering-with-having"
/>
}
- placement="top"
- mouseEnterDelay={0.5}
+ arrow
+ delayDuration={500}
>
<div className="label" style={{ cursor: 'help' }}>
Having
</div>
- </Tooltip>
+ </TooltipSimple>
<div className="input">
<HavingFilter
onClose={(): void => handleRemoveView(QueryBuilderField.Having)}
onChange={handleChangeHaving}
queryData={query}
+ placeholder={placeholderOf(QueryBuilderField.Having)}
/>
</div>
</div>
@@ -518,7 +377,7 @@ function QueryAddOns({
type="number"
onChange={handleChangeLimit}
initialValue={query?.limit ?? undefined}
- placeholder="Enter limit"
+ placeholder={placeholderOf(QueryBuilderField.Limit)}
onClose={(): void => handleRemoveView(QueryBuilderField.Limit)}
closeIcon={<ChevronUp size={16} />}
/>
@@ -527,7 +386,7 @@ function QueryAddOns({
{selectedViews.find((view) => view.key === QueryBuilderField.OrderBy) && (
<div className="add-on-content" data-testid="order-by-content">
<div className="periscope-input-with-label">
- <Tooltip
+ <TooltipSimple
title={
<TooltipContent
label="Order By"
@@ -535,13 +394,13 @@ function QueryAddOns({
docLink="https://signoz.io/docs/querying/result-manipulation/#sorting--limiting"
/>
}
- placement="top"
- mouseEnterDelay={0.5}
+ arrow
+ delayDuration={500}
>
<div className="label" style={{ cursor: 'help' }}>
Order By
</div>
- </Tooltip>
+ </TooltipSimple>
<div className="input">
<OrderByFilter
entityVersion={version}
@@ -549,6 +408,7 @@ function QueryAddOns({
onChange={handleChangeOrderByKeys}
isRawQuery={isRawQuery}
isNewQueryV2
+ placeholder={placeholderOf(QueryBuilderField.OrderBy)}
/>
</div>
{!isPinned(QueryBuilderField.OrderBy) && (
@@ -566,7 +426,7 @@ function QueryAddOns({
showReduceTo && (
<div className="add-on-content" data-testid="reduce-to-content">
<div className="periscope-input-with-label">
- <Tooltip
+ <TooltipSimple
title={
<TooltipContent
label="Reduce to"
@@ -574,13 +434,13 @@ function QueryAddOns({
docLink="https://signoz.io/docs/userguide/query-builder-v5/#result-manipulation"
/>
}
- placement="top"
- mouseEnterDelay={0.5}
+ arrow
+ delayDuration={500}
>
<div className="label" style={{ cursor: 'help' }}>
Reduce to
</div>
- </Tooltip>
+ </TooltipSimple>
<div className="input">
<ReduceToFilter query={query} onChange={handleChangeReduceToV5} />
</div>
@@ -600,7 +460,7 @@ function QueryAddOns({
<div className="add-on-content" data-testid="legend-format-content">
<InputWithLabel
label="Legend format"
- placeholder="Write legend format"
+ placeholder={placeholderOf(QueryBuilderField.Legend)}
onChange={handleChangeQueryLegend}
initialValue={isEmpty(query?.legend) ? undefined : query?.legend}
onClose={(): void => handleRemoveView(QueryBuilderField.Legend)}
@@ -647,7 +507,7 @@ function QueryAddOns({
return {
value: addOn.key,
label: (
- <Tooltip
+ <TooltipSimple
title={
<TooltipContent
label={addOn.label}
@@ -655,8 +515,8 @@ function QueryAddOns({
docLink={resolved?.disabled ? undefined : addOn.docLink}
/>
}
- placement="top"
- mouseEnterDelay={0.5}
+ arrow
+ delayDuration={500}
>
<span
className={cx('add-on-tab-title', {
@@ -668,7 +528,7 @@ function QueryAddOns({
{addOn.icon}
{addOn.label}
</span>
- </Tooltip>
+ </TooltipSimple>
),
};
})}
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/TooltipContent.module.scss b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/TooltipContent.module.scss
new file mode 100644
index 0000000000..22d115fb96
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/TooltipContent.module.scss
@@ -0,0 +1,24 @@
+.content {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-4);
+ max-width: 300px;
+}
+
+.label {
+ font-size: var(--font-size-sm);
+}
+
+.description {
+ font-size: var(--font-size-xs);
+ line-height: var(--line-height-normal);
+}
+
+.docLink {
+ display: flex;
+ align-items: center;
+ gap: var(--spacing-2);
+ margin-top: var(--spacing-2);
+ color: var(--accent-primary);
+ font-size: var(--font-size-xs);
+}
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/TooltipContent.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/TooltipContent.tsx
new file mode 100644
index 0000000000..36471f5022
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/TooltipContent.tsx
@@ -0,0 +1,33 @@
+import { ExternalLink } from '@signozhq/icons';
+
+import styles from './TooltipContent.module.scss';
+
+// Custom tooltip content component
+export default function TooltipContent({
+ label,
+ description,
+ docLink,
+}: {
+ label: string;
+ description?: string;
+ docLink?: string;
+}): JSX.Element {
+ return (
+ <div className={styles.content}>
+ <strong className={styles.label}>{label}</strong>
+ {description && <span className={styles.description}>{description}</span>}
+ {docLink && (
+ <a
+ href={docLink}
+ target="_blank"
+ rel="noopener noreferrer"
+ onClick={(e): void => e.stopPropagation()}
+ className={styles.docLink}
+ >
+ Learn more
+ <ExternalLink size={12} />
+ </a>
+ )}
+ </div>
+ );
+}
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/constants.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/constants.tsx
new file mode 100644
index 0000000000..5c404472e7
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/constants.tsx
@@ -0,0 +1,115 @@
+import { BarChart, Grid3X3, ScrollText } from '@signozhq/icons';
+import { ATTRIBUTE_TYPES } from 'constants/queryBuilder';
+
+import { QueryBuilderField } from '../../queryBuilderFields.types';
+
+import type { AddOn, AddOnDefinition, AddOnField } from './types';
+
+// A Record, so a field added to the enum has to be placed here or in `NonAddOnField`.
+export const ADD_ON_DEFINITIONS = {
+ [QueryBuilderField.GroupBy]: {
+ input: true,
+ icon: <BarChart size={14} />,
+ label: 'Group By',
+ queryPath: 'groupBy',
+ placeholder: 'Everything (no breakdown)',
+ description:
+ 'Break down data by attributes like service name, endpoint, status code, or region. Essential for spotting patterns and comparing performance across different segments.',
+ docLink: 'https://signoz.io/docs/querying/aggregation-grouping/#grouping',
+ },
+ [QueryBuilderField.Having]: {
+ input: true,
+ icon: <ScrollText size={14} />,
+ label: 'Having',
+ queryPath: 'having.expression',
+ placeholder: 'Type Having query like count() > 10 ...',
+ description:
+ 'Filter grouped results based on aggregate conditions. Show only groups meeting specific criteria, like error rates > 5% or p99 latency > 500',
+ docLink:
+ 'https://signoz.io/docs/querying/result-manipulation/#conditional-filtering-with-having',
+ },
+ [QueryBuilderField.OrderBy]: {
+ input: true,
+ icon: <ScrollText size={14} />,
+ label: 'Order By',
+ queryPath: 'orderBy',
+ placeholder: 'Select fields to order by',
+ description:
+ 'Sort results to surface what matters most. Quickly identify slowest operations, most frequent errors, or highest resource consumers.',
+ docLink:
+ 'https://signoz.io/docs/querying/result-manipulation/#sorting--limiting',
+ },
+ [QueryBuilderField.Limit]: {
+ input: true,
+ icon: <ScrollText size={14} />,
+ label: 'Limit',
+ queryPath: 'limit',
+ placeholder: 'Enter limit',
+ description:
+ 'Show only the top/bottom N results. Perfect for focusing on outliers, reducing noise, and improving dashboard performance.',
+ docLink:
+ 'https://signoz.io/docs/querying/result-manipulation/#how-limit-works-for-time-series',
+ },
+ [QueryBuilderField.Legend]: {
+ input: true,
+ icon: <ScrollText size={14} />,
+ label: 'Legend format',
+ queryPath: 'legend',
+ placeholder: 'Write legend format',
+ description:
+ 'Customize series labels using variables like {{service.name}}-{{endpoint}}. Makes charts readable at a glance during incident investigation.',
+ docLink:
+ 'https://signoz.io/docs/querying/aggregation-grouping/#legend-formatting',
+ },
+ [QueryBuilderField.ReduceTo]: {
+ input: false,
+ icon: <ScrollText size={14} />,
+ label: 'Reduce to',
+ queryPath: 'reduceTo',
+ description:
+ 'Apply mathematical operations like sum, average, min, max, or percentiles to reduce multiple time series into a single value.',
+ docLink:
+ 'https://signoz.io/docs/userguide/query-builder-v5/#result-manipulation',
+ },
+ [QueryBuilderField.BucketOptions]: {
+ input: false,
+ icon: <Grid3X3 size={14} />,
+ label: 'Bucket by',
+ queryPath: 'bucketOptions',
+ description:
+ 'Choose how the bucket axis is spaced — logarithmically, so every band is the same height and the tail stays readable, or linearly up to a max value. Left to Auto, the query picks the finest log axis it can return.',
+ docLink: 'https://signoz.io/docs/userguide/query-builder-v5/',
+ },
+} as const satisfies Record<AddOnField, AddOnDefinition>;
+
+export type InputAddOnField = {
+ [K in AddOnField]: (typeof ADD_ON_DEFINITIONS)[K] extends { input: true }
+ ? K
+ : never;
+}[AddOnField];
+
+const toAddOn = (key: AddOnField): AddOn => ({
+ key,
+ ...ADD_ON_DEFINITIONS[key],
+});
+
+export const BASE_ADD_ONS = (
+ [
+ QueryBuilderField.GroupBy,
+ QueryBuilderField.Having,
+ QueryBuilderField.OrderBy,
+ QueryBuilderField.Limit,
+ QueryBuilderField.Legend,
+ ] as const satisfies readonly AddOnField[]
+).map(toAddOn);
+
+export const REDUCE_TO = toAddOn(QueryBuilderField.ReduceTo);
+
+// Offered only by a heatmap over metrics: the bucket axis is what a heatmap plots
+// against, and no other panel type sends one. A histogram brings its own buckets.
+export const HISTOGRAM_ATTRIBUTE_TYPES = new Set<string>([
+ ATTRIBUTE_TYPES.HISTOGRAM,
+ ATTRIBUTE_TYPES.EXPONENTIAL_HISTOGRAM,
+]);
+
+export const BUCKET_OPTIONS = toAddOn(QueryBuilderField.BucketOptions);
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/types.ts b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/types.ts
new file mode 100644
index 0000000000..5ff51e765e
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/types.ts
@@ -0,0 +1,27 @@
+import type { QueryBuilderField } from '../../queryBuilderFields.types';
+
+/** Fields the add-on bar does not own: each has its own control elsewhere in the query. */
+export type NonAddOnField =
+ | QueryBuilderField.Aggregation
+ | QueryBuilderField.StepInterval
+ | QueryBuilderField.Functions
+ | QueryBuilderField.Formula
+ | QueryBuilderField.AdditionalQueries;
+
+export type AddOnField = Exclude<QueryBuilderField, NonAddOnField>;
+
+export interface AddOnSpec {
+ icon: React.ReactNode;
+ label: string;
+ /** Where the add-on's value lives on the query; a value there opens it on mount. */
+ queryPath: string;
+ description?: string;
+ docLink?: string;
+}
+
+/** A text field has to name what leaving it empty means. */
+export type AddOnDefinition =
+ | (AddOnSpec & { input: true; placeholder: string })
+ | (AddOnSpec & { input: false });
+
+export type AddOn = AddOnDefinition & { key: AddOnField };
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/utils.ts b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/utils.ts
index fff24de2bc..dcb540823b 100644
--- a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/utils.ts
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAddOns/utils.ts
@@ -14,3 +14,6 @@ export const buildDefaultLegendFromGroupBy = (
return segments.join(', ');
};
+
+export const hasValue = (value: unknown): boolean =>
+ value != null && value !== '' && !(Array.isArray(value) && value.length === 0);
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAggregation/QueryAggregation.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAggregation/QueryAggregation.tsx
index 73418d8733..63d0577858 100644
--- a/frontend/src/components/QueryBuilderV2/QueryV2/QueryAggregation/QueryAggregation.tsx
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryAggregation/QueryAggregation.tsx
@@ -12,7 +12,11 @@ import {
QueryBuilderField,
QueryBuilderFieldsConfig,
} from '../../queryBuilderFields.types';
-import { resolveQueryBuilderField } from '../../queryBuilderFields.utils';
+import {
+ resolveQueryBuilderField,
+ type ResolvedQueryBuilderField,
+ STEP_INTERVAL_PLACEHOLDER,
+} from '../../queryBuilderFields.utils';
import QueryAggregationSelect from './QueryAggregationSelect';
@@ -33,9 +37,9 @@ function QueryAggregationOptions({
queryData: IBuilderQuery | IBuilderTraceOperator;
fieldsConfig?: QueryBuilderFieldsConfig;
}): JSX.Element {
- const stepInterval = useMemo(() => {
+ const stepInterval = useMemo<ResolvedQueryBuilderField>(() => {
if (panelType === PANEL_TYPES.VALUE) {
- return { hidden: true, disabled: false, reason: undefined };
+ return { hidden: true, disabled: false, pinned: false };
}
const isNonMetricSource =
@@ -45,7 +49,7 @@ function QueryAggregationOptions({
isNonMetricSource &&
(panelType === PANEL_TYPES.TABLE || panelType === PANEL_TYPES.PIE)
) {
- return { hidden: true, disabled: false, reason: undefined };
+ return { hidden: true, disabled: false, pinned: false };
}
return resolveQueryBuilderField(QueryBuilderField.StepInterval, fieldsConfig);
@@ -105,7 +109,7 @@ function QueryAggregationOptions({
initialValue={queryData?.stepInterval ? queryData?.stepInterval : null}
className="query-aggregation-interval-input"
label="Seconds"
- placeholder="Auto"
+ placeholder={stepInterval.placeholder ?? STEP_INTERVAL_PLACEHOLDER}
type="number"
onChange={handleAggregationIntervalChange}
disabled={stepInterval.disabled}
diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QueryV2.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QueryV2.tsx
index eeb5e44397..1fc029cefd 100644
--- a/frontend/src/components/QueryBuilderV2/QueryV2/QueryV2.tsx
+++ b/frontend/src/components/QueryBuilderV2/QueryV2/QueryV2.tsx
@@ -316,6 +316,7 @@ export const QueryV2 = forwardRef(function QueryV2(
index={index}
key={`metrics-aggregate-section-${query.queryName}-${query.dataSource}-${signalSource}`}
version="v4"
+ fieldsConfig={fieldsConfig}
/>
)}
diff --git a/frontend/src/components/QueryBuilderV2/__tests__/QueryAddOns.test.tsx b/frontend/src/components/QueryBuilderV2/__tests__/QueryAddOns.test.tsx
index 4140c284b3..391e96c1fb 100644
--- a/frontend/src/components/QueryBuilderV2/__tests__/QueryAddOns.test.tsx
+++ b/frontend/src/components/QueryBuilderV2/__tests__/QueryAddOns.test.tsx
@@ -9,6 +9,7 @@ import {
} from 'tests/test-utils';
import { DataSource, ReduceOperators } from 'types/common/queryBuilder';
+import { QueryBuilderField } from '../queryBuilderFields.types';
import QueryAddOns from '../QueryV2/QueryAddOns/QueryAddOns';
// Mocks: only what is required for this component to render and for us to assert handler calls
@@ -34,9 +35,10 @@ jest.mock('hooks/queryBuilder/useQueryBuilder', () => ({
}));
jest.mock('container/QueryBuilder/filters/GroupByFilter/GroupByFilter', () => ({
- GroupByFilter: ({ onChange }: any): JSX.Element => (
+ GroupByFilter: ({ onChange, placeholder }: any): JSX.Element => (
<button
data-testid="groupby"
+ data-placeholder={placeholder}
onClick={(): void => onChange(['service.name'])}
>
GroupByFilter
@@ -45,9 +47,10 @@ jest.mock('container/QueryBuilder/filters/GroupByFilter/GroupByFilter', () => ({
}));
jest.mock('container/QueryBuilder/filters/OrderByFilter/OrderByFilter', () => ({
- OrderByFilter: ({ onChange }: any): JSX.Element => (
+ OrderByFilter: ({ onChange, placeholder }: any): JSX.Element => (
<button
data-testid="orderby"
+ data-placeholder={placeholder}
onClick={(): void => onChange([{ columnName: 'duration', order: 'desc' }])}
>
OrderByFilter
@@ -57,10 +60,11 @@ jest.mock('container/QueryBuilder/filters/OrderByFilter/OrderByFilter', () => ({
jest.mock('../QueryV2/QueryAddOns/HavingFilter/HavingFilter', () => ({
__esModule: true,
- default: ({ onChange, onClose }: any): JSX.Element => (
+ default: ({ onChange, onClose, placeholder }: any): JSX.Element => (
<div>
<button
data-testid="having-change"
+ data-placeholder={placeholder}
onClick={(): void => onChange('p99 > 500')}
>
HavingFilter
@@ -169,6 +173,55 @@ describe('QueryAddOns', () => {
expect(mockHandleChangeQueryData).toHaveBeenCalledWith('limit', 10);
});
+ it.each([
+ [QueryBuilderField.Limit, 'input-Limit', 'placeholder'],
+ [QueryBuilderField.Legend, 'input-Legend format', 'placeholder'],
+ [QueryBuilderField.GroupBy, 'groupby', 'data-placeholder'],
+ [QueryBuilderField.Having, 'having-change', 'data-placeholder'],
+ [QueryBuilderField.OrderBy, 'orderby', 'data-placeholder'],
+ ])('shows the configured %s placeholder', (field, inputTestId, attribute) => {
+ render(
+ <QueryAddOns
+ query={baseQuery()}
+ version="v5"
+ isRawQuery={false}
+ showReduceTo={false}
+ panelType={PANEL_TYPES.TIME_SERIES}
+ index={0}
+ fieldsConfig={{
+ [field]: { state: 'pinned', placeholder: 'Default X' },
+ }}
+ isForTraceOperator={false}
+ />,
+ );
+
+ expect(screen.getByTestId(inputTestId)).toHaveAttribute(
+ attribute,
+ 'Default X',
+ );
+ });
+
+ it('keeps the built-in placeholder without a rule', () => {
+ render(
+ <QueryAddOns
+ query={baseQuery()}
+ version="v5"
+ isRawQuery={false}
+ showReduceTo={false}
+ panelType={PANEL_TYPES.TIME_SERIES}
+ index={0}
+ isForTraceOperator={false}
+ />,
+ );
+
+ fireEvent.click(screen.getByTestId('query-add-on-limit'));
+
+ expect(screen.getByTestId('input-Limit')).toHaveAttribute(
+ 'placeholder',
+ 'Enter limit',
+ );
+ });
+
it('auto-opens Order By and Limit when present in query', () => {
const query = baseQuery({
orderBy: [{ columnName: 'duration', order: 'desc' }],
diff --git a/frontend/src/components/QueryBuilderV2/__tests__/QueryAggregation.test.tsx b/frontend/src/components/QueryBuilderV2/__tests__/QueryAggregation.test.tsx
new file mode 100644
index 0000000000..e3b7ce5c1e
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/__tests__/QueryAggregation.test.tsx
@@ -0,0 +1,47 @@
+import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
+import { render, screen } from 'tests/test-utils';
+import type { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
+import { DataSource } from 'types/common/queryBuilder';
+
+import { QueryBuilderField } from '../queryBuilderFields.types';
+import QueryAggregationOptions from '../QueryV2/QueryAggregation/QueryAggregation';
+
+jest.mock('../QueryV2/QueryAggregation/QueryAggregationSelect', () => ({
+ __esModule: true,
+ default: (): null => null,
+}));
+
+const queryData = initialQueriesMap.traces.builder
+ .queryData[0] as IBuilderQuery;
+
+describe('QueryAggregationOptions step interval placeholder', () => {
+ it('shows the configured placeholder', () => {
+ render(
+ <QueryAggregationOptions
+ dataSource={DataSource.TRACES}
+ panelType={PANEL_TYPES.TIME_SERIES}
+ onAggregationIntervalChange={jest.fn()}
+ queryData={queryData}
+ fieldsConfig={{
+ [QueryBuilderField.StepInterval]: {
+ state: 'pinned',
+ placeholder: 'Default 60',
+ },
+ }}
+ />,
+ );
+ expect(screen.getByPlaceholderText('Default 60')).toBeInTheDocument();
+ });
+
+ it('falls back to Auto', () => {
+ render(
+ <QueryAggregationOptions
+ dataSource={DataSource.TRACES}
+ panelType={PANEL_TYPES.TIME_SERIES}
+ onAggregationIntervalChange={jest.fn()}
+ queryData={queryData}
+ />,
+ );
+ expect(screen.getByPlaceholderText('Auto')).toBeInTheDocument();
+ });
+});
diff --git a/frontend/src/components/QueryBuilderV2/__tests__/queryBuilderFields.utils.test.ts b/frontend/src/components/QueryBuilderV2/__tests__/queryBuilderFields.utils.test.ts
index a9d0a041f0..220938061a 100644
--- a/frontend/src/components/QueryBuilderV2/__tests__/queryBuilderFields.utils.test.ts
+++ b/frontend/src/components/QueryBuilderV2/__tests__/queryBuilderFields.utils.test.ts
@@ -57,6 +57,14 @@ describe('resolveQueryBuilderField', () => {
expect(resolved.hidden).toBe(false);
});
+ it('carries the placeholder on a pinned field', () => {
+ const resolved = resolveQueryBuilderField(QueryBuilderField.Limit, {
+ [QueryBuilderField.Limit]: { state: 'pinned', placeholder: 'Default 10' },
+ });
+
+ expect(resolved.placeholder).toBe('Default 10');
+ });
+
it('only ever resolves one state at a time', () => {
const resolved = resolveQueryBuilderField(QueryBuilderField.Limit, {
[QueryBuilderField.Limit]: { state: 'disabled', reason: 'why' },
diff --git a/frontend/src/components/QueryBuilderV2/__tests__/syncQueryBuilderFields.test.ts b/frontend/src/components/QueryBuilderV2/__tests__/syncQueryBuilderFields.test.ts
new file mode 100644
index 0000000000..e8ba1186b2
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/__tests__/syncQueryBuilderFields.test.ts
@@ -0,0 +1,149 @@
+import type { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';
+import type { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
+
+import {
+ QueryBuilderField,
+ type SyncedQueryBuilderField,
+} from '../queryBuilderFields.types';
+import {
+ snapshotQueries,
+ syncQueryBuilderFields,
+} from '../syncQueryBuilderFields';
+
+const key = (name: string): BaseAutocompleteData =>
+ ({ key: name }) as BaseAutocompleteData;
+
+function query(
+ queryName: string,
+ {
+ groupBy = [],
+ limit = null,
+ dataSource = 'traces',
+ }: { groupBy?: string[]; limit?: number | null; dataSource?: string } = {},
+): IBuilderQuery {
+ return {
+ queryName,
+ groupBy: groupBy.map(key),
+ limit,
+ dataSource,
+ } as IBuilderQuery;
+}
+
+const GROUP_BY: SyncedQueryBuilderField[] = [QueryBuilderField.GroupBy];
+
+describe('syncQueryBuilderFields', () => {
+ it('copies an edited field to the other queries', () => {
+ const previous = snapshotQueries([query('A'), query('B')]);
+
+ expect(
+ syncQueryBuilderFields(
+ [query('A', { groupBy: ['service.name'] }), query('B')],
+ previous,
+ GROUP_BY,
+ ),
+ ).toStrictEqual([
+ { index: 1, query: query('B', { groupBy: ['service.name'] }) },
+ ]);
+ });
+
+ it('gives a new query the existing values', () => {
+ const previous = snapshotQueries([query('A', { groupBy: ['service.name'] })]);
+
+ expect(
+ syncQueryBuilderFields(
+ [query('A', { groupBy: ['service.name'] }), query('B')],
+ previous,
+ GROUP_BY,
+ ),
+ ).toStrictEqual([
+ { index: 1, query: query('B', { groupBy: ['service.name'] }) },
+ ]);
+ });
+
+ it("gives a query switched to another signal the others' values, not its reset ones", () => {
+ const previous = snapshotQueries([
+ query('A', { groupBy: ['service.name'] }),
+ query('B', { groupBy: ['service.name'], dataSource: 'metrics' }),
+ ]);
+
+ expect(
+ syncQueryBuilderFields(
+ [query('A', { groupBy: ['service.name'] }), query('B')],
+ previous,
+ GROUP_BY,
+ ),
+ ).toStrictEqual([
+ { index: 1, query: query('B', { groupBy: ['service.name'] }) },
+ ]);
+ });
+
+ it('leaves values that already differ until one is edited', () => {
+ const queries = [query('A', { groupBy: ['host.name'] }), query('B')];
+
+ expect(
+ syncQueryBuilderFields(queries, snapshotQueries(queries), GROUP_BY),
+ ).toStrictEqual([]);
+ });
+
+ it('gives a new query the first value without touching differing ones', () => {
+ const saved = [
+ query('A', { groupBy: ['service.name'] }),
+ query('B', { groupBy: ['host.name'] }),
+ ];
+
+ expect(
+ syncQueryBuilderFields(
+ [...saved, query('C')],
+ snapshotQueries(saved),
+ GROUP_BY,
+ ),
+ ).toStrictEqual([
+ { index: 2, query: query('C', { groupBy: ['service.name'] }) },
+ ]);
+ });
+
+ it('copies an edit to every query even when one was added', () => {
+ const saved = [
+ query('A', { groupBy: ['service.name'] }),
+ query('B', { groupBy: ['host.name'] }),
+ ];
+
+ expect(
+ syncQueryBuilderFields(
+ [query('A', { groupBy: ['k8s.pod.name'] }), saved[1], query('C')],
+ snapshotQueries(saved),
+ GROUP_BY,
+ ),
+ ).toStrictEqual([
+ { index: 1, query: query('B', { groupBy: ['k8s.pod.name'] }) },
+ { index: 2, query: query('C', { groupBy: ['k8s.pod.name'] }) },
+ ]);
+ });
+
+ it('syncs each field from its own source', () => {
+ const previous = snapshotQueries([query('A'), query('B')]);
+
+ expect(
+ syncQueryBuilderFields(
+ [query('A', { groupBy: ['service.name'] }), query('B', { limit: 50 })],
+ previous,
+ [QueryBuilderField.GroupBy, QueryBuilderField.Limit],
+ ),
+ ).toStrictEqual([
+ { index: 0, query: query('A', { groupBy: ['service.name'], limit: 50 }) },
+ { index: 1, query: query('B', { groupBy: ['service.name'], limit: 50 }) },
+ ]);
+ });
+
+ it('leaves fields it is not asked to sync', () => {
+ const previous = snapshotQueries([query('A'), query('B')]);
+
+ expect(
+ syncQueryBuilderFields(
+ [query('A', { limit: 50 }), query('B')],
+ previous,
+ GROUP_BY,
+ ),
+ ).toStrictEqual([]);
+ });
+});
diff --git a/frontend/src/components/QueryBuilderV2/__tests__/useSyncQueryBuilderFields.test.ts b/frontend/src/components/QueryBuilderV2/__tests__/useSyncQueryBuilderFields.test.ts
new file mode 100644
index 0000000000..1c07606722
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/__tests__/useSyncQueryBuilderFields.test.ts
@@ -0,0 +1,64 @@
+import { renderHook } from '@testing-library/react';
+import type { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';
+import type { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
+
+import {
+ QueryBuilderField,
+ type SyncedQueryBuilderField,
+} from '../queryBuilderFields.types';
+import { useSyncQueryBuilderFields } from '../useSyncQueryBuilderFields';
+
+const mockHandleSetQueryData = jest.fn();
+let mockQueries: IBuilderQuery[] = [];
+
+jest.mock('hooks/queryBuilder/useQueryBuilder', () => ({
+ useQueryBuilder: (): unknown => ({
+ currentQuery: { builder: { queryData: mockQueries } },
+ handleSetQueryData: mockHandleSetQueryData,
+ }),
+}));
+
+const query = (queryName: string, groupBy: string[]): IBuilderQuery =>
+ ({
+ queryName,
+ groupBy: groupBy.map((name) => ({ key: name }) as BaseAutocompleteData),
+ dataSource: 'traces',
+ }) as IBuilderQuery;
+
+const GROUP_BY: SyncedQueryBuilderField[] = [QueryBuilderField.GroupBy];
+
+function setup(
+ fields: SyncedQueryBuilderField[] | undefined,
+ initial: IBuilderQuery[],
+): (next: IBuilderQuery[]) => void {
+ mockQueries = initial;
+ const { rerender } = renderHook(() => useSyncQueryBuilderFields(fields));
+ return (next): void => {
+ mockQueries = next;
+ rerender();
+ };
+}
+
+describe('useSyncQueryBuilderFields', () => {
+ beforeEach(() => mockHandleSetQueryData.mockClear());
+
+ it('writes the synced value into the other queries', () => {
+ const update = setup(GROUP_BY, [query('A', []), query('B', [])]);
+
+ update([query('A', ['service.name']), query('B', [])]);
+
+ expect(mockHandleSetQueryData).toHaveBeenCalledTimes(1);
+ expect(mockHandleSetQueryData).toHaveBeenCalledWith(
+ 1,
+ query('B', ['service.name']),
+ );
+ });
+
+ it('does nothing when the kind syncs no fields', () => {
+ const update = setup(undefined, [query('A', []), query('B', [])]);
+
+ update([query('A', ['service.name']), query('B', [])]);
+
+ expect(mockHandleSetQueryData).not.toHaveBeenCalled();
+ });
+});
diff --git a/frontend/src/components/QueryBuilderV2/queryBuilderFields.types.ts b/frontend/src/components/QueryBuilderV2/queryBuilderFields.types.ts
index b3f079230b..1663fa5324 100644
--- a/frontend/src/components/QueryBuilderV2/queryBuilderFields.types.ts
+++ b/frontend/src/components/QueryBuilderV2/queryBuilderFields.types.ts
@@ -22,11 +22,23 @@ export enum QueryBuilderField {
AdditionalQueries = 'additional_queries',
}
-/** `reason` is required on `disabled`: an inert control the user can see has to explain itself. */
+/** Per-query builder fields that can be kept equal across a panel's queries. */
+export type SyncedQueryBuilderField =
+ | QueryBuilderField.GroupBy
+ | QueryBuilderField.OrderBy
+ | QueryBuilderField.Having
+ | QueryBuilderField.Limit
+ | QueryBuilderField.StepInterval
+ | QueryBuilderField.ReduceTo;
+
+/**
+ * `reason` is required on `disabled`: an inert control the user can see has to explain itself.
+ * `placeholder` on `pinned` names the value an empty field falls back to.
+ */
export type QueryBuilderFieldRule =
| { state: 'hidden' }
| { state: 'disabled'; reason: string }
- | { state: 'pinned' };
+ | { state: 'pinned'; placeholder?: string };
/**
* A caller's narrowing of the builder's surface. The builder works out which fields suit
diff --git a/frontend/src/components/QueryBuilderV2/queryBuilderFields.utils.ts b/frontend/src/components/QueryBuilderV2/queryBuilderFields.utils.ts
index 4226b71f4a..bb3c75b4f5 100644
--- a/frontend/src/components/QueryBuilderV2/queryBuilderFields.utils.ts
+++ b/frontend/src/components/QueryBuilderV2/queryBuilderFields.utils.ts
@@ -10,6 +10,7 @@ export interface ResolvedQueryBuilderField {
reason?: string;
/** Rendered open, not dismissable, and kept out of the add-on toggle bar. */
pinned: boolean;
+ placeholder?: string;
}
const AVAILABLE: ResolvedQueryBuilderField = {
@@ -18,6 +19,8 @@ const AVAILABLE: ResolvedQueryBuilderField = {
pinned: false,
};
+export const STEP_INTERVAL_PLACEHOLDER = 'Auto';
+
function fromRule(rule: QueryBuilderFieldRule): ResolvedQueryBuilderField {
switch (rule.state) {
case 'hidden':
@@ -41,8 +44,10 @@ export function resolveQueryBuilderField(
config?: QueryBuilderFieldsConfig,
): ResolvedQueryBuilderField {
const rule = config?.[field];
+ const resolved = rule ? fromRule(rule) : AVAILABLE;
+ const placeholder = rule?.state === 'pinned' ? rule.placeholder : undefined;
- return rule ? fromRule(rule) : AVAILABLE;
+ return placeholder ? { ...resolved, placeholder } : resolved;
}
/**
diff --git a/frontend/src/components/QueryBuilderV2/syncQueryBuilderFields.ts b/frontend/src/components/QueryBuilderV2/syncQueryBuilderFields.ts
new file mode 100644
index 0000000000..655c494768
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/syncQueryBuilderFields.ts
@@ -0,0 +1,82 @@
+import { isEqual } from 'lodash-es';
+import type { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
+
+import {
+ QueryBuilderField,
+ type SyncedQueryBuilderField,
+} from './queryBuilderFields.types';
+
+const QUERY_PROPERTY = {
+ [QueryBuilderField.GroupBy]: 'groupBy',
+ [QueryBuilderField.OrderBy]: 'orderBy',
+ [QueryBuilderField.Having]: 'having',
+ [QueryBuilderField.Limit]: 'limit',
+ [QueryBuilderField.StepInterval]: 'stepInterval',
+ [QueryBuilderField.ReduceTo]: 'reduceTo',
+} as const satisfies Record<SyncedQueryBuilderField, keyof IBuilderQuery>;
+
+export function snapshotQueries(
+ queries: IBuilderQuery[],
+): Map<string, IBuilderQuery> {
+ return new Map(queries.map((query) => [query.queryName, query]));
+}
+
+/**
+ * The query each field should be copied from: the one whose value just changed
+ * (to all), else a settled one (to newcomers only) when a query was added or
+ * switched signal. A signal switch reloads that query's own state, so it is
+ * never the source.
+ */
+function findSource(
+ property: keyof IBuilderQuery,
+ settled: IBuilderQuery[],
+ hasNewcomer: boolean,
+ previous: Map<string, IBuilderQuery>,
+): { source: IBuilderQuery; newcomersOnly: boolean } | undefined {
+ const changed = settled.find(
+ (query) =>
+ !isEqual(previous.get(query.queryName)?.[property], query[property]),
+ );
+ if (changed) {
+ return { source: changed, newcomersOnly: false };
+ }
+ return hasNewcomer && settled.length > 0
+ ? { source: settled[0], newcomersOnly: true }
+ : undefined;
+}
+
+export function syncQueryBuilderFields(
+ queries: IBuilderQuery[],
+ previous: Map<string, IBuilderQuery>,
+ fields: SyncedQueryBuilderField[],
+): { index: number; query: IBuilderQuery }[] {
+ const settled = queries.filter((query) => {
+ const before = previous.get(query.queryName);
+ return (
+ before?.dataSource === query.dataSource && before.source === query.source
+ );
+ });
+ const hasNewcomer = settled.length < queries.length;
+ const sources = fields
+ .map((field) => QUERY_PROPERTY[field])
+ .map((property) => ({
+ property,
+ found: findSource(property, settled, hasNewcomer, previous),
+ }));
+
+ return queries.flatMap((query, index) => {
+ const isSettled = settled.includes(query);
+ const patch = sources.reduce<Partial<IBuilderQuery>>(
+ (acc, { property, found }) =>
+ found &&
+ !(found.newcomersOnly && isSettled) &&
+ !isEqual(query[property], found.source[property])
+ ? { ...acc, [property]: found.source[property] }
+ : acc,
+ {},
+ );
+ return Object.keys(patch).length > 0
+ ? [{ index, query: { ...query, ...patch } }]
+ : [];
+ });
+}
diff --git a/frontend/src/components/QueryBuilderV2/useSyncQueryBuilderFields.ts b/frontend/src/components/QueryBuilderV2/useSyncQueryBuilderFields.ts
new file mode 100644
index 0000000000..efa939a94a
--- /dev/null
+++ b/frontend/src/components/QueryBuilderV2/useSyncQueryBuilderFields.ts
@@ -0,0 +1,37 @@
+import { useEffect, useRef } from 'react';
+import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
+import type { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
+
+import type { SyncedQueryBuilderField } from './queryBuilderFields.types';
+import {
+ snapshotQueries,
+ syncQueryBuilderFields,
+} from './syncQueryBuilderFields';
+
+const NO_FIELDS: SyncedQueryBuilderField[] = [];
+
+/**
+ * Keeps `fields` equal across builder queries: an edit to one query copies to
+ * the rest, and a query added or switched to another signal takes the others'
+ * values. Values that already differ when this starts are left alone until one
+ * of them is edited.
+ */
+export function useSyncQueryBuilderFields(
+ fields: SyncedQueryBuilderField[] = NO_FIELDS,
+): void {
+ const { currentQuery, handleSetQueryData } = useQueryBuilder();
+ const queries = currentQuery.builder.queryData;
+ const previousRef = useRef<Map<string, IBuilderQuery>>();
+ const enabled = fields.length > 0;
+
+ useEffect(() => {
+ const previous = previousRef.current;
+ previousRef.current = enabled ? snapshotQueries(queries) : undefined;
+ if (!enabled || !previous || queries.length < 2) {
+ return;
+ }
+ syncQueryBuilderFields(queries, previous, fields).forEach(
+ ({ index, query }) => handleSetQueryData(index, query),
+ );
+ }, [enabled, fields, queries, handleSetQueryData]);
+}
diff --git a/frontend/src/container/QueryBuilder/filters/GroupByFilter/GroupByFilter.interfaces.ts b/frontend/src/container/QueryBuilder/filters/GroupByFilter/GroupByFilter.interfaces.ts
index cea028d3ee..31df05db18 100644
--- a/frontend/src/container/QueryBuilder/filters/GroupByFilter/GroupByFilter.interfaces.ts
+++ b/frontend/src/container/QueryBuilder/filters/GroupByFilter/GroupByFilter.interfaces.ts
@@ -5,4 +5,5 @@ export type GroupByFilterProps = {
query: IBuilderQuery;
onChange: (values: BaseAutocompleteData[]) => void;
disabled: boolean;
+ placeholder?: string;
};
diff --git a/frontend/src/container/QueryBuilder/filters/GroupByFilter/GroupByFilter.tsx b/frontend/src/container/QueryBuilder/filters/GroupByFilter/GroupByFilter.tsx
index c49d5bfd2c..13b6f9a7f3 100644
--- a/frontend/src/container/QueryBuilder/filters/GroupByFilter/GroupByFilter.tsx
+++ b/frontend/src/container/QueryBuilder/filters/GroupByFilter/GroupByFilter.tsx
@@ -34,6 +34,7 @@ export const GroupByFilter = memo(function GroupByFilter({
query,
onChange,
disabled,
+ placeholder = 'Everything (no breakdown)',
}: GroupByFilterProps): JSX.Element {
const getPopupContainer = useSelectPopupContainer();
const [searchText, setSearchText] = useState<string>('');
@@ -153,7 +154,7 @@ export const GroupByFilter = memo(function GroupByFilter({
notFoundContent={isFetching ? <Spin size="small" /> : null}
onChange={handleChange}
data-testid="group-by"
- placeholder={localValues?.length === 0 ? 'Everything (no breakdown)' : ''}
+ placeholder={localValues?.length === 0 ? placeholder : ''}
/>
);
});
diff --git a/frontend/src/container/QueryBuilder/filters/OrderByFilter/OrderByFilter.interfaces.ts b/frontend/src/container/QueryBuilder/filters/OrderByFilter/OrderByFilter.interfaces.ts
index 0ab051386b..8f470bb982 100644
--- a/frontend/src/container/QueryBuilder/filters/OrderByFilter/OrderByFilter.interfaces.ts
+++ b/frontend/src/container/QueryBuilder/filters/OrderByFilter/OrderByFilter.interfaces.ts
@@ -9,6 +9,7 @@ export type OrderByFilterProps = {
isRawQuery?: boolean;
entityVersion?: string;
isNewQueryV2?: boolean;
+ placeholder?: string;
};
export type OrderByFilterValue = {
diff --git a/frontend/src/container/QueryBuilder/filters/OrderByFilter/OrderByFilter.tsx b/frontend/src/container/QueryBuilder/filters/OrderByFilter/OrderByFilter.tsx
index 0d8236cfeb..de39e15f6e 100644
--- a/frontend/src/container/QueryBuilder/filters/OrderByFilter/OrderByFilter.tsx
+++ b/frontend/src/container/QueryBuilder/filters/OrderByFilter/OrderByFilter.tsx
@@ -21,6 +21,7 @@ export function OrderByFilter({
isRawQuery = false,
entityVersion,
isNewQueryV2 = false,
+ placeholder,
}: OrderByFilterProps): JSX.Element {
const getPopupContainer = useSelectPopupContainer();
const {
@@ -101,6 +102,7 @@ export function OrderByFilter({
options={optionsData}
notFoundContent={isFetching ? <Spin size="small" /> : null}
onChange={handleChange}
+ placeholder={placeholder}
data-testid="order-by"
/>
);
diff --git a/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder.module.scss b/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder.module.scss
index 4c4e25610e..7526293720 100644
--- a/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder.module.scss
+++ b/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder.module.scss
@@ -5,6 +5,7 @@
height: 100%;
min-height: 0;
overflow: auto;
+ scrollbar-gutter: stable;
background-color: var(--l1-background);
@include custom-scrollbar;
}
diff --git a/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder.tsx b/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder.tsx
index eadbf29f2b..c0192b4760 100644
--- a/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder.tsx
+++ b/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/PanelEditorQueryBuilder.tsx
@@ -19,6 +19,7 @@ import PromQLQueryContainer from 'container/QueryBuilder/rawQueryEditors/PromQL'
import RunQueryBtn from 'container/QueryBuilder/components/RunQueryBtn/RunQueryBtn';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { useIsDarkMode } from 'hooks/useDarkMode';
+import { useSyncQueryBuilderFields } from 'components/QueryBuilderV2/useSyncQueryBuilderFields';
import { DataSource } from 'types/common/queryBuilder';
import {
@@ -72,6 +73,7 @@ function PanelEditorQueryBuilder({
const isRawQuery = isRawRequest(panelDefinition.queryCapabilities);
const { currentQuery } = useQueryBuilder();
const isDarkMode = useIsDarkMode();
+ useSyncQueryBuilderFields(panelDefinition.syncedQueryBuilderFields);
// Cleared here, not in QueryBuilderV2: builder panes unmount on every tab switch.
useEffect(() => {
diff --git a/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/__tests__/PanelEditorQueryBuilder.test.tsx b/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/__tests__/PanelEditorQueryBuilder.test.tsx
index 5fd747cc39..434de3e486 100644
--- a/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/__tests__/PanelEditorQueryBuilder.test.tsx
+++ b/frontend/src/pages/DashboardPage/DashboardContainer/PanelEditor/PanelEditorQueryBuilder/__tests__/PanelEditorQueryBuilder.test.tsx
@@ -20,6 +20,9 @@ jest.mock('hooks/queryBuilder/useQueryBuilder', () => ({
useQueryBuilder: jest.fn(),
}));
jest.mock('hooks/useDarkMode', () => ({ useIsDarkMode: (): boolean => false }));
+jest.mock('components/QueryBuilderV2/useSyncQueryBuilderFields', () => ({
+ useSyncQueryBuilderFields: jest.fn(),
+}));
jest.mock('components/QueryBuilderV2/QueryBuilderV2', () => ({
QueryBuilderV2: (props: unknown): null => {
mockQueryBuilderV2(props);
diff --git a/frontend/src/pages/DashboardPage/DashboardContainer/Panels/types/panelCapabilities.ts b/frontend/src/pages/DashboardPage/DashboardContainer/Panels/types/panelCapabilities.ts
index 3468fce1e1..8bbdd22f1c 100644
--- a/frontend/src/pages/DashboardPage/DashboardContainer/Panels/types/panelCapabilities.ts
+++ b/frontend/src/pages/DashboardPage/DashboardContainer/Panels/types/panelCapabilities.ts
@@ -32,6 +32,11 @@ export interface PanelQueryCapabilities {
* carries no explicit limit" — an explicit limit means the user asked for a fixed set.
*/
serverPaginated: boolean;
+ /**
+ * `limit` for a lone builder query that sets none. Skipped with several queries,
+ * where per-query limits can keep different groups and break the join.
+ */
+ defaultRowLimit?: number;
}
/** Raw rows rather than an aggregated result — the single source for "is this raw?". */
diff --git a/frontend/src/pages/DashboardPage/DashboardContainer/Panels/types/panelDefinition.ts b/frontend/src/pages/DashboardPage/DashboardContainer/Panels/types/panelDefinition.ts
index 3bc92efee1..ec3a5396da 100644
--- a/frontend/src/pages/DashboardPage/DashboardContainer/Panels/types/panelDefinition.ts
+++ b/frontend/src/pages/DashboardPage/DashboardContainer/Panels/types/panelDefinition.ts
@@ -8,6 +8,7 @@ import type { ChartLine } from '@signozhq/icons';
import type { SectionConfig } from './sections';
import type { AnyPanelInteractionProps } from './interactions';
import type { PanelKind } from './panelKind';
+import type { SyncedQueryBuilderField } from 'components/QueryBuilderV2/queryBuilderFields.types';
import type {
PanelQueryCapabilities,
QueryBuilderFieldsConfig,
@@ -121,6 +122,8 @@ export interface QueryPanelDefinition<
queryBuilderFields: QueryBuilderFieldsConfig;
/** How this kind's query-range request is shaped (request type, paging, result formatting). */
queryCapabilities: PanelQueryCapabilities;
+ /** Builder fields kept equal across queries: an edit to one query copies to the rest. */
+ syncedQueryBuilderFields?: SyncedQueryBuilderField[];
}
/**
diff --git a/frontend/src/pages/DashboardPage/DashboardContainer/queryV5/__tests__/buildQueryRangeRequest.test.ts b/frontend/src/pages/DashboardPage/DashboardContainer/queryV5/__tests__/buildQueryRangeRequest.test.ts
index 3e12cb7a9e..cf90b069b6 100644
--- a/frontend/src/pages/DashboardPage/DashboardContainer/queryV5/__tests__/buildQueryRangeRequest.test.ts
+++ b/frontend/src/pages/DashboardPage/DashboardContainer/queryV5/__tests__/buildQueryRangeRequest.test.ts
@@ -71,6 +71,10 @@ const LIST_PANEL_CAPABILITIES = {
orderTiebreaker: true,
serverPaginated: true,
};
+const DEFAULT_LIMIT_CAPABILITIES = {
+ ...TABLE_CAPABILITIES,
+ defaultRowLimit: 10_000,
+};
describe('requestType', () => {
it.each([
@@ -396,6 +400,51 @@ describe('buildQueryRangeRequest', () => {
});
});
+describe('defaultRowLimit', () => {
+ function limits(queries: DashboardtypesQueryDTO[]): unknown[] {
+ const request = buildQueryRangeRequest({
+ queries,
+ queryCapabilities: DEFAULT_LIMIT_CAPABILITIES,
+ startMs: START_MS,
+ endMs: START_MS + HOUR_MS,
+ });
+ return (request.compositeQuery?.queries ?? []).map(
+ (envelope) => (envelope.spec as { limit?: number }).limit,
+ );
+ }
+
+ it('limits a lone builder query', () => {
+ expect(limits(bareBuilderQuery({ name: 'A' }))).toStrictEqual([10_000]);
+ });
+
+ it('keeps a limit the user set', () => {
+ expect(limits(bareBuilderQuery({ name: 'A', limit: 50 }))).toStrictEqual([
+ 50,
+ ]);
+ });
+
+ it('leaves several queries unlimited so their join keeps every group', () => {
+ expect(
+ limits(
+ compositeQuery([
+ { type: 'builder_query', spec: { name: 'A' } },
+ { type: 'builder_query', spec: { name: 'B' } },
+ ]),
+ ),
+ ).toStrictEqual([undefined, undefined]);
+ });
+
+ it('leaves a lone non-builder query alone', () => {
+ expect(
+ limits(
+ compositeQuery([
+ { type: 'clickhouse_sql', spec: { name: 'A', query: 'SELECT 1' } },
+ ]),
+ ),
+ ).toStrictEqual([undefined]);
+ });
+});
+
describe('getBucketedStepIntervalSeconds', () => {
// V1 parity: getBarStepIntervalPoints in container/GridCardLayout/utils.ts
it.each([
diff --git a/frontend/src/pages/DashboardPage/DashboardContainer/queryV5/buildQueryRangeRequest.ts b/frontend/src/pages/DashboardPage/DashboardContainer/queryV5/buildQueryRangeRequest.ts
index ab610c715d..037838ccd9 100644
--- a/frontend/src/pages/DashboardPage/DashboardContainer/queryV5/buildQueryRangeRequest.ts
+++ b/frontend/src/pages/DashboardPage/DashboardContainer/queryV5/buildQueryRangeRequest.ts
@@ -217,6 +217,30 @@ function withPagination(
});
}
+function withDefaultRowLimit(
+ envelopes: Querybuildertypesv5QueryEnvelopeDTO[],
+ limit: number,
+): Querybuildertypesv5QueryEnvelopeDTO[] {
+ const [envelope] = envelopes;
+ if (
+ envelopes.length !== 1 ||
+ envelope.type !==
+ Querybuildertypesv5QueryEnvelopeBuilderDTOType.builder_query ||
+ envelope.spec?.limit
+ ) {
+ return envelopes;
+ }
+ return [
+ {
+ ...envelope,
+ spec: {
+ ...envelope.spec,
+ limit,
+ } as Querybuildertypesv5BuilderQuerySpecDTO,
+ },
+ ];
+}
+
export interface BuildQueryRangeRequestArgs {
queries: DashboardtypesQueryDTO[];
/**
@@ -249,6 +273,7 @@ export function buildQueryRangeRequest({
formatTableResultForUI,
bucketedStepInterval,
orderTiebreaker,
+ defaultRowLimit,
},
startMs,
endMs,
@@ -266,6 +291,9 @@ export function buildQueryRangeRequest({
if (pagination) {
envelopes = withPagination(envelopes, pagination);
}
+ if (defaultRowLimit) {
+ envelopes = withDefaultRowLimit(envelopes, defaultRowLimit);
+ }
return {
schemaVersion: 'v1',