mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-24 02:46:27 +00:00
chore: populate default zero queries for metrics (#9103)
This commit is contained in:
parent
ff8ac96d37
commit
1c257f3e14
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/SigNoz/govaluate"
|
"github.com/SigNoz/govaluate"
|
||||||
"github.com/SigNoz/signoz/pkg/errors"
|
"github.com/SigNoz/signoz/pkg/errors"
|
||||||
|
"github.com/SigNoz/signoz/pkg/types/metrictypes"
|
||||||
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
|
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
|
||||||
"github.com/SigNoz/signoz/pkg/valuer"
|
"github.com/SigNoz/signoz/pkg/valuer"
|
||||||
)
|
)
|
||||||
@ -423,13 +424,25 @@ func (r *QueryRangeRequest) GetQueriesSupportingZeroDefault() map[string]bool {
|
|||||||
canDefaultZero := make(map[string]bool)
|
canDefaultZero := make(map[string]bool)
|
||||||
for _, q := range r.CompositeQuery.Queries {
|
for _, q := range r.CompositeQuery.Queries {
|
||||||
if q.Type == QueryTypeBuilder {
|
if q.Type == QueryTypeBuilder {
|
||||||
if query, ok := q.Spec.(QueryBuilderQuery[TraceAggregation]); ok {
|
switch spec := q.Spec.(type) {
|
||||||
if len(query.Aggregations) == 1 && canDefaultZeroAgg(query.Aggregations[0].Expression) {
|
case QueryBuilderQuery[TraceAggregation]:
|
||||||
canDefaultZero[query.Name] = true
|
if len(spec.Aggregations) == 1 && canDefaultZeroAgg(spec.Aggregations[0].Expression) {
|
||||||
|
canDefaultZero[spec.Name] = true
|
||||||
|
}
|
||||||
|
case QueryBuilderQuery[LogAggregation]:
|
||||||
|
if len(spec.Aggregations) == 1 && canDefaultZeroAgg(spec.Aggregations[0].Expression) {
|
||||||
|
canDefaultZero[spec.Name] = true
|
||||||
|
}
|
||||||
|
case QueryBuilderQuery[MetricAggregation]:
|
||||||
|
if len(spec.Aggregations) == 1 {
|
||||||
|
timeAgg := spec.Aggregations[0].TimeAggregation
|
||||||
|
|
||||||
|
if timeAgg == metrictypes.TimeAggregationCount ||
|
||||||
|
timeAgg == metrictypes.TimeAggregationCountDistinct ||
|
||||||
|
timeAgg == metrictypes.TimeAggregationRate ||
|
||||||
|
timeAgg == metrictypes.TimeAggregationIncrease {
|
||||||
|
canDefaultZero[spec.Name] = true
|
||||||
}
|
}
|
||||||
} else if query, ok := q.Spec.(QueryBuilderQuery[LogAggregation]); ok {
|
|
||||||
if len(query.Aggregations) == 1 && canDefaultZeroAgg(query.Aggregations[0].Expression) {
|
|
||||||
canDefaultZero[query.Name] = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1683,6 +1683,86 @@ func TestQueryRangeRequest_GetQueriesSupportingZeroDefault(t *testing.T) {
|
|||||||
"A": true,
|
"A": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "test metrics",
|
||||||
|
CompositeQuery: CompositeQuery{
|
||||||
|
Queries: []QueryEnvelope{
|
||||||
|
{
|
||||||
|
Type: QueryTypeBuilder,
|
||||||
|
Spec: QueryBuilderQuery[MetricAggregation]{
|
||||||
|
Name: "A",
|
||||||
|
Signal: telemetrytypes.SignalTraces,
|
||||||
|
Filter: &Filter{
|
||||||
|
Expression: "service.name = demo",
|
||||||
|
},
|
||||||
|
Aggregations: []MetricAggregation{
|
||||||
|
{
|
||||||
|
MetricName: "calls",
|
||||||
|
TimeAggregation: metrictypes.TimeAggregationRate,
|
||||||
|
SpaceAggregation: metrictypes.SpaceAggregationSum,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: QueryTypeBuilder,
|
||||||
|
Spec: QueryBuilderQuery[MetricAggregation]{
|
||||||
|
Name: "B",
|
||||||
|
Signal: telemetrytypes.SignalTraces,
|
||||||
|
Filter: &Filter{
|
||||||
|
Expression: "service.name = demo",
|
||||||
|
},
|
||||||
|
Aggregations: []MetricAggregation{
|
||||||
|
{
|
||||||
|
MetricName: "memory.usage",
|
||||||
|
TimeAggregation: metrictypes.TimeAggregationAvg,
|
||||||
|
SpaceAggregation: metrictypes.SpaceAggregationSum,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: QueryTypeBuilder,
|
||||||
|
Spec: QueryBuilderQuery[MetricAggregation]{
|
||||||
|
Name: "C",
|
||||||
|
Signal: telemetrytypes.SignalTraces,
|
||||||
|
Filter: &Filter{
|
||||||
|
Expression: "service.name = demo",
|
||||||
|
},
|
||||||
|
Aggregations: []MetricAggregation{
|
||||||
|
{
|
||||||
|
MetricName: "calls",
|
||||||
|
TimeAggregation: metrictypes.TimeAggregationIncrease,
|
||||||
|
SpaceAggregation: metrictypes.SpaceAggregationSum,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: QueryTypeBuilder,
|
||||||
|
Spec: QueryBuilderQuery[MetricAggregation]{
|
||||||
|
Name: "D",
|
||||||
|
Signal: telemetrytypes.SignalTraces,
|
||||||
|
Filter: &Filter{
|
||||||
|
Expression: "service.name = demo",
|
||||||
|
},
|
||||||
|
Aggregations: []MetricAggregation{
|
||||||
|
{
|
||||||
|
MetricName: "calls",
|
||||||
|
TimeAggregation: metrictypes.TimeAggregationCount,
|
||||||
|
SpaceAggregation: metrictypes.SpaceAggregationSum,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: map[string]bool{
|
||||||
|
"A": true,
|
||||||
|
"C": true,
|
||||||
|
"D": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "test min on logs - doesn't support zeroDefault",
|
name: "test min on logs - doesn't support zeroDefault",
|
||||||
CompositeQuery: CompositeQuery{
|
CompositeQuery: CompositeQuery{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user