Skip to content

Commit a762203

Browse files
authored
fix: metadata options not finding sum metrics due to broad of cache key (#837)
1 parent c60b975 commit a762203

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

.changeset/swift-eyes-perform.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
"@hyperdx/app": patch
4+
---
5+
6+
fix: metadata getAllKeyValues query key scoped to table now

packages/app/src/components/MetricNameSelect.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { Select } from '@mantine/core';
99

1010
import { useGetKeyValues } from '@/hooks/useMetadata';
11+
import { capitalizeFirstLetter } from '@/utils';
1112

1213
const MAX_METRIC_NAME_OPTIONS = 3000;
1314

@@ -128,7 +129,7 @@ export function MetricNameSelect({
128129
useMetricNames(metricSource);
129130

130131
const options = useMemo(() => {
131-
return [
132+
const metricsFromQuery = [
132133
...(gaugeMetrics?.map(metric => ({
133134
value: `${metric}${SEPARATOR}gauge`,
134135
label: `${metric} (Gauge)`,
@@ -142,6 +143,20 @@ export function MetricNameSelect({
142143
label: `${metric} (Sum)`,
143144
})) ?? []),
144145
];
146+
// if saved metric does not exist in the available options, assume it exists
147+
// and add it to options
148+
if (
149+
metricName &&
150+
!metricsFromQuery.find(
151+
metric => metric.value !== `${metricName}${SEPARATOR}${metricType}`,
152+
)
153+
) {
154+
metricsFromQuery.push({
155+
value: `${metricName}${SEPARATOR}${metricType}`,
156+
label: `${metricName} (${capitalizeFirstLetter(metricType)})`,
157+
});
158+
}
159+
return metricsFromQuery;
145160
}, [gaugeMetrics, histogramMetrics, sumMetrics]);
146161

147162
return (

packages/common-utils/src/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export class Metadata {
439439
disableRowLimit?: boolean;
440440
}) {
441441
return this.cache.getOrFetch(
442-
`${chartConfig.from.databaseName}.${keys.join(',')}.${chartConfig.dateRange.toString()}.${disableRowLimit}.values`,
442+
`${chartConfig.from.databaseName}.${chartConfig.from.tableName}.${keys.join(',')}.${chartConfig.dateRange.toString()}.${disableRowLimit}.values`,
443443
async () => {
444444
const sql = await renderChartConfig(
445445
{

0 commit comments

Comments
 (0)