count_distinct aggFn on metric tiles ignores valueExpression, always counts distinct metric Values
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- clickhouse, sql, typescript
Línea de trabajo
Comienza en packages/common-utils/src/core/renderChartConfig.ts, en translateMetricChartConfig, e inspecciona cómo se traducen los elementos de selección de gauge antes de la generación de SQL. Reproduce la configuración de métrica count_distinct del issue, conserva su valueExpression del atributo y verifica que la consulta generada cuente valores de atributo distintos en lugar de LastValue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug Description
When using count_distinct as the aggFn on a metric tile, the valueExpression is ignored. The generated SQL always counts distinct values of the metric's float Value column rather than the specified attribute expression.
Steps to Reproduce
- Create a dashboard tile with
displayType: "number"and a metric select usingcount_distinctwith avalueExpressionpointing to an attribute:{ "displayType": "number", "source": "Metrics", "select": [ { "aggFn": "count_distinct", "valueExpression": "Attributes['name']", "metricName": "argocd_app_info", "metricType": "gauge" } ] } - Observe the number displayed — for an info metric (where
Valueis always1.0), the tile shows1or2instead of the actual count of distinct attribute values.
Expected Behavior
The tile should display the count of distinct values of Attributes['name'] across all time series for the metric — i.e., the number of distinct applications reported by argocd_app_info.
Direct ClickHouse query gives the correct answer:
SELECT uniqExact(Attributes['name'])
FROM default.otel_metrics_gauge
WHERE MetricName = 'argocd_app_info'
AND TimeUnix >= now() - INTERVAL 1 HOUR
-- returns 53
Actual Behavior
The generated SQL uses count(DISTINCT LastValue) where LastValue = last_value(Value) — the gauge's numeric value — not the attribute expression:
-- Generated by HyperDX
...
Bucketed AS (
SELECT
...,
last_value(Value) AS LastValue, -- <-- always the float metric value
any(Attributes) AS Attributes
FROM Source
GROUP BY AttributesHash, __hdx_time_bucket2
)
SELECT count(DISTINCT LastValue) -- <-- counts distinct 1.0, 0.0, etc.
FROM Bucketed
Result: 2 (distinct float values) instead of 53 (distinct app names).
Root Cause
In packages/common-utils/src/core/renderChartConfig.ts, translateMetricChartConfig unconditionally overwrites valueExpression with 'LastValue' for gauge metrics before passing the select config to SQL generation:
select: [
{
..._select,
valueExpression: 'LastValue', // overwrites user-provided Attributes['name']
aggCondition: '',
},
]
The original valueExpression from the user config is never used in metric query translation.
Additional Context
- The zod schema (
externalDashboardSelectItemSchemainpackages/api/src/utils/zod.ts) accepts and even requiresvalueExpressionfor non-countaggFns on metrics — so the intent to support this exists, but the query translator doesn't honour it. - The UI currently has no input for
valueExpressionon metric tiles, which makes sense given it's ignored — but fixing the translator would enable useful aggregations like counting distinct label values. - Confirmed present in v2.27.0. No prior issue or fix found.
Suggested Fix
For count_distinct (and potentially other aggFns where valueExpression refers to an attribute), use the user-provided expression instead of hardcoding 'LastValue':
// In translateMetricChartConfig for gauge metrics:
const effectiveValueExpression =
_select.aggFn === 'count_distinct' && _select.valueExpression
? _select.valueExpression
: 'LastValue';
select: [
{
..._select,
valueExpression: effectiveValueExpression,
aggCondition: '',
},
]
- Lenguaje dominante
- TypeScript
- Estrellas
- 10.1k
- Forks
- 527
- Merge medio
- 1 d 20 h
- PR fusionados (30 d)
- 186
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ClickHouse/ClickStack
-
external
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ClickHouse/ClickStack#3761 ·
Los mantenedores suelen responder en 1 día
-
Metric chart with aggFn increase and a multi-column group-by fails: toString() gets several argumentsPosiblemente ocupada @CG-5228 la tomó hace 26 días. Abiertoexternal
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ClickHouse/ClickStack#3477 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Slack notifications for inline alerts fail when the chart-explorer link passes Slack's 3000-character block limitPosiblemente ocupada @Tyagiquamar la tomó hace 27 días. Abiertoalerting bug external
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ClickHouse/ClickStack#3452 ·
Los mantenedores suelen responder en 1 día
-
check-alerts worker: 13 error spans (mongodb.create, NamespaceExists) every minute because mongoose autoCreate is still onQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertobug external Needs Feedback
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ClickHouse/ClickStack#3308 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
enhancement Needs Feedback
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
ClickHouse/ClickStack#3687 ·
Los mantenedores suelen responder en 1 día
Todos los issues de ClickHouse/ClickStack
Issues similares
-
Add: GTrekkerAbiertocheck:passed streams:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
area: ui Bug Payload OSS
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
payloadcms/payload#19839 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
fix(auth): add the email OTP verification step to Pollar loginPosiblemente ocupada @akansnoro la tomó hoy. AbiertoStellar Wave
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
safetrustcr/dApp-SafeTrust#584 · 10 comentarios ·
Los mantenedores suelen responder en 1 día
-
The manager preset saves launch definitions without the required file and digest pairPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día