mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-04 11:25:52 +08:00
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/smartystreets/assertions/should"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
"go.signoz.io/signoz/pkg/query-service/app/metrics"
|
|
"go.signoz.io/signoz/pkg/query-service/model"
|
|
)
|
|
|
|
func TestParseFilterSingleFilter(t *testing.T) {
|
|
Convey("TestParseFilterSingleFilter", t, func() {
|
|
postBody := []byte(`{
|
|
"op": "AND",
|
|
"items": [
|
|
{"key": "namespace", "value": "a", "op": "EQ"}
|
|
]
|
|
}`)
|
|
req, _ := http.NewRequest("POST", "", bytes.NewReader(postBody))
|
|
res, _ := parseFilterSet(req)
|
|
query, _ := metrics.BuildMetricsTimeSeriesFilterQuery(res, []string{}, "table", model.NOOP)
|
|
So(query, ShouldContainSubstring, "signoz_metrics.time_series_v2 WHERE metric_name = 'table' AND JSONExtractString(labels, 'namespace') = 'a'")
|
|
})
|
|
}
|
|
|
|
func TestParseFilterMultipleFilter(t *testing.T) {
|
|
Convey("TestParseFilterMultipleFilter", t, func() {
|
|
postBody := []byte(`{
|
|
"op": "AND",
|
|
"items": [
|
|
{"key": "namespace", "value": "a", "op": "EQ"},
|
|
{"key": "host", "value": ["host-1", "host-2"], "op": "IN"}
|
|
]
|
|
}`)
|
|
req, _ := http.NewRequest("POST", "", bytes.NewReader(postBody))
|
|
res, _ := parseFilterSet(req)
|
|
query, _ := metrics.BuildMetricsTimeSeriesFilterQuery(res, []string{}, "table", model.NOOP)
|
|
So(query, should.ContainSubstring, "JSONExtractString(labels, 'host') IN ['host-1','host-2']")
|
|
So(query, should.ContainSubstring, "JSONExtractString(labels, 'namespace') = 'a'")
|
|
})
|
|
}
|
|
|
|
func TestParseFilterNotSupportedOp(t *testing.T) {
|
|
Convey("TestParseFilterNotSupportedOp", t, func() {
|
|
postBody := []byte(`{
|
|
"op": "AND",
|
|
"items": [
|
|
{"key": "namespace", "value": "a", "op": "PO"}
|
|
]
|
|
}`)
|
|
req, _ := http.NewRequest("POST", "", bytes.NewReader(postBody))
|
|
res, _ := parseFilterSet(req)
|
|
_, err := metrics.BuildMetricsTimeSeriesFilterQuery(res, []string{}, "table", model.NOOP)
|
|
So(err, should.BeError, "unsupported operation")
|
|
})
|
|
}
|