mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 03:59:04 +08:00
feat: sanitize query and remove groupBy for list panel query (#5285)
This commit is contained in:
parent
faa1728b8c
commit
a4e98e565d
@ -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}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user