mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-31 12:12:08 +08:00
QB - Logs - Enable TimeShift function (#4792)
* feat: qb - logs - enable time shift function * feat: qb - logs - enable time shift function * feat: show functions for logs in v3 version too
This commit is contained in:
parent
a7b0ef55ad
commit
6a4aa9a956
@ -2,7 +2,7 @@
|
|||||||
import { QueryFunctionsTypes } from 'types/common/queryBuilder';
|
import { QueryFunctionsTypes } from 'types/common/queryBuilder';
|
||||||
import { SelectOption } from 'types/common/select';
|
import { SelectOption } from 'types/common/select';
|
||||||
|
|
||||||
export const queryFunctionOptions: SelectOption<string, string>[] = [
|
export const metricQueryFunctionOptions: SelectOption<string, string>[] = [
|
||||||
{
|
{
|
||||||
value: QueryFunctionsTypes.CUTOFF_MIN,
|
value: QueryFunctionsTypes.CUTOFF_MIN,
|
||||||
label: 'Cut Off Min',
|
label: 'Cut Off Min',
|
||||||
@ -65,6 +65,12 @@ export const queryFunctionOptions: SelectOption<string, string>[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const logsQueryFunctionOptions: SelectOption<string, string>[] = [
|
||||||
|
{
|
||||||
|
value: QueryFunctionsTypes.TIME_SHIFT,
|
||||||
|
label: 'Time Shift',
|
||||||
|
},
|
||||||
|
];
|
||||||
interface QueryFunctionConfigType {
|
interface QueryFunctionConfigType {
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
showInput: boolean;
|
showInput: boolean;
|
||||||
|
@ -56,8 +56,9 @@ function QuerySection({
|
|||||||
initialDataSource: ALERTS_DATA_SOURCE_MAP[alertType],
|
initialDataSource: ALERTS_DATA_SOURCE_MAP[alertType],
|
||||||
}}
|
}}
|
||||||
showFunctions={
|
showFunctions={
|
||||||
alertType === AlertTypes.METRICS_BASED_ALERT &&
|
(alertType === AlertTypes.METRICS_BASED_ALERT &&
|
||||||
alertDef.version === ENTITY_VERSION_V4
|
alertDef.version === ENTITY_VERSION_V4) ||
|
||||||
|
alertType === AlertTypes.LOGS_BASED_ALERT
|
||||||
}
|
}
|
||||||
version={alertDef.version || 'v3'}
|
version={alertDef.version || 'v3'}
|
||||||
/>
|
/>
|
||||||
|
@ -77,6 +77,7 @@
|
|||||||
.qb-entity-options {
|
.qb-entity-options {
|
||||||
.options {
|
.options {
|
||||||
border-color: var(--bg-vanilla-300);
|
border-color: var(--bg-vanilla-300);
|
||||||
|
box-shadow: none;
|
||||||
|
|
||||||
.periscope-btn {
|
.periscope-btn {
|
||||||
border-color: var(--bg-vanilla-300);
|
border-color: var(--bg-vanilla-300);
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
IBuilderQuery,
|
IBuilderQuery,
|
||||||
QueryFunctionProps,
|
QueryFunctionProps,
|
||||||
} from 'types/api/queryBuilder/queryBuilderData';
|
} from 'types/api/queryBuilder/queryBuilderData';
|
||||||
|
import { DataSource } from 'types/common/queryBuilder';
|
||||||
|
|
||||||
import QueryFunctions from '../QueryFunctions/QueryFunctions';
|
import QueryFunctions from '../QueryFunctions/QueryFunctions';
|
||||||
|
|
||||||
@ -57,6 +58,8 @@ export default function QBEntityOptions({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isLogsDataSource = query?.dataSource === DataSource.LOGS;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
<div className="qb-entity-options">
|
<div className="qb-entity-options">
|
||||||
@ -97,12 +100,14 @@ export default function QBEntityOptions({
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{showFunctions &&
|
{showFunctions &&
|
||||||
isMetricsDataSource &&
|
(isMetricsDataSource || isLogsDataSource) &&
|
||||||
query &&
|
query &&
|
||||||
onQueryFunctionsUpdates && (
|
onQueryFunctionsUpdates && (
|
||||||
<QueryFunctions
|
<QueryFunctions
|
||||||
|
query={query}
|
||||||
queryFunctions={query.functions}
|
queryFunctions={query.functions}
|
||||||
onChange={onQueryFunctionsUpdates}
|
onChange={onQueryFunctionsUpdates}
|
||||||
|
maxFunctions={isLogsDataSource ? 1 : 3}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Button.Group>
|
</Button.Group>
|
||||||
|
@ -36,6 +36,7 @@ import {
|
|||||||
} from 'react';
|
} from 'react';
|
||||||
import { useLocation } from 'react-use';
|
import { useLocation } from 'react-use';
|
||||||
import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
|
import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
|
||||||
|
import { DataSource } from 'types/common/queryBuilder';
|
||||||
import { transformToUpperCase } from 'utils/transformToUpperCase';
|
import { transformToUpperCase } from 'utils/transformToUpperCase';
|
||||||
|
|
||||||
import QBEntityOptions from '../QBEntityOptions/QBEntityOptions';
|
import QBEntityOptions from '../QBEntityOptions/QBEntityOptions';
|
||||||
@ -324,7 +325,10 @@ export const Query = memo(function Query({
|
|||||||
<QBEntityOptions
|
<QBEntityOptions
|
||||||
isMetricsDataSource={isMetricsDataSource}
|
isMetricsDataSource={isMetricsDataSource}
|
||||||
showFunctions={
|
showFunctions={
|
||||||
(version && version === ENTITY_VERSION_V4) || showFunctions || false
|
(version && version === ENTITY_VERSION_V4) ||
|
||||||
|
query.dataSource === DataSource.LOGS ||
|
||||||
|
showFunctions ||
|
||||||
|
false
|
||||||
}
|
}
|
||||||
isCollapsed={isCollapse}
|
isCollapsed={isCollapse}
|
||||||
entityType="query"
|
entityType="query"
|
||||||
|
@ -2,15 +2,21 @@
|
|||||||
import { Button, Flex, Input, Select } from 'antd';
|
import { Button, Flex, Input, Select } from 'antd';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import {
|
import {
|
||||||
queryFunctionOptions,
|
logsQueryFunctionOptions,
|
||||||
|
metricQueryFunctionOptions,
|
||||||
queryFunctionsTypesConfig,
|
queryFunctionsTypesConfig,
|
||||||
} from 'constants/queryFunctionOptions';
|
} from 'constants/queryFunctionOptions';
|
||||||
import { useIsDarkMode } from 'hooks/useDarkMode';
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
||||||
import { debounce, isNil } from 'lodash-es';
|
import { debounce, isNil } from 'lodash-es';
|
||||||
import { X } from 'lucide-react';
|
import { X } from 'lucide-react';
|
||||||
import { QueryFunctionProps } from 'types/api/queryBuilder/queryBuilderData';
|
import {
|
||||||
|
IBuilderQuery,
|
||||||
|
QueryFunctionProps,
|
||||||
|
} from 'types/api/queryBuilder/queryBuilderData';
|
||||||
|
import { DataSource } from 'types/common/queryBuilder';
|
||||||
|
|
||||||
interface FunctionProps {
|
interface FunctionProps {
|
||||||
|
query: IBuilderQuery;
|
||||||
funcData: QueryFunctionProps;
|
funcData: QueryFunctionProps;
|
||||||
index: any;
|
index: any;
|
||||||
handleUpdateFunctionArgs: any;
|
handleUpdateFunctionArgs: any;
|
||||||
@ -19,6 +25,7 @@ interface FunctionProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Function({
|
export default function Function({
|
||||||
|
query,
|
||||||
funcData,
|
funcData,
|
||||||
index,
|
index,
|
||||||
handleUpdateFunctionArgs,
|
handleUpdateFunctionArgs,
|
||||||
@ -44,6 +51,12 @@ export default function Function({
|
|||||||
500,
|
500,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// update the logic when we start supporting functions for traces
|
||||||
|
const functionOptions =
|
||||||
|
query.dataSource === DataSource.LOGS
|
||||||
|
? logsQueryFunctionOptions
|
||||||
|
: metricQueryFunctionOptions;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex className="query-function">
|
<Flex className="query-function">
|
||||||
<Select
|
<Select
|
||||||
@ -62,7 +75,7 @@ export default function Function({
|
|||||||
boxShadow: `4px 10px 16px 2px rgba(0, 0, 0, 0.20)`,
|
boxShadow: `4px 10px 16px 2px rgba(0, 0, 0, 0.20)`,
|
||||||
}}
|
}}
|
||||||
placement="bottomRight"
|
placement="bottomRight"
|
||||||
options={queryFunctionOptions}
|
options={functionOptions}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{showInput && (
|
{showInput && (
|
||||||
|
@ -6,19 +6,29 @@ import { useIsDarkMode } from 'hooks/useDarkMode';
|
|||||||
import { cloneDeep, pullAt } from 'lodash-es';
|
import { cloneDeep, pullAt } from 'lodash-es';
|
||||||
import { Plus } from 'lucide-react';
|
import { Plus } from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { QueryFunctionProps } from 'types/api/queryBuilder/queryBuilderData';
|
import {
|
||||||
import { QueryFunctionsTypes } from 'types/common/queryBuilder';
|
IBuilderQuery,
|
||||||
|
QueryFunctionProps,
|
||||||
|
} from 'types/api/queryBuilder/queryBuilderData';
|
||||||
|
import { DataSource, QueryFunctionsTypes } from 'types/common/queryBuilder';
|
||||||
|
|
||||||
import Function from './Function';
|
import Function from './Function';
|
||||||
|
|
||||||
const defaultFunctionStruct: QueryFunctionProps = {
|
const defaultMetricFunctionStruct: QueryFunctionProps = {
|
||||||
name: QueryFunctionsTypes.CUTOFF_MIN,
|
name: QueryFunctionsTypes.CUTOFF_MIN,
|
||||||
args: [],
|
args: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const defaultLogFunctionStruct: QueryFunctionProps = {
|
||||||
|
name: QueryFunctionsTypes.TIME_SHIFT,
|
||||||
|
args: [],
|
||||||
|
};
|
||||||
|
|
||||||
interface QueryFunctionsProps {
|
interface QueryFunctionsProps {
|
||||||
|
query: IBuilderQuery;
|
||||||
queryFunctions: QueryFunctionProps[];
|
queryFunctions: QueryFunctionProps[];
|
||||||
onChange: (functions: QueryFunctionProps[]) => void;
|
onChange: (functions: QueryFunctionProps[]) => void;
|
||||||
|
maxFunctions: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SVG component
|
// SVG component
|
||||||
@ -71,8 +81,10 @@ function FunctionIcon({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function QueryFunctions({
|
export default function QueryFunctions({
|
||||||
|
query,
|
||||||
queryFunctions,
|
queryFunctions,
|
||||||
onChange,
|
onChange,
|
||||||
|
maxFunctions = 3,
|
||||||
}: QueryFunctionsProps): JSX.Element {
|
}: QueryFunctionsProps): JSX.Element {
|
||||||
const [functions, setFunctions] = useState<QueryFunctionProps[]>(
|
const [functions, setFunctions] = useState<QueryFunctionProps[]>(
|
||||||
queryFunctions,
|
queryFunctions,
|
||||||
@ -81,6 +93,11 @@ export default function QueryFunctions({
|
|||||||
const isDarkMode = useIsDarkMode();
|
const isDarkMode = useIsDarkMode();
|
||||||
|
|
||||||
const handleAddNewFunction = (): void => {
|
const handleAddNewFunction = (): void => {
|
||||||
|
const defaultFunctionStruct =
|
||||||
|
query.dataSource === DataSource.LOGS
|
||||||
|
? defaultLogFunctionStruct
|
||||||
|
: defaultMetricFunctionStruct;
|
||||||
|
|
||||||
const updatedFunctionsArr = [
|
const updatedFunctionsArr = [
|
||||||
...functions,
|
...functions,
|
||||||
{
|
{
|
||||||
@ -149,6 +166,7 @@ export default function QueryFunctions({
|
|||||||
<div className="query-functions-list">
|
<div className="query-functions-list">
|
||||||
{functions.map((func, index) => (
|
{functions.map((func, index) => (
|
||||||
<Function
|
<Function
|
||||||
|
query={query}
|
||||||
funcData={func}
|
funcData={func}
|
||||||
index={index}
|
index={index}
|
||||||
// eslint-disable-next-line react/no-array-index-key
|
// eslint-disable-next-line react/no-array-index-key
|
||||||
@ -170,7 +188,7 @@ export default function QueryFunctions({
|
|||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
className="periscope-btn add-function-btn"
|
className="periscope-btn add-function-btn"
|
||||||
disabled={functions && functions.length >= 3}
|
disabled={functions && functions.length >= maxFunctions}
|
||||||
onClick={handleAddNewFunction}
|
onClick={handleAddNewFunction}
|
||||||
>
|
>
|
||||||
<Plus size={14} color={!isDarkMode ? '#0B0C0E' : 'white'} />
|
<Plus size={14} color={!isDarkMode ? '#0B0C0E' : 'white'} />
|
||||||
|
@ -294,7 +294,10 @@ export const useQueryOperations: UseQueryOperations = ({
|
|||||||
...query,
|
...query,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (newQuery.dataSource === DataSource.METRICS) {
|
if (
|
||||||
|
newQuery.dataSource === DataSource.METRICS ||
|
||||||
|
newQuery.dataSource === DataSource.LOGS
|
||||||
|
) {
|
||||||
newQuery.functions = functions;
|
newQuery.functions = functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,6 +307,7 @@ export const useQueryOperations: UseQueryOperations = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const isMetricsDataSource = query.dataSource === DataSource.METRICS;
|
const isMetricsDataSource = query.dataSource === DataSource.METRICS;
|
||||||
|
const isLogsDataSource = query.dataSource === DataSource.LOGS;
|
||||||
|
|
||||||
const isTracePanelType = panelType === PANEL_TYPES.TRACE;
|
const isTracePanelType = panelType === PANEL_TYPES.TRACE;
|
||||||
|
|
||||||
@ -346,6 +350,7 @@ export const useQueryOperations: UseQueryOperations = ({
|
|||||||
return {
|
return {
|
||||||
isTracePanelType,
|
isTracePanelType,
|
||||||
isMetricsDataSource,
|
isMetricsDataSource,
|
||||||
|
isLogsDataSource,
|
||||||
operators,
|
operators,
|
||||||
spaceAggregationOptions,
|
spaceAggregationOptions,
|
||||||
listOfAdditionalFilters,
|
listOfAdditionalFilters,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user