mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 23:55:59 +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)}
|
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
|
// validate the request body
|
||||||
if err := validateQueryRangeParamsV3(queryRangeParams); err != nil {
|
if err := validateQueryRangeParamsV3(queryRangeParams); err != nil {
|
||||||
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: err}
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: err}
|
||||||
|
@ -428,6 +428,16 @@ func (c *CompositeQuery) EnabledQueries() int {
|
|||||||
return count
|
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 {
|
func (c *CompositeQuery) Validate() error {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return fmt.Errorf("composite query is required")
|
return fmt.Errorf("composite query is required")
|
||||||
@ -747,9 +757,9 @@ func (b *BuilderQuery) Validate(panelType PanelType) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if b.GroupBy != nil {
|
if b.GroupBy != nil {
|
||||||
if len(b.GroupBy) > 0 && panelType == PanelTypeList {
|
// if len(b.GroupBy) > 0 && panelType == PanelTypeList {
|
||||||
return fmt.Errorf("group by is not supported for list panel type")
|
// return fmt.Errorf("group by is not supported for list panel type")
|
||||||
}
|
// }
|
||||||
|
|
||||||
for _, groupBy := range b.GroupBy {
|
for _, groupBy := range b.GroupBy {
|
||||||
if err := groupBy.Validate(); err != nil {
|
if err := groupBy.Validate(); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user