revert: revert check for metric type without query range constraint

This commit is contained in:
Naman Verma
2026-03-11 17:09:21 +05:30
parent b453010075
commit 4e6fa6286b
3 changed files with 11 additions and 17 deletions

View File

@@ -382,7 +382,7 @@ func (q *querier) QueryRange(ctx context.Context, orgID valuer.UUID, req *qbtype
}
// TODO(srikanthccv): warn when the metric is missing
if spec.Aggregations[i].Temporality == metrictypes.Unknown {
spec.Aggregations[i].Temporality = metrictypes.Unspecified // is this needed?
spec.Aggregations[i].Temporality = metrictypes.Unspecified
}
if spec.Aggregations[i].MetricName != "" && spec.Aggregations[i].Type == metrictypes.UnspecifiedType {

View File

@@ -1735,6 +1735,8 @@ func (t *telemetryMetaStore) fetchMetricsTemporalityAndType(ctx context.Context,
temporalities := make(map[string][]metrictypes.Temporality)
types := make(map[string]metrictypes.Type)
adjustedStartTs, adjustedEndTs, tsTableName, _ := telemetrymetrics.WhichTSTableToUse(queryTimeRangeStartTs, queryTimeRangeEndTs, nil)
// Build query to fetch temporality for all metrics
// We use attr_string_value where attr_name = '__temporality__'
// Note: The columns are mixed in the current data - temporality column contains metric_name
@@ -1744,14 +1746,14 @@ func (t *telemetryMetaStore) fetchMetricsTemporalityAndType(ctx context.Context,
"temporality",
"any(type) AS type",
"any(is_monotonic) as is_monotonic",
"max(unix_milli) AS last_seen_at",
"min(unix_milli) AS first_seen_at",
).
From(t.metricsDBName + "." + telemetrymetrics.TimeseriesV41weekTableName)
From(t.metricsDBName + "." + tsTableName)
// Filter by metric names (in the temporality column due to data mix-up)
sb.Where(
sb.In("metric_name", metricNames),
sb.GTE("unix_milli", adjustedStartTs),
sb.LT("unix_milli", adjustedEndTs),
)
sb.GroupBy("metric_name", "temporality")
@@ -1772,23 +1774,16 @@ func (t *telemetryMetaStore) fetchMetricsTemporalityAndType(ctx context.Context,
var temporality metrictypes.Temporality
var metricType metrictypes.Type
var isMonotonic bool
var lastSeenAt int64
var firstSeenAt int64
if err := rows.Scan(&metricName, &temporality, &metricType, &isMonotonic, &lastSeenAt, &firstSeenAt); err != nil {
if err := rows.Scan(&metricName, &temporality, &metricType, &isMonotonic); err != nil {
return nil, nil, errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, "failed to scan temporality result")
}
// always pick the metric type, regardless of when it was seen
if metricType == metrictypes.SumType && !isMonotonic {
metricType = metrictypes.GaugeType
}
types[metricName] = metricType
// if the temporality was seen between the time range, only then consider it
if lastSeenAt < int64(queryTimeRangeStartTs) || firstSeenAt > int64(queryTimeRangeEndTs) {
continue
}
if temporality != metrictypes.Unknown {
temporalities[metricName] = append(temporalities[metricName], temporality)
}
if metricType == metrictypes.SumType && !isMonotonic {
metricType = metrictypes.GaugeType
}
types[metricName] = metricType
}
if err := rows.Err(); err != nil {
return nil, nil, errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, "error iterating over metrics temporality rows")

View File

@@ -299,7 +299,6 @@ func (b *MetricQueryStatementBuilder) buildTimeSeriesCTE(
sb.LTE("unix_milli", end),
)
// is this needed?
if query.Aggregations[0].Temporality != metrictypes.Multiple && query.Aggregations[0].Temporality != metrictypes.Unknown {
sb.Where(sb.ILike("temporality", query.Aggregations[0].Temporality.StringValue()))
}