Skip to content

Commit 9c5c239

Browse files
authored
fix: handle 'filters' config (metrics) (#663)
Ref: HDX-1466
1 parent 29e8f37 commit 9c5c239

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/forty-mails-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
---
4+
5+
fix: handle 'filters' config (metrics)

packages/common-utils/src/renderChartConfig.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ async function translateMetricChartConfig(
799799
}
800800

801801
// assumes all the selects are from a single metric type, for now
802-
const { select, from, ...restChartConfig } = chartConfig;
802+
const { select, from, filters, where, ...restChartConfig } = chartConfig;
803803
if (!select || !Array.isArray(select)) {
804804
throw new Error('multi select or string select on metrics not supported');
805805
}
@@ -824,6 +824,7 @@ async function translateMetricChartConfig(
824824
tableName: metricTables[MetricsDataType.Gauge],
825825
},
826826
filters: [
827+
...(filters ?? []),
827828
{
828829
type: 'sql',
829830
condition: `MetricName = '${metricName}'`,
@@ -874,6 +875,7 @@ async function translateMetricChartConfig(
874875
databaseName: '',
875876
tableName: 'Bucketed',
876877
},
878+
where: '', // clear up the condition since the where clause is already applied at the upstream CTE
877879
timestampValueExpression: timeBucketCol,
878880
};
879881
} else if (metricType === MetricsDataType.Sum && metricName) {
@@ -899,6 +901,7 @@ async function translateMetricChartConfig(
899901
tableName: metricTables[MetricsDataType.Gauge],
900902
},
901903
filters: [
904+
...(filters ?? []),
902905
{
903906
type: 'sql',
904907
condition: `MetricName = '${metricName}'`,
@@ -971,6 +974,7 @@ async function translateMetricChartConfig(
971974
databaseName: '',
972975
tableName: 'Bucketed',
973976
},
977+
where: '', // clear up the condition since the where clause is already applied at the upstream CTE
974978
timestampValueExpression: `\`${timeBucketCol}\``,
975979
};
976980
} else if (metricType === MetricsDataType.Histogram && metricName) {
@@ -995,6 +999,7 @@ async function translateMetricChartConfig(
995999
tableName: metricTables[MetricsDataType.Histogram],
9961000
},
9971001
filters: [
1002+
...(filters ?? []),
9981003
{
9991004
type: 'sql',
10001005
condition: `MetricName = '${metricName}'`,
@@ -1059,6 +1064,7 @@ async function translateMetricChartConfig(
10591064
databaseName: '',
10601065
tableName: 'RawHist',
10611066
},
1067+
where: '', // clear up the condition since the where clause is already applied at the upstream CTE
10621068
};
10631069
}
10641070

0 commit comments

Comments
 (0)