mirror of
https://github.com/hanzoai/o11y.git
synced 2026-11-02 14:03:38 +00:00
Full rebrand of the SigNoz observability platform: - Go module: github.com/SigNoz/signoz → github.com/hanzoai/o11y - Frontend: @signozhq/* → @hanzo/o11y-*, posthog-js → @hanzo/insights - Docker: signoz/* → ghcr.io/hanzoai/o11y* - ClickHouse → Hanzo Datastore (hanzoai/datastore) - Env vars: SIGNOZ_* → HANZO_* - DB tables: signoz_* → o11y_* - All branding, URLs, docs updated - 2172 files changed
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package cumulative
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/o11y/pkg/query-service/app/metrics/v4/helpers"
|
|
v3 "github.com/hanzoai/o11y/pkg/query-service/model/v3"
|
|
)
|
|
|
|
// PrepareMetricQueryCumulativeTable prepares the query to be used for fetching metrics
|
|
func PrepareMetricQueryCumulativeTable(start, end, step int64, mq *v3.BuilderQuery) (string, error) {
|
|
var query string
|
|
|
|
temporalAggSubQuery, err := prepareTimeAggregationSubQuery(start, end, step, mq)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
groupBy := helpers.GroupingSetsByAttributeKeyTags(mq.GroupBy...)
|
|
orderBy := helpers.OrderByAttributeKeyTags(mq.OrderBy, mq.GroupBy)
|
|
selectLabels := helpers.GroupByAttributeKeyTags(mq.GroupBy...)
|
|
|
|
valueFilter := " WHERE isNaN(per_series_value) = 0"
|
|
if mq.MetricValueFilter != nil {
|
|
valueFilter += fmt.Sprintf(" AND per_series_value = %f", mq.MetricValueFilter.Value)
|
|
}
|
|
|
|
queryTmpl :=
|
|
"SELECT %s," +
|
|
" %s as value" +
|
|
" FROM (%s)" +
|
|
valueFilter +
|
|
" GROUP BY %s" +
|
|
" ORDER BY %s"
|
|
|
|
switch mq.SpaceAggregation {
|
|
case v3.SpaceAggregationAvg:
|
|
op := "avg(per_series_value)"
|
|
query = fmt.Sprintf(queryTmpl, selectLabels, op, temporalAggSubQuery, groupBy, orderBy)
|
|
case v3.SpaceAggregationSum:
|
|
op := "sum(per_series_value)"
|
|
query = fmt.Sprintf(queryTmpl, selectLabels, op, temporalAggSubQuery, groupBy, orderBy)
|
|
case v3.SpaceAggregationMin:
|
|
op := "min(per_series_value)"
|
|
query = fmt.Sprintf(queryTmpl, selectLabels, op, temporalAggSubQuery, groupBy, orderBy)
|
|
case v3.SpaceAggregationMax:
|
|
op := "max(per_series_value)"
|
|
query = fmt.Sprintf(queryTmpl, selectLabels, op, temporalAggSubQuery, groupBy, orderBy)
|
|
case v3.SpaceAggregationCount:
|
|
op := "count(per_series_value)"
|
|
query = fmt.Sprintf(queryTmpl, selectLabels, op, temporalAggSubQuery, groupBy, orderBy)
|
|
}
|
|
|
|
return query, nil
|
|
}
|