mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
fix: aggCondition issue in sum/gauge/histogram metrics (#662)
Ref: HDX-1455
This commit is contained in:
parent
385c9f3dfa
commit
29e8f37d00
3 changed files with 41 additions and 3 deletions
5
.changeset/olive-peaches-marry.md
Normal file
5
.changeset/olive-peaches-marry.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@hyperdx/common-utils": patch
|
||||
---
|
||||
|
||||
fix: aggCondition issue in sum/gauge/histogram metrics
|
||||
|
|
@ -41,7 +41,7 @@ exports[`renderChartConfig should generate sql for a single histogram metric 1`]
|
|||
SELECT *, cityHash64(mapConcat(ScopeAttributes, ResourceAttributes, Attributes)) AS AttributesHash,
|
||||
length(BucketCounts) as CountLength
|
||||
FROM default.otel_metrics_histogram)
|
||||
WHERE MetricName = 'http.server.duration'
|
||||
WHERE (TimeUnix >= fromUnixTimestamp64Milli(1739318400000) AND TimeUnix <= fromUnixTimestamp64Milli(1765670400000)) AND ((MetricName = 'http.server.duration'))
|
||||
ORDER BY Attributes, TimeUnix ASC
|
||||
),RawHist AS (
|
||||
SELECT *, toUInt64( 0.5 * arraySum(BucketRates)) AS Rank,
|
||||
|
|
|
|||
|
|
@ -867,6 +867,7 @@ async function translateMetricChartConfig(
|
|||
{
|
||||
..._select,
|
||||
valueExpression: 'LastValue',
|
||||
aggCondition: '', // clear up the condition since the where clause is already applied at the upstream CTE
|
||||
},
|
||||
],
|
||||
from: {
|
||||
|
|
@ -959,7 +960,13 @@ async function translateMetricChartConfig(
|
|||
`,
|
||||
},
|
||||
],
|
||||
select,
|
||||
select: [
|
||||
{
|
||||
..._select,
|
||||
valueExpression: 'Value',
|
||||
aggCondition: '', // clear up the condition since the where clause is already applied at the upstream CTE
|
||||
},
|
||||
],
|
||||
from: {
|
||||
databaseName: '',
|
||||
tableName: 'Bucketed',
|
||||
|
|
@ -977,6 +984,31 @@ async function translateMetricChartConfig(
|
|||
throw new Error('quantile must be specified for histogram metrics');
|
||||
}
|
||||
|
||||
// Render the where clause to limit data selection on the source CTE but also search forward/back one
|
||||
// bucket window to ensure that there is enough data to compute a reasonable value on the ends of the
|
||||
// series.
|
||||
const where = await renderWhere(
|
||||
{
|
||||
...chartConfig,
|
||||
from: {
|
||||
...from,
|
||||
tableName: metricTables[MetricsDataType.Histogram],
|
||||
},
|
||||
filters: [
|
||||
{
|
||||
type: 'sql',
|
||||
condition: `MetricName = '${metricName}'`,
|
||||
},
|
||||
],
|
||||
includedDataInterval:
|
||||
chartConfig.granularity === 'auto' &&
|
||||
Array.isArray(chartConfig.dateRange)
|
||||
? convertDateRangeToGranularityString(chartConfig.dateRange, 60)
|
||||
: chartConfig.granularity,
|
||||
},
|
||||
metadata,
|
||||
);
|
||||
|
||||
return {
|
||||
...restChartConfig,
|
||||
with: [
|
||||
|
|
@ -994,7 +1026,7 @@ async function translateMetricChartConfig(
|
|||
SELECT *, cityHash64(mapConcat(ScopeAttributes, ResourceAttributes, Attributes)) AS AttributesHash,
|
||||
length(BucketCounts) as CountLength
|
||||
FROM ${renderFrom({ from: { ...from, tableName: metricTables[MetricsDataType.Histogram] } })})
|
||||
WHERE MetricName = '${metricName}'
|
||||
WHERE ${where}
|
||||
ORDER BY Attributes, TimeUnix ASC
|
||||
`,
|
||||
},
|
||||
|
|
@ -1019,6 +1051,7 @@ async function translateMetricChartConfig(
|
|||
{
|
||||
..._selectRest,
|
||||
aggFn: 'sum',
|
||||
aggCondition: '', // clear up the condition since the where clause is already applied at the upstream CTE
|
||||
valueExpression: 'Rate',
|
||||
},
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue