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

This commit is contained in:
Nityananda Gohain 2024-06-19 15:40:34 +05:30 committed by GitHub
parent faa1728b8c
commit a4e98e565d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -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}

View File

@ -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 {