diff --git a/pkg/query-service/model/v3/v3.go b/pkg/query-service/model/v3/v3.go new file mode 100644 index 0000000000..fc9b72075b --- /dev/null +++ b/pkg/query-service/model/v3/v3.go @@ -0,0 +1,240 @@ +package v3 + +import "time" + +type DataSource string + +const ( + DataSourceTraces DataSource = "traces" + DataSourceLogs DataSource = "logs" + DataSourceMetrics DataSource = "metrics" +) + +type AggregateOperator string + +const ( + AggregateOperatorNoOp AggregateOperator = "noop" + AggregateOpeatorCount AggregateOperator = "count" + AggregateOperatorCountDistinct AggregateOperator = "count_distinct" + AggregateOperatorSum AggregateOperator = "sum" + AggregateOperatorAvg AggregateOperator = "avg" + AggregateOperatorMin AggregateOperator = "min" + AggregateOperatorMax AggregateOperator = "max" + AggregateOperatorP05 AggregateOperator = "p05" + AggregateOperatorP10 AggregateOperator = "p10" + AggregateOperatorP20 AggregateOperator = "p20" + AggregateOperatorP25 AggregateOperator = "p25" + AggregateOperatorP50 AggregateOperator = "p50" + AggregateOperatorP75 AggregateOperator = "p75" + AggregateOperatorP90 AggregateOperator = "p90" + AggregateOperatorP95 AggregateOperator = "p95" + AggregateOperatorP99 AggregateOperator = "p99" + AggregateOperatorRate AggregateOperator = "rate" + AggregateOperatorSumRate AggregateOperator = "sum_rate" + AggregateOperatorAvgRate AggregateOperator = "avg_rate" + AggregateOperatorMinRate AggregateOperator = "min_rate" + AggregateOperatorMaxRate AggregateOperator = "max_rate" + AggregateOperatorRateSum AggregateOperator = "rate_sum" + AggregateOperatorRateAvg AggregateOperator = "rate_avg" + AggregateOperatorRateMin AggregateOperator = "rate_min" + AggregateOperatorRateMax AggregateOperator = "rate_max" + AggregateOperatorHistQuant50 AggregateOperator = "hist_quantile_50" + AggregateOperatorHistQuant75 AggregateOperator = "hist_quantile_75" + AggregateOperatorHistQuant90 AggregateOperator = "hist_quantile_90" + AggregateOperatorHistQuant95 AggregateOperator = "hist_quantile_95" + AggregateOperatorHistQuant99 AggregateOperator = "hist_quantile_99" +) + +type ReduceToOperator string + +const ( + ReduceToOperatorLast ReduceToOperator = "last" + ReduceToOperatorSum ReduceToOperator = "sum" + ReduceToOperatorAvg ReduceToOperator = "avg" + ReduceToOperatorMin ReduceToOperator = "min" + ReduceToOperatorMax ReduceToOperator = "max" +) + +type QueryType string + +const ( + QueryTypeBuilder QueryType = "builder" + QueryTypeClickHouseSQL QueryType = "clickhouse_sql" + QueryTypePromQL QueryType = "promql" +) + +type PanelType string + +const ( + PanelTypeValue PanelType = "value" + PanelTypeGraph PanelType = "graph" + PanelTypeTable PanelType = "table" + PanelTypeList PanelType = "list" +) + +// AggregateAttributeRequest is a request to fetch possible attribute keys +// for a selected aggregate operator and search text. +// The context of the selected aggregate operator is used as the +// type of the attribute key is different for different aggregate operators. +// For example, for the aggregate operator "avg" the attribute value type must be +// a number +type AggregateAttributeRequest struct { + DataSource DataSource `json:"dataSource"` + Operator AggregateOperator `json:"aggregateOperator"` + SearchText string `json:"searchText"` + Limit int `json:"limit"` +} + +type TagType string + +const ( + TagTypeColumn TagType = "column" + TagTypeTag TagType = "tag" + TagTypeResource TagType = "resource" +) + +// FilterAttributeKeyRequest is a request to fetch possible attribute keys +// for a selected aggregate operator and aggregate attribute and search text. +type FilterAttributeKeyRequest struct { + DataSource DataSource `json:"dataSource"` + AggregateOperator AggregateOperator `json:"aggregateOperator"` + AggregateAttribute string `json:"aggregateAttribute"` + TagType TagType `json:"tagType"` + SearchText string `json:"searchText"` + Limit int `json:"limit"` +} + +type FilterAttributeKeyDataType string + +const ( + FilterAttributeKeyDataTypeString FilterAttributeKeyDataType = "string" + FilterAttributeKeyDataTypeNumber FilterAttributeKeyDataType = "number" + FilterAttributeKeyDataTypeBool FilterAttributeKeyDataType = "bool" +) + +// FilterAttributeValueRequest is a request to fetch possible attribute values +// for a selected aggregate operator, aggregate attribute, filter attribute key +// and search text. +type FilterAttributeValueRequest struct { + DataSource DataSource `json:"dataSource"` + AggregateOperator AggregateOperator `json:"aggregateOperator"` + AggregateAttribute string `json:"aggregateAttribute"` + FilterAttributeKey string `json:"filterAttributeKey"` + FilterAttributeKeyDataType FilterAttributeKeyDataType `json:"filterAttributeKeyDataType"` + TagType TagType `json:"tagType"` + SearchText string `json:"searchText"` + Limit int `json:"limit"` +} + +type AggregateAttributeResponse struct { + AttributeKeys []AttributeKey `json:"attributeKeys"` +} + +type FilterAttributeKeyResponse struct { + AttributeKeys []AttributeKey `json:"attributeKeys"` +} + +type AttributeKey struct { + Key string `json:"key"` + DataType string `json:"dataType"` + Type string `json:"type"` // "column" or "tag"/"attr"/"attribute" or "resource"? +} + +type FilterAttributeValueResponse struct { + StringAttributeValues []string `json:"stringAttributeValues"` + NumberAttributeValues []interface{} `json:"numberAttributeValues"` + BoolAttributeValues []bool `json:"boolAttributeValues"` +} + +type QueryRangeParamsV3 struct { + Start int64 `json:"start"` + End int64 `json:"end"` + Step int64 `json:"step"` + CompositeQuery *CompositeQuery `json:"compositeQuery"` + Variables map[string]interface{} `json:"variables,omitempty"` +} + +type PromQuery struct { + Query string `json:"query"` + Stats string `json:"stats,omitempty"` + Disabled bool `json:"disabled"` +} + +type ClickHouseQuery struct { + Query string `json:"query"` + Disabled bool `json:"disabled"` +} + +type CompositeQuery struct { + BuilderQueries map[string]*BuilderQuery `json:"builderQueries,omitempty"` + ClickHouseQueries map[string]*ClickHouseQuery `json:"chQueries,omitempty"` + PromQueries map[string]*PromQuery `json:"promQueries,omitempty"` + PanelType PanelType `json:"panelType"` + QueryType QueryType `json:"queryType"` +} + +type BuilderQuery struct { + QueryName string `json:"queryName"` + DataSource DataSource `json:"dataSource"` + AggregateOperator AggregateOperator `json:"aggregateOperator"` + AggregateAttribute string `json:"aggregateAttribute,omitempty"` + Filters *FilterSet `json:"filters,omitempty"` + GroupBy []string `json:"groupBy,omitempty"` + Expression string `json:"expression"` + Disabled bool `json:"disabled"` + Having []Having `json:"having,omitempty"` + Limit uint64 `json:"limit"` + Offset uint64 `json:"offset"` + PageSize uint64 `json:"pageSize"` + OrderBy []OrderBy `json:"orderBy,omitempty"` + ReduceTo ReduceToOperator `json:"reduceTo,omitempty"` + SelectColumns []string `json:"selectColumns,omitempty"` +} + +type FilterSet struct { + Operator string `json:"op,omitempty"` + Items []FilterItem `json:"items"` +} + +type FilterItem struct { + Key string `json:"key"` + Value interface{} `json:"value"` + Operator string `json:"op"` +} + +type OrderBy struct { + ColumnName string `json:"columnName"` + Order string `json:"order"` +} + +type Having struct { + ColumnName string `json:"columnName"` + Operator string `json:"operator"` + Value interface{} `json:"value"` +} + +type QueryRangeResponse struct { + ResultType string `json:"resultType"` + Result []*Result `json:"result"` +} + +type Result struct { + QueryName string `json:"queryName"` + Series *Series `json:"series"` + List []*Row `json:"list"` +} + +type Series struct { + Labels map[string]string `json:"labels"` + Points []Point `json:"values"` +} + +type Row struct { + Timestamp time.Time `json:"timestamp"` + Data map[string]string `json:"data"` +} + +type Point struct { + Timestamp int64 `json:"timestamp"` + Value float64 `json:"value"` +}