mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 04:22:13 +08:00
Tempo: add support for sum_over_time metrics queries (#101545)
* feat: add sum_over_time to tempo metrics query regex * added a test to assert sum_over_time is interpret as traceql metric
This commit is contained in:
@ -128,7 +128,6 @@ func handleConversionError(ctxLogger log.Logger, span trace.Span, err error) (*b
|
||||
func (s *Service) performMetricsQuery(ctx context.Context, dsInfo *Datasource, model *dataquery.TempoQuery, query backend.DataQuery, span trace.Span) (*http.Response, []byte, error) {
|
||||
ctxLogger := s.logger.FromContext(ctx)
|
||||
request, err := s.createMetricsQuery(ctx, dsInfo, model, query.TimeRange.From.Unix(), query.TimeRange.To.Unix())
|
||||
|
||||
if err != nil {
|
||||
ctxLogger.Error("Failed to create request", "error", err, "function", logEntrypoint())
|
||||
span.RecordError(err)
|
||||
@ -202,6 +201,6 @@ func isInstantQuery(metricQueryType *dataquery.MetricsQueryType) bool {
|
||||
}
|
||||
|
||||
func isMetricsQuery(query string) bool {
|
||||
match, _ := regexp.MatchString("\\|\\s*(rate|count_over_time|avg_over_time|max_over_time|min_over_time|quantile_over_time|histogram_over_time|compare)\\s*\\(", query)
|
||||
match, _ := regexp.MatchString("\\|\\s*(rate|count_over_time|avg_over_time|sum_over_time|max_over_time|min_over_time|quantile_over_time|histogram_over_time|compare)\\s*\\(", query)
|
||||
return match
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ func TestCreateMetricsQuery_Success(t *testing.T) {
|
||||
assert.Equal(t, "http://tempo:3100/api/metrics/query_range?end=1625184000&exemplars=123&q=%7Battribute%3D%22value%22%7D&start=1625097600&step=14", req.URL.String())
|
||||
assert.Equal(t, "application/json", req.Header.Get("Accept"))
|
||||
}
|
||||
|
||||
func TestCreateMetricsQuery_OnlyQuery(t *testing.T) {
|
||||
logger := backend.NewLoggerWith("logger", "tsdb.tempo.test")
|
||||
service := &Service{
|
||||
@ -94,6 +95,11 @@ func TestQueryWithAvgOverTimeFunction_ReturnsTrue(t *testing.T) {
|
||||
assert.True(t, result)
|
||||
}
|
||||
|
||||
func TestQueryWithSumOverTimeFunction_ReturnsTrue(t *testing.T) {
|
||||
result := isMetricsQuery("{} | sum_over_time(foo)")
|
||||
assert.True(t, result)
|
||||
}
|
||||
|
||||
func TestQueryWithCountOverTimeFunction_ReturnsTrue(t *testing.T) {
|
||||
result := isMetricsQuery("{} | count_over_time(foo)")
|
||||
assert.True(t, result)
|
||||
|
Reference in New Issue
Block a user