mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-12 18:21:33 +08:00

* fix: having value data type * feat: connect new builder to dashboard * Fix/query builder filters (#2623) * feat: rename query data type * fix: remove reset of groupBy * fix: filters search * fix: calls autocomplete times * fix: response mapper * fix: removee unnecessary field * fix: no check ts types for old query builder * fix: disable check utils old builder
215 lines
5.0 KiB
TypeScript
215 lines
5.0 KiB
TypeScript
// ** Helpers
|
|
import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider';
|
|
import { createNewBuilderItemName } from 'lib/newQueryBuilder/createNewBuilderItemName';
|
|
import { LocalDataType } from 'types/api/queryBuilder/queryAutocompleteResponse';
|
|
import {
|
|
HavingForm,
|
|
IBuilderFormula,
|
|
IBuilderQuery,
|
|
} from 'types/api/queryBuilder/queryBuilderData';
|
|
import {
|
|
BoolOperators,
|
|
DataSource,
|
|
LogsAggregatorOperator,
|
|
MetricAggregateOperator,
|
|
NumberOperators,
|
|
PanelTypeKeys,
|
|
QueryAdditionalFilter,
|
|
ReduceOperators,
|
|
StringOperators,
|
|
TracesAggregatorOperator,
|
|
} from 'types/common/queryBuilder';
|
|
import { SelectOption } from 'types/common/select';
|
|
|
|
export const MAX_FORMULAS = 20;
|
|
export const MAX_QUERIES = 26;
|
|
|
|
export const formulasNames: string[] = Array.from(
|
|
Array(MAX_FORMULAS),
|
|
(_, i) => `F${i + 1}`,
|
|
);
|
|
const alpha: number[] = Array.from(Array(MAX_QUERIES), (_, i) => i + 65);
|
|
export const alphabet: string[] = alpha.map((str) => String.fromCharCode(str));
|
|
|
|
export enum QueryBuilderKeys {
|
|
GET_AGGREGATE_ATTRIBUTE = 'GET_AGGREGATE_ATTRIBUTE',
|
|
GET_AGGREGATE_KEYS = 'GET_AGGREGATE_KEYS',
|
|
}
|
|
|
|
export const mapOfOperators: Record<DataSource, string[]> = {
|
|
metrics: Object.values(MetricAggregateOperator),
|
|
logs: Object.values(LogsAggregatorOperator),
|
|
traces: Object.values(TracesAggregatorOperator),
|
|
};
|
|
|
|
export const mapOfFilters: Record<DataSource, QueryAdditionalFilter[]> = {
|
|
metrics: [
|
|
// eslint-disable-next-line sonarjs/no-duplicate-string
|
|
{ text: 'Aggregation interval', field: 'stepInterval' },
|
|
{ text: 'Having', field: 'having' },
|
|
],
|
|
logs: [
|
|
{ text: 'Order by', field: 'orderBy' },
|
|
{ text: 'Limit', field: 'limit' },
|
|
{ text: 'Having', field: 'having' },
|
|
{ text: 'Aggregation interval', field: 'stepInterval' },
|
|
],
|
|
traces: [
|
|
{ text: 'Order by', field: 'orderBy' },
|
|
{ text: 'Limit', field: 'limit' },
|
|
{ text: 'Having', field: 'having' },
|
|
{ text: 'Aggregation interval', field: 'stepInterval' },
|
|
],
|
|
};
|
|
|
|
export const REDUCE_TO_VALUES: SelectOption<ReduceOperators, string>[] = [
|
|
{ value: 'last', label: 'Latest of values in timeframe' },
|
|
{ value: 'sum', label: 'Sum of values in timeframe' },
|
|
{ value: 'avg', label: 'Average of values in timeframe' },
|
|
{ value: 'max', label: 'Max of values in timeframe' },
|
|
{ value: 'min', label: 'Min of values in timeframe' },
|
|
];
|
|
|
|
export const initialHavingValues: HavingForm = {
|
|
columnName: '',
|
|
op: '',
|
|
value: [],
|
|
};
|
|
|
|
export const initialAggregateAttribute: IBuilderQuery['aggregateAttribute'] = {
|
|
dataType: null,
|
|
key: '',
|
|
isColumn: null,
|
|
type: null,
|
|
};
|
|
|
|
export const initialQueryBuilderFormValues: IBuilderQuery = {
|
|
dataSource: DataSource.METRICS,
|
|
queryName: createNewBuilderItemName({ existNames: [], sourceNames: alphabet }),
|
|
aggregateOperator: Object.values(MetricAggregateOperator)[0],
|
|
aggregateAttribute: initialAggregateAttribute,
|
|
tagFilters: { items: [], op: 'AND' },
|
|
expression: createNewBuilderItemName({
|
|
existNames: [],
|
|
sourceNames: alphabet,
|
|
}),
|
|
disabled: false,
|
|
having: [],
|
|
stepInterval: 30,
|
|
limit: null,
|
|
orderBy: [],
|
|
groupBy: [],
|
|
legend: '',
|
|
reduceTo: 'sum',
|
|
};
|
|
|
|
export const initialFormulaBuilderFormValues: IBuilderFormula = {
|
|
queryName: createNewBuilderItemName({
|
|
existNames: [],
|
|
sourceNames: formulasNames,
|
|
}),
|
|
expression: '',
|
|
disabled: false,
|
|
legend: '',
|
|
};
|
|
|
|
export const operatorsByTypes: Record<LocalDataType, string[]> = {
|
|
string: Object.values(StringOperators),
|
|
number: Object.values(NumberOperators),
|
|
bool: Object.values(BoolOperators),
|
|
};
|
|
|
|
export const PANEL_TYPES: Record<PanelTypeKeys, GRAPH_TYPES> = {
|
|
TIME_SERIES: 'graph',
|
|
VALUE: 'value',
|
|
TABLE: 'table',
|
|
LIST: 'list',
|
|
EMPTY_WIDGET: 'EMPTY_WIDGET',
|
|
};
|
|
|
|
export type IQueryBuilderState = 'search';
|
|
|
|
export const QUERY_BUILDER_SEARCH_VALUES = {
|
|
MULTIPLY: 'MULTIPLY_VALUE',
|
|
SINGLE: 'SINGLE_VALUE',
|
|
NON: 'NON_VALUE',
|
|
NOT_VALID: 'NOT_VALID',
|
|
};
|
|
|
|
export const OPERATORS = {
|
|
IN: 'IN',
|
|
NIN: 'NOT_IN',
|
|
LIKE: 'LIKE',
|
|
NLIKE: 'NOT_LIKE',
|
|
'=': '=',
|
|
'!=': '!=',
|
|
EXISTS: 'EXISTS',
|
|
NOT_EXISTS: 'NOT_EXISTS',
|
|
CONTAINS: 'CONTAINS',
|
|
NOT_CONTAINS: 'NOT_CONTAINS',
|
|
'>=': '>=',
|
|
'>': '>',
|
|
'<=': '<=',
|
|
'<': '<',
|
|
};
|
|
|
|
export const QUERY_BUILDER_OPERATORS_BY_TYPES = {
|
|
string: [
|
|
OPERATORS['='],
|
|
OPERATORS['!='],
|
|
OPERATORS.IN,
|
|
OPERATORS.NIN,
|
|
OPERATORS.LIKE,
|
|
OPERATORS.NLIKE,
|
|
OPERATORS.CONTAINS,
|
|
OPERATORS.NOT_CONTAINS,
|
|
OPERATORS.EXISTS,
|
|
OPERATORS.NOT_EXISTS,
|
|
],
|
|
number: [
|
|
OPERATORS['='],
|
|
OPERATORS['!='],
|
|
OPERATORS.IN,
|
|
OPERATORS.NIN,
|
|
OPERATORS.EXISTS,
|
|
OPERATORS.NOT_EXISTS,
|
|
OPERATORS['>='],
|
|
OPERATORS['>'],
|
|
OPERATORS['<='],
|
|
OPERATORS['<'],
|
|
],
|
|
boolean: [
|
|
OPERATORS['='],
|
|
OPERATORS['!='],
|
|
OPERATORS.EXISTS,
|
|
OPERATORS.NOT_EXISTS,
|
|
],
|
|
universal: [
|
|
OPERATORS['='],
|
|
OPERATORS['!='],
|
|
OPERATORS.IN,
|
|
OPERATORS.NIN,
|
|
OPERATORS.EXISTS,
|
|
OPERATORS.NOT_EXISTS,
|
|
OPERATORS.LIKE,
|
|
OPERATORS.NLIKE,
|
|
OPERATORS['>='],
|
|
OPERATORS['>'],
|
|
OPERATORS['<='],
|
|
OPERATORS['<'],
|
|
OPERATORS.CONTAINS,
|
|
OPERATORS.NOT_CONTAINS,
|
|
],
|
|
};
|
|
|
|
export const HAVING_OPERATORS: string[] = [
|
|
OPERATORS['='],
|
|
OPERATORS['!='],
|
|
OPERATORS.IN,
|
|
OPERATORS.NIN,
|
|
OPERATORS['>='],
|
|
OPERATORS['>'],
|
|
OPERATORS['<='],
|
|
OPERATORS['<'],
|
|
];
|