mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 23:25:54 +08:00
feat: limit & order by is enabled in the metrics query builder (#3566)
* feat: limit filter is enabled in the metrics filters * chore: orderBy is enabled for metrics data source * chore: fix table type limit and order by --------- Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
This commit is contained in:
parent
9d3c4598ac
commit
4227faa6b5
@ -151,7 +151,6 @@ export const Query = memo(function Query({
|
|||||||
case PANEL_TYPES.TIME_SERIES: {
|
case PANEL_TYPES.TIME_SERIES: {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{!isMetricsDataSource && (
|
|
||||||
<Col span={11}>
|
<Col span={11}>
|
||||||
<Row gutter={[11, 5]}>
|
<Row gutter={[11, 5]}>
|
||||||
<Col flex="5.93rem">
|
<Col flex="5.93rem">
|
||||||
@ -162,7 +161,6 @@ export const Query = memo(function Query({
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Col>
|
</Col>
|
||||||
)}
|
|
||||||
<Col span={11}>
|
<Col span={11}>
|
||||||
<Row gutter={[11, 5]}>
|
<Row gutter={[11, 5]}>
|
||||||
<Col flex="5.93rem">
|
<Col flex="5.93rem">
|
||||||
@ -173,7 +171,6 @@ export const Query = memo(function Query({
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Col>
|
</Col>
|
||||||
{!isMetricsDataSource && (
|
|
||||||
<Col span={11}>
|
<Col span={11}>
|
||||||
<Row gutter={[11, 5]}>
|
<Row gutter={[11, 5]}>
|
||||||
<Col flex="5.93rem">
|
<Col flex="5.93rem">
|
||||||
@ -182,7 +179,6 @@ export const Query = memo(function Query({
|
|||||||
<Col flex="1 1 12.5rem">{renderOrderByFilter()}</Col>
|
<Col flex="1 1 12.5rem">{renderOrderByFilter()}</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Col>
|
</Col>
|
||||||
)}
|
|
||||||
|
|
||||||
<Col span={11}>{renderAggregateEveryFilter()}</Col>
|
<Col span={11}>{renderAggregateEveryFilter()}</Col>
|
||||||
</>
|
</>
|
||||||
@ -251,7 +247,6 @@ export const Query = memo(function Query({
|
|||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
panelType,
|
panelType,
|
||||||
isMetricsDataSource,
|
|
||||||
query,
|
query,
|
||||||
filterConfigs?.limit?.isHidden,
|
filterConfigs?.limit?.isHidden,
|
||||||
filterConfigs?.having?.isHidden,
|
filterConfigs?.having?.isHidden,
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
||||||
import { getOperatorsBySourceAndPanelType } from 'lib/newQueryBuilder/getOperatorsBySourceAndPanelType';
|
import { getOperatorsBySourceAndPanelType } from 'lib/newQueryBuilder/getOperatorsBySourceAndPanelType';
|
||||||
import { findDataTypeOfOperator } from 'lib/query/findDataTypeOfOperator';
|
import { findDataTypeOfOperator } from 'lib/query/findDataTypeOfOperator';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';
|
import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';
|
||||||
import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
|
import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
|
||||||
import {
|
import {
|
||||||
@ -148,13 +148,9 @@ export const useQueryOperations: UseQueryOperations = ({
|
|||||||
[query, index, handleSetQueryData],
|
[query, index, handleSetQueryData],
|
||||||
);
|
);
|
||||||
|
|
||||||
const isMetricsDataSource = useMemo(
|
const isMetricsDataSource = query.dataSource === DataSource.METRICS;
|
||||||
() => query.dataSource === DataSource.METRICS,
|
|
||||||
[query.dataSource],
|
const isTracePanelType = panelType === PANEL_TYPES.TRACE;
|
||||||
);
|
|
||||||
const isTracePanelType = useMemo(() => panelType === PANEL_TYPES.TRACE, [
|
|
||||||
panelType,
|
|
||||||
]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (initialDataSource && dataSource !== initialDataSource) return;
|
if (initialDataSource && dataSource !== initialDataSource) return;
|
||||||
|
@ -3062,7 +3062,7 @@ func applyMetricLimit(results []*v3.Result, queryRangeParams *v3.QueryRangeParam
|
|||||||
limit := builderQueries[result.QueryName].Limit
|
limit := builderQueries[result.QueryName].Limit
|
||||||
|
|
||||||
orderByList := builderQueries[result.QueryName].OrderBy
|
orderByList := builderQueries[result.QueryName].OrderBy
|
||||||
if limit != 0 {
|
if limit >= 0 {
|
||||||
if len(orderByList) == 0 {
|
if len(orderByList) == 0 {
|
||||||
// If no orderBy is specified, sort by value in descending order
|
// If no orderBy is specified, sort by value in descending order
|
||||||
orderByList = []v3.OrderBy{{ColumnName: constants.SigNozOrderByValue, Order: "desc"}}
|
orderByList = []v3.OrderBy{{ColumnName: constants.SigNozOrderByValue, Order: "desc"}}
|
||||||
@ -3070,6 +3070,18 @@ func applyMetricLimit(results []*v3.Result, queryRangeParams *v3.QueryRangeParam
|
|||||||
sort.SliceStable(result.Series, func(i, j int) bool {
|
sort.SliceStable(result.Series, func(i, j int) bool {
|
||||||
for _, orderBy := range orderByList {
|
for _, orderBy := range orderByList {
|
||||||
if orderBy.ColumnName == constants.SigNozOrderByValue {
|
if orderBy.ColumnName == constants.SigNozOrderByValue {
|
||||||
|
|
||||||
|
// For table type queries (we rely on the fact that one value for row), sort
|
||||||
|
// based on final aggregation value
|
||||||
|
if len(result.Series[i].Points) == 1 && len(result.Series[j].Points) == 1 {
|
||||||
|
if orderBy.Order == "asc" {
|
||||||
|
return result.Series[i].Points[0].Value < result.Series[j].Points[0].Value
|
||||||
|
} else if orderBy.Order == "desc" {
|
||||||
|
return result.Series[i].Points[0].Value > result.Series[j].Points[0].Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For graph type queries, sort based on GroupingSetsPoint
|
||||||
if result.Series[i].GroupingSetsPoint == nil || result.Series[j].GroupingSetsPoint == nil {
|
if result.Series[i].GroupingSetsPoint == nil || result.Series[j].GroupingSetsPoint == nil {
|
||||||
// Handle nil GroupingSetsPoint, if needed
|
// Handle nil GroupingSetsPoint, if needed
|
||||||
// Here, we assume non-nil values are always less than nil values
|
// Here, we assume non-nil values are always less than nil values
|
||||||
@ -3102,7 +3114,7 @@ func applyMetricLimit(results []*v3.Result, queryRangeParams *v3.QueryRangeParam
|
|||||||
return i < j
|
return i < j
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(result.Series) > int(limit) {
|
if limit > 0 && len(result.Series) > int(limit) {
|
||||||
result.Series = result.Series[:limit]
|
result.Series = result.Series[:limit]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user