fix: handle 'filters' config (metrics) (#663)

Ref: HDX-1466
This commit is contained in:
Warren 2025-03-11 00:25:00 -07:00 committed by GitHub
parent 29e8f37d00
commit 9c5c2396fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"@hyperdx/common-utils": patch
---
fix: handle 'filters' config (metrics)

View file

@ -799,7 +799,7 @@ async function translateMetricChartConfig(
}
// assumes all the selects are from a single metric type, for now
const { select, from, ...restChartConfig } = chartConfig;
const { select, from, filters, where, ...restChartConfig } = chartConfig;
if (!select || !Array.isArray(select)) {
throw new Error('multi select or string select on metrics not supported');
}
@ -824,6 +824,7 @@ async function translateMetricChartConfig(
tableName: metricTables[MetricsDataType.Gauge],
},
filters: [
...(filters ?? []),
{
type: 'sql',
condition: `MetricName = '${metricName}'`,
@ -874,6 +875,7 @@ async function translateMetricChartConfig(
databaseName: '',
tableName: 'Bucketed',
},
where: '', // clear up the condition since the where clause is already applied at the upstream CTE
timestampValueExpression: timeBucketCol,
};
} else if (metricType === MetricsDataType.Sum && metricName) {
@ -899,6 +901,7 @@ async function translateMetricChartConfig(
tableName: metricTables[MetricsDataType.Gauge],
},
filters: [
...(filters ?? []),
{
type: 'sql',
condition: `MetricName = '${metricName}'`,
@ -971,6 +974,7 @@ async function translateMetricChartConfig(
databaseName: '',
tableName: 'Bucketed',
},
where: '', // clear up the condition since the where clause is already applied at the upstream CTE
timestampValueExpression: `\`${timeBucketCol}\``,
};
} else if (metricType === MetricsDataType.Histogram && metricName) {
@ -995,6 +999,7 @@ async function translateMetricChartConfig(
tableName: metricTables[MetricsDataType.Histogram],
},
filters: [
...(filters ?? []),
{
type: 'sql',
condition: `MetricName = '${metricName}'`,
@ -1059,6 +1064,7 @@ async function translateMetricChartConfig(
databaseName: '',
tableName: 'RawHist',
},
where: '', // clear up the condition since the where clause is already applied at the upstream CTE
};
}