mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 20:38:59 +08:00
fix: update query range params (#2453)
This commit is contained in:
parent
d29dfa0751
commit
27c48674d4
@ -229,7 +229,6 @@ type FilterAttributeKeyResponse struct {
|
|||||||
type AttributeKeyType string
|
type AttributeKeyType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AttributeKeyTypeColumn AttributeKeyType = "column"
|
|
||||||
AttributeKeyTypeTag AttributeKeyType = "tag"
|
AttributeKeyTypeTag AttributeKeyType = "tag"
|
||||||
AttributeKeyTypeResource AttributeKeyType = "resource"
|
AttributeKeyTypeResource AttributeKeyType = "resource"
|
||||||
)
|
)
|
||||||
@ -238,6 +237,29 @@ type AttributeKey struct {
|
|||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
DataType AttributeKeyDataType `json:"dataType"`
|
DataType AttributeKeyDataType `json:"dataType"`
|
||||||
Type AttributeKeyType `json:"type"`
|
Type AttributeKeyType `json:"type"`
|
||||||
|
IsColumn bool `json:"isColumn"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a AttributeKey) Validate() error {
|
||||||
|
switch a.DataType {
|
||||||
|
case AttributeKeyDataTypeBool, AttributeKeyDataTypeNumber, AttributeKeyDataTypeString:
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid attribute dataType: %s", a.DataType)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch a.Type {
|
||||||
|
case AttributeKeyTypeResource, AttributeKeyTypeTag:
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid attribute type: %s", a.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.Key == "" {
|
||||||
|
return fmt.Errorf("key is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilterAttributeValueResponse struct {
|
type FilterAttributeValueResponse struct {
|
||||||
@ -345,9 +367,9 @@ type BuilderQuery struct {
|
|||||||
QueryName string `json:"queryName"`
|
QueryName string `json:"queryName"`
|
||||||
DataSource DataSource `json:"dataSource"`
|
DataSource DataSource `json:"dataSource"`
|
||||||
AggregateOperator AggregateOperator `json:"aggregateOperator"`
|
AggregateOperator AggregateOperator `json:"aggregateOperator"`
|
||||||
AggregateAttribute string `json:"aggregateAttribute,omitempty"`
|
AggregateAttribute AttributeKey `json:"aggregateAttribute,omitempty"`
|
||||||
Filters *FilterSet `json:"filters,omitempty"`
|
Filters *FilterSet `json:"filters,omitempty"`
|
||||||
GroupBy []string `json:"groupBy,omitempty"`
|
GroupBy []AttributeKey `json:"groupBy,omitempty"`
|
||||||
Expression string `json:"expression"`
|
Expression string `json:"expression"`
|
||||||
Disabled bool `json:"disabled"`
|
Disabled bool `json:"disabled"`
|
||||||
Having []Having `json:"having,omitempty"`
|
Having []Having `json:"having,omitempty"`
|
||||||
@ -356,7 +378,7 @@ type BuilderQuery struct {
|
|||||||
PageSize uint64 `json:"pageSize"`
|
PageSize uint64 `json:"pageSize"`
|
||||||
OrderBy []OrderBy `json:"orderBy,omitempty"`
|
OrderBy []OrderBy `json:"orderBy,omitempty"`
|
||||||
ReduceTo ReduceToOperator `json:"reduceTo,omitempty"`
|
ReduceTo ReduceToOperator `json:"reduceTo,omitempty"`
|
||||||
SelectColumns []string `json:"selectColumns,omitempty"`
|
SelectColumns []AttributeKey `json:"selectColumns,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BuilderQuery) Validate() error {
|
func (b *BuilderQuery) Validate() error {
|
||||||
@ -376,7 +398,7 @@ func (b *BuilderQuery) Validate() error {
|
|||||||
if err := b.AggregateOperator.Validate(); err != nil {
|
if err := b.AggregateOperator.Validate(); err != nil {
|
||||||
return fmt.Errorf("aggregate operator is invalid: %w", err)
|
return fmt.Errorf("aggregate operator is invalid: %w", err)
|
||||||
}
|
}
|
||||||
if b.AggregateAttribute == "" && b.AggregateOperator.RequireAttribute() {
|
if b.AggregateAttribute == (AttributeKey{}) && b.AggregateOperator.RequireAttribute() {
|
||||||
return fmt.Errorf("aggregate attribute is required")
|
return fmt.Errorf("aggregate attribute is required")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -388,11 +410,20 @@ func (b *BuilderQuery) Validate() error {
|
|||||||
}
|
}
|
||||||
if b.GroupBy != nil {
|
if b.GroupBy != nil {
|
||||||
for _, groupBy := range b.GroupBy {
|
for _, groupBy := range b.GroupBy {
|
||||||
if groupBy == "" {
|
if groupBy.Validate() != nil {
|
||||||
return fmt.Errorf("group by cannot be empty")
|
return fmt.Errorf("group by is invalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.SelectColumns != nil {
|
||||||
|
for _, selectColumn := range b.SelectColumns {
|
||||||
|
if selectColumn.Validate() != nil {
|
||||||
|
return fmt.Errorf("select column is invalid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if b.Expression == "" {
|
if b.Expression == "" {
|
||||||
return fmt.Errorf("expression is required")
|
return fmt.Errorf("expression is required")
|
||||||
}
|
}
|
||||||
@ -411,11 +442,16 @@ func (f *FilterSet) Validate() error {
|
|||||||
if f.Operator != "" && f.Operator != "AND" && f.Operator != "OR" {
|
if f.Operator != "" && f.Operator != "AND" && f.Operator != "OR" {
|
||||||
return fmt.Errorf("operator must be AND or OR")
|
return fmt.Errorf("operator must be AND or OR")
|
||||||
}
|
}
|
||||||
|
for _, item := range f.Items {
|
||||||
|
if err := item.Key.Validate(); err != nil {
|
||||||
|
return fmt.Errorf("filter item key is invalid: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilterItem struct {
|
type FilterItem struct {
|
||||||
Key string `json:"key"`
|
Key AttributeKey `json:"key"`
|
||||||
Value interface{} `json:"value"`
|
Value interface{} `json:"value"`
|
||||||
Operator string `json:"op"`
|
Operator string `json:"op"`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user