mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-04 11:25:52 +08:00

* Queryrange params tests * review suggestions, quantile, simple metric filter and some refactoring * Add value type support * Add supprot for re2 regex, refactor, update tests and other changes * chore: update govaluate dep to signoz/govaluate * chore: add name to grouping * chore: add support for NOOP * fix: make result format compatible with prom HTTP API * chore: update clickhouse server and update query builder to use new schema * chore: use metric_name in auto suggest APIs * chore: add reduce operator and new aggregate functions * chore: add support for not like op * chore: fix the dip at the end for incomplete time range * chore: rounddown the end to exclude the incomplete collection
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package parser
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"go.signoz.io/query-service/app/metrics"
|
|
"go.signoz.io/query-service/model"
|
|
)
|
|
|
|
func validateQueryRangeParamsV2(qp *model.QueryRangeParamsV2) error {
|
|
var errs []error
|
|
if !(qp.DataSource >= model.METRICS && qp.DataSource <= model.LOGS) {
|
|
errs = append(errs, fmt.Errorf("unsupported data source"))
|
|
}
|
|
if !(qp.CompositeMetricQuery.QueryType >= model.QUERY_BUILDER && qp.CompositeMetricQuery.QueryType <= model.PROM) {
|
|
errs = append(errs, fmt.Errorf("unsupported query type"))
|
|
}
|
|
if !(qp.CompositeMetricQuery.PanelType >= model.TIME_SERIES && qp.CompositeMetricQuery.PanelType <= model.QUERY_VALUE) {
|
|
errs = append(errs, fmt.Errorf("unsupported panel type"))
|
|
}
|
|
if len(errs) != 0 {
|
|
return fmt.Errorf("one or more errors found : %s", metrics.FormatErrs(errs, ","))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ParseMetricQueryRangeParams(r *http.Request) (*model.QueryRangeParamsV2, *model.ApiError) {
|
|
|
|
var postData *model.QueryRangeParamsV2
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&postData); err != nil {
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: err}
|
|
}
|
|
if err := validateQueryRangeParamsV2(postData); err != nil {
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: err}
|
|
}
|
|
|
|
return postData, nil
|
|
}
|
|
|
|
func ParseMetricAutocompleteTagParams(r *http.Request) (*model.MetricAutocompleteTagParams, *model.ApiError) {
|
|
|
|
metricName := r.URL.Query().Get("metricName")
|
|
if len(metricName) == 0 {
|
|
err := fmt.Errorf("metricName not present in params")
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: err}
|
|
}
|
|
|
|
tagsStr := r.URL.Query().Get("tags")
|
|
// fmt.Println(tagsStr)
|
|
|
|
// parsing tags
|
|
var tags map[string]string
|
|
if tagsStr != "" && len(tagsStr) != 0 {
|
|
|
|
err := json.Unmarshal([]byte(tagsStr), &tags)
|
|
if err != nil {
|
|
return nil, &model.ApiError{Typ: model.ErrorBadData, Err: fmt.Errorf("unable to parse tags in params: %v", err)}
|
|
}
|
|
}
|
|
|
|
matchText := r.URL.Query().Get("match")
|
|
|
|
tagKey := r.URL.Query().Get("tagKey")
|
|
|
|
metricAutocompleteTagParams := &model.MetricAutocompleteTagParams{
|
|
MetricName: metricName,
|
|
MetricTags: tags,
|
|
Match: matchText,
|
|
TagKey: tagKey,
|
|
}
|
|
|
|
return metricAutocompleteTagParams, nil
|
|
}
|