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.

feat: sanitize query and remove groupBy for list panel query (#5285)

Nityananda Gohaina4e98e565d3d
diff --git a/pkg/query-service/app/parser.go b/pkg/query-service/app/parser.go
index d976fd17b2..47da531d0b 100644
--- a/pkg/query-service/app/parser.go
+++ b/pkg/query-service/app/parser.go
@@ -958,6 +958,9 @@ func ParseQueryRangeParams(r *http.Request) (*v3.QueryRangeParamsV3, *model.ApiE
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("cannot parse the request body: %v", err)}
}
+ // sanitize the request body
+ queryRangeParams.CompositeQuery.Sanitize()
+
// validate the request body
if err := validateQueryRangeParamsV3(queryRangeParams); err != nil {
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: err}
diff --git a/pkg/query-service/model/v3/v3.go b/pkg/query-service/model/v3/v3.go
index 61272ddb2d..2a12c8e1fa 100644
--- a/pkg/query-service/model/v3/v3.go
+++ b/pkg/query-service/model/v3/v3.go
@@ -428,6 +428,16 @@ func (c *CompositeQuery) EnabledQueries() int {
return count
}
+func (c *CompositeQuery) Sanitize() {
+ // remove groupBy for queries with list panel type
+ for _, query := range c.BuilderQueries {
+ if len(query.GroupBy) > 0 && c.PanelType == PanelTypeList {
+ query.GroupBy = []AttributeKey{}
+ }
+ }
+
+}
+
func (c *CompositeQuery) Validate() error {
if c == nil {
return fmt.Errorf("composite query is required")
@@ -747,9 +757,9 @@ func (b *BuilderQuery) Validate(panelType PanelType) error {
}
}
if b.GroupBy != nil {
- if len(b.GroupBy) > 0 && panelType == PanelTypeList {
- return fmt.Errorf("group by is not supported for list panel type")
- }
+ // if len(b.GroupBy) > 0 && panelType == PanelTypeList {
+ // return fmt.Errorf("group by is not supported for list panel type")
+ // }
for _, groupBy := range b.GroupBy {
if err := groupBy.Validate(); err != nil {