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.

chore(frontend): dynamic vars load with empty textbox variables (#10480)

Ashwin Bhatkal4f0e245e3d11
diff --git a/frontend/src/providers/Dashboard/store/__tests__/variableFetchStore.test.ts b/frontend/src/providers/Dashboard/store/__tests__/variableFetchStore.test.ts
index 0100dbbfc6..4d93cd67e8 100644
--- a/frontend/src/providers/Dashboard/store/__tests__/variableFetchStore.test.ts
+++ b/frontend/src/providers/Dashboard/store/__tests__/variableFetchStore.test.ts
@@ -25,7 +25,7 @@ function resetStore(): void {
function mockContext(overrides: Partial<VariableFetchContext> = {}): void {
getVariableDependencyContextSpy.mockReturnValue({
- doAllVariablesHaveValuesSelected: false,
+ doAllQueryVariablesHaveValuesSelected: false,
variableTypes: {},
dynamicVariableOrder: [],
dependencyData: null,
@@ -175,9 +175,9 @@ describe('variableFetchStore', () => {
expect(storeSnapshot.cycleIds.b).toBe(1);
});
- it('should set dynamic variables to waiting when not all variables have values', () => {
+ it('should set dynamic variables to waiting when not all query variables have values', () => {
mockContext({
- doAllVariablesHaveValuesSelected: false,
+ doAllQueryVariablesHaveValuesSelected: false,
dependencyData: buildDependencyData({ order: [] }),
variableTypes: { dyn1: 'DYNAMIC' },
dynamicVariableOrder: ['dyn1'],
@@ -190,9 +190,9 @@ describe('variableFetchStore', () => {
expect(storeSnapshot.states.dyn1).toBe('waiting');
});
- it('should set dynamic variables to loading when all variables have values', () => {
+ it('should set dynamic variables to loading when all query variables have values', () => {
mockContext({
- doAllVariablesHaveValuesSelected: true,
+ doAllQueryVariablesHaveValuesSelected: true,
dependencyData: buildDependencyData({ order: [] }),
variableTypes: { dyn1: 'DYNAMIC' },
dynamicVariableOrder: ['dyn1'],
@@ -523,5 +523,77 @@ describe('variableFetchStore', () => {
expect(variableFetchStore.getSnapshot().states.b).toBe('revalidating');
});
+
+ it('should enqueue dynamic variables immediately when all query variables are settled', () => {
+ mockContext({
+ dependencyData: buildDependencyData({
+ transitiveDescendants: { customVar: [] },
+ parentDependencyGraph: {},
+ }),
+ variableTypes: { q1: 'QUERY', customVar: 'CUSTOM', dyn1: 'DYNAMIC' },
+ dynamicVariableOrder: ['dyn1'],
+ });
+
+ variableFetchStore.update((d) => {
+ d.states.q1 = 'idle';
+ d.states.customVar = 'idle';
+ d.states.dyn1 = 'idle';
+ });
+
+ enqueueDescendantsOfVariable('customVar');
+
+ const snapshot = variableFetchStore.getSnapshot();
+ expect(snapshot.states.dyn1).toBe('loading');
+ expect(snapshot.cycleIds.dyn1).toBe(1);
+ });
+
+ it('should set dynamic variables to waiting when query variables are not yet settled', () => {
+ // a is a query variable still loading; changing customVar should queue dyn1 as waiting
+ mockContext({
+ dependencyData: buildDependencyData({
+ transitiveDescendants: { customVar: [] },
+ parentDependencyGraph: {},
+ }),
+ variableTypes: { a: 'QUERY', customVar: 'CUSTOM', dyn1: 'DYNAMIC' },
+ dynamicVariableOrder: ['dyn1'],
+ });
+
+ variableFetchStore.update((d) => {
+ d.states.a = 'loading';
+ d.states.customVar = 'idle';
+ d.states.dyn1 = 'idle';
+ });
+
+ enqueueDescendantsOfVariable('customVar');
+
+ expect(variableFetchStore.getSnapshot().states.dyn1).toBe('waiting');
+ });
+
+ it('should set dynamic variables to waiting when a query descendant is now loading', () => {
+ // a -> b (QUERY), dyn1 (DYNAMIC). When a changes, b starts loading,
+ // so dyn1 should wait until b settles.
+ mockContext({
+ dependencyData: buildDependencyData({
+ transitiveDescendants: { a: ['b'] },
+ parentDependencyGraph: { b: ['a'] },
+ }),
+ variableTypes: { a: 'QUERY', b: 'QUERY', dyn1: 'DYNAMIC' },
+ dynamicVariableOrder: ['dyn1'],
+ });
+
+ variableFetchStore.update((d) => {
+ d.states.a = 'idle';
+ d.states.b = 'idle';
+ d.states.dyn1 = 'idle';
+ });
+
+ enqueueDescendantsOfVariable('a');
+
+ const snapshot = variableFetchStore.getSnapshot();
+ // b's parent (a) is idle → b starts loading
+ expect(snapshot.states.b).toBe('loading');
+ // dyn1 must wait because b is now loading (not settled)
+ expect(snapshot.states.dyn1).toBe('waiting');
+ });
});
});
diff --git a/frontend/src/providers/Dashboard/store/dashboardVariables/__tests__/dashboardVariablesStore.test.ts b/frontend/src/providers/Dashboard/store/dashboardVariables/__tests__/dashboardVariablesStore.test.ts
index 47d540b758..e22f8fc18b 100644
--- a/frontend/src/providers/Dashboard/store/dashboardVariables/__tests__/dashboardVariablesStore.test.ts
+++ b/frontend/src/providers/Dashboard/store/dashboardVariables/__tests__/dashboardVariablesStore.test.ts
@@ -134,7 +134,7 @@ describe('dashboardVariablesStore', () => {
expect(dependencyData).not.toBeNull();
});
- it('should report doAllVariablesHaveValuesSelected as true when all variables have selectedValue', () => {
+ it('should report doAllQueryVariablesHaveValuesSelected as true when all query variables have values', () => {
setDashboardVariablesStore({
dashboardId: 'dash-1',
variables: {
@@ -146,18 +146,20 @@ describe('dashboardVariablesStore', () => {
}),
region: createVariable({
name: 'region',
- type: 'CUSTOM',
+ type: 'QUERY',
order: 1,
selectedValue: 'us-east',
}),
},
});
- const { doAllVariablesHaveValuesSelected } = getVariableDependencyContext();
- expect(doAllVariablesHaveValuesSelected).toBe(true);
+ const {
+ doAllQueryVariablesHaveValuesSelected,
+ } = getVariableDependencyContext();
+ expect(doAllQueryVariablesHaveValuesSelected).toBe(true);
});
- it('should report doAllVariablesHaveValuesSelected as false when some variables lack selectedValue', () => {
+ it('should report doAllQueryVariablesHaveValuesSelected as false when a query variable lacks a selectedValue', () => {
setDashboardVariablesStore({
dashboardId: 'dash-1',
variables: {
@@ -169,66 +171,52 @@ describe('dashboardVariablesStore', () => {
}),
region: createVariable({
name: 'region',
- type: 'CUSTOM',
+ type: 'QUERY',
order: 1,
selectedValue: undefined,
}),
},
});
- const { doAllVariablesHaveValuesSelected } = getVariableDependencyContext();
- expect(doAllVariablesHaveValuesSelected).toBe(false);
+ const {
+ doAllQueryVariablesHaveValuesSelected,
+ } = getVariableDependencyContext();
+ expect(doAllQueryVariablesHaveValuesSelected).toBe(false);
});
- it('should treat DYNAMIC variable with allSelected=true and selectedValue=null as having a value', () => {
+ it('should ignore non-QUERY variables when computing doAllQueryVariablesHaveValuesSelected', () => {
+ // env (QUERY) has a value; region (CUSTOM) and dyn1 (DYNAMIC) do not — they are ignored
setDashboardVariablesStore({
dashboardId: 'dash-1',
variables: {
- dyn1: createVariable({
- name: 'dyn1',
- type: 'DYNAMIC',
- order: 0,
- selectedValue: null as any,
- allSelected: true,
- }),
env: createVariable({
name: 'env',
type: 'QUERY',
- order: 1,
+ order: 0,
selectedValue: 'prod',
}),
- },
- });
-
- const { doAllVariablesHaveValuesSelected } = getVariableDependencyContext();
- expect(doAllVariablesHaveValuesSelected).toBe(true);
- });
-
- it('should treat DYNAMIC variable with allSelected=true and selectedValue=undefined as having a value', () => {
- setDashboardVariablesStore({
- dashboardId: 'dash-1',
- variables: {
+ region: createVariable({
+ name: 'region',
+ type: 'CUSTOM',
+ order: 1,
+ selectedValue: undefined,
+ }),
dyn1: createVariable({
name: 'dyn1',
type: 'DYNAMIC',
- order: 0,
- selectedValue: undefined,
- allSelected: true,
- }),
- env: createVariable({
- name: 'env',
- type: 'QUERY',
- order: 1,
- selectedValue: 'prod',
+ order: 2,
+ selectedValue: '',
}),
},
});
- const { doAllVariablesHaveValuesSelected } = getVariableDependencyContext();
- expect(doAllVariablesHaveValuesSelected).toBe(true);
+ const {
+ doAllQueryVariablesHaveValuesSelected,
+ } = getVariableDependencyContext();
+ expect(doAllQueryVariablesHaveValuesSelected).toBe(true);
});
- it('should treat DYNAMIC variable with allSelected=true and empty string selectedValue as having a value', () => {
+ it('should return true for doAllQueryVariablesHaveValuesSelected when there are no query variables', () => {
setDashboardVariablesStore({
dashboardId: 'dash-1',
variables: {
@@ -237,61 +225,72 @@ describe('dashboardVariablesStore', () => {
type: 'DYNAMIC',
order: 0,
selectedValue: '',
- allSelected: true,
- }),
- env: createVariable({
- name: 'env',
- type: 'QUERY',
- order: 1,
- selectedValue: 'prod',
}),
},
});
- const { doAllVariablesHaveValuesSelected } = getVariableDependencyContext();
- expect(doAllVariablesHaveValuesSelected).toBe(true);
+ const {
+ doAllQueryVariablesHaveValuesSelected,
+ } = getVariableDependencyContext();
+ expect(doAllQueryVariablesHaveValuesSelected).toBe(true);
});
- it('should treat DYNAMIC variable with allSelected=true and empty array selectedValue as having a value', () => {
+ // Any non-nil, non-empty-array selectedValue is treated as selected
+ it.each([
+ { label: 'numeric 0', selectedValue: 0 as number },
+ { label: 'boolean false', selectedValue: false as boolean },
+ // ideally not possible but till we have concrete schema, we should not block dynamic variables
+ { label: 'empty string', selectedValue: '' },
+ {
+ label: 'non-empty array',
+ selectedValue: ['a', 'b'] as (string | number | boolean)[],
+ },
+ ])('should return true when selectedValue is $label', ({ selectedValue }) => {
setDashboardVariablesStore({
dashboardId: 'dash-1',
variables: {
- dyn1: createVariable({
- name: 'dyn1',
- type: 'DYNAMIC',
- order: 0,
- selectedValue: [] as any,
- allSelected: true,
- }),
env: createVariable({
name: 'env',
type: 'QUERY',
- order: 1,
- selectedValue: 'prod',
+ order: 0,
+ selectedValue,
}),
},
});
- const { doAllVariablesHaveValuesSelected } = getVariableDependencyContext();
- expect(doAllVariablesHaveValuesSelected).toBe(true);
+ const {
+ doAllQueryVariablesHaveValuesSelected,
+ } = getVariableDependencyContext();
+ expect(doAllQueryVariablesHaveValuesSelected).toBe(true);
});
- it('should report false when a DYNAMIC variable has empty selectedValue and allSelected is not true', () => {
- setDashboardVariablesStore({
- dashboardId: 'dash-1',
- variables: {
- dyn1: createVariable({
- name: 'dyn1',
- type: 'DYNAMIC',
- order: 0,
- selectedValue: '',
- allSelected: false,
- }),
- },
- });
+ // null/undefined (tested above) and empty array are treated as not selected
+ it.each([
+ {
+ label: 'null',
+ selectedValue: null as IDashboardVariable['selectedValue'],
+ },
+ { label: 'empty array', selectedValue: [] as (string | number | boolean)[] },
+ ])(
+ 'should return false when selectedValue is $label',
+ ({ selectedValue }) => {
+ setDashboardVariablesStore({
+ dashboardId: 'dash-1',
+ variables: {
+ env: createVariable({
+ name: 'env',
+ type: 'QUERY',
+ order: 0,
+ selectedValue,
+ }),
+ },
+ });
- const { doAllVariablesHaveValuesSelected } = getVariableDependencyContext();
- expect(doAllVariablesHaveValuesSelected).toBe(false);
- });
+ const {
+ doAllQueryVariablesHaveValuesSelected,
+ } = getVariableDependencyContext();
+ expect(doAllQueryVariablesHaveValuesSelected).toBe(false);
+ },
+ );
});
});
diff --git a/frontend/src/providers/Dashboard/store/dashboardVariables/dashboardVariablesStore.ts b/frontend/src/providers/Dashboard/store/dashboardVariables/dashboardVariablesStore.ts
index a20a5ec7f8..ab31e6f758 100644
--- a/frontend/src/providers/Dashboard/store/dashboardVariables/dashboardVariablesStore.ts
+++ b/frontend/src/providers/Dashboard/store/dashboardVariables/dashboardVariablesStore.ts
@@ -1,4 +1,4 @@
-import { isEmpty, isUndefined } from 'lodash-es';
+import { isNil } from 'lodash-es';
import createStore from '../store';
import { VariableFetchContext } from '../variableFetchStore';
@@ -68,28 +68,28 @@ export function updateDashboardVariablesStore({
*/
export function getVariableDependencyContext(): VariableFetchContext {
const state = dashboardVariablesStore.getSnapshot();
+ // Dynamic variables should only wait on query variables having values,
+ // not on CUSTOM, TEXTBOX, or other types.
+ const doAllQueryVariablesHaveValuesSelected = Object.values(
+ state.variables,
+ ).every((variable) => {
+ if (variable.type !== 'QUERY') {
+ return true;
+ }
- // If every variable already has a selectedValue (e.g. persisted from
- // localStorage/URL), dynamic variables can start in parallel.
- // Otherwise they wait for query vars to settle first.
- const doAllVariablesHaveValuesSelected = Object.values(state.variables).every(
- (variable) => {
- if (
- variable.type === 'DYNAMIC' &&
- (variable.selectedValue === null || isEmpty(variable.selectedValue)) &&
- variable.allSelected === true
- ) {
- return true;
- }
+ if (isNil(variable.selectedValue)) {
+ return false;
+ }
- return (
- !isUndefined(variable.selectedValue) && !isEmpty(variable.selectedValue)
- );
- },
- );
+ if (Array.isArray(variable.selectedValue)) {
+ return variable.selectedValue.length > 0;
+ }
+
+ return true;
+ });
return {
- doAllVariablesHaveValuesSelected,
+ doAllQueryVariablesHaveValuesSelected,
variableTypes: state.variableTypes,
dynamicVariableOrder: state.dynamicVariableOrder,
dependencyData: state.dependencyData,
diff --git a/frontend/src/providers/Dashboard/store/variableFetchStore.ts b/frontend/src/providers/Dashboard/store/variableFetchStore.ts
index cb645f9122..0ddcd50d9f 100644
--- a/frontend/src/providers/Dashboard/store/variableFetchStore.ts
+++ b/frontend/src/providers/Dashboard/store/variableFetchStore.ts
@@ -36,7 +36,7 @@ export type VariableFetchContext = Pick<
IDashboardVariablesStoreState,
'variableTypes' | 'dynamicVariableOrder' | 'dependencyData'
> & {
- doAllVariablesHaveValuesSelected: boolean;
+ doAllQueryVariablesHaveValuesSelected: boolean;
};
const initialState: IVariableFetchStoreState = {
@@ -88,7 +88,7 @@ export function initializeVariableFetchStore(variableNames: string[]): void {
*/
export function enqueueFetchOfAllVariables(): void {
const {
- doAllVariablesHaveValuesSelected,
+ doAllQueryVariablesHaveValuesSelected,
dependencyData,
variableTypes,
dynamicVariableOrder,
@@ -116,7 +116,7 @@ export function enqueueFetchOfAllVariables(): void {
// otherwise wait for query variables to settle first
dynamicVariableOrder.forEach((name) => {
draft.cycleIds[name] = (draft.cycleIds[name] || 0) + 1;
- draft.states[name] = doAllVariablesHaveValuesSelected
+ draft.states[name] = doAllQueryVariablesHaveValuesSelected
? resolveFetchState(draft, name)
: 'waiting';
});
@@ -208,7 +208,11 @@ export function onVariableFetchFailure(name: string): void {
* ensures parents are set before children within a single update).
*/
export function enqueueDescendantsOfVariable(name: string): void {
- const { dependencyData, variableTypes } = getVariableDependencyContext();
+ const {
+ dependencyData,
+ variableTypes,
+ dynamicVariableOrder,
+ } = getVariableDependencyContext();
if (!dependencyData) {
return;
}
@@ -230,5 +234,18 @@ export function enqueueDescendantsOfVariable(name: string): void {
? resolveFetchState(draft, desc)
: 'waiting';
});
+
+ // Dynamic variables implicitly depend on all query variable values.
+ // If all query variables are currently settled, start them immediately;
+ // otherwise they wait until query vars finish (unlocked via onVariableFetchComplete).
+ dynamicVariableOrder.forEach((dynName) => {
+ draft.cycleIds[dynName] = (draft.cycleIds[dynName] || 0) + 1;
+ draft.states[dynName] = areAllQueryVariablesSettled(
+ draft.states,
+ variableTypes,
+ )
+ ? resolveFetchState(draft, dynName)
+ : 'waiting';
+ });
});
}