fix: pull metrics name from supported type list (#303)

This commit is contained in:
Warren 2024-02-06 18:59:34 -08:00 committed by GitHub
parent b87c4d771b
commit 095ec0e0c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 16 deletions

View file

@ -0,0 +1,6 @@
---
'@hyperdx/api': patch
'@hyperdx/app': patch
---
fix: histogram AggFn values to be only valid ones (UI)

View file

@ -54,6 +54,7 @@ export enum MetricsDataType {
Gauge = 'Gauge',
Histogram = 'Histogram',
Sum = 'Sum',
// TODO: support 'Summary' and 'ExponentialHistogram'
}
export enum AggFn {
@ -674,13 +675,15 @@ export const getMetricsNames = async ({
data_type,
format('{} - {}', name, data_type) as name
FROM ??
WHERE (_timestamp_sort_key >= ? AND _timestamp_sort_key < ?)
WHERE data_type IN (?)
AND (_timestamp_sort_key >= ? AND _timestamp_sort_key < ?)
AND (_created_at >= fromUnixTimestamp64Milli(?) AND _created_at < fromUnixTimestamp64Milli(?))
GROUP BY name, data_type
ORDER BY name
`,
[
tableName,
Object.values(MetricsDataType),
msToBigIntNs(startTime),
msToBigIntNs(endTime),
startTime,

View file

@ -9,7 +9,7 @@ import api from './api';
import Checkbox from './Checkbox';
import MetricTagFilterInput from './MetricTagFilterInput';
import SearchInput from './SearchInput';
import type { AggFn, ChartSeries, SourceTable } from './types';
import { AggFn, ChartSeries, MetricsDataType, SourceTable } from './types';
import { NumberFormat } from './types';
import { legacyMetricNameToNameAndDataType } from './utils';
@ -38,16 +38,27 @@ export const AGG_FNS = [
{ value: 'count_distinct' as const, label: 'Count Distinct' },
];
export const METRIC_AGG_FNS = [
{ value: 'sum' as const, label: 'Sum' },
{ value: 'p99' as const, label: '99th Percentile' },
{ value: 'p95' as const, label: '95th Percentile' },
{ value: 'p90' as const, label: '90th Percentile' },
{ value: 'p50' as const, label: 'Median' },
{ value: 'avg' as const, label: 'Average' },
{ value: 'max' as const, label: 'Maximum' },
{ value: 'min' as const, label: 'Minimum' },
];
export const getMetricAggFns = (dataType: MetricsDataType) => {
if (dataType === MetricsDataType.Histogram) {
return [
{ value: 'p99' as const, label: '99th Percentile' },
{ value: 'p95' as const, label: '95th Percentile' },
{ value: 'p90' as const, label: '90th Percentile' },
{ value: 'p50' as const, label: 'Median' },
];
}
return [
{ value: 'sum' as const, label: 'Sum' },
{ value: 'p99' as const, label: '99th Percentile' },
{ value: 'p95' as const, label: '95th Percentile' },
{ value: 'p90' as const, label: '90th Percentile' },
{ value: 'p50' as const, label: 'Median' },
{ value: 'avg' as const, label: 'Average' },
{ value: 'max' as const, label: 'Maximum' },
{ value: 'min' as const, label: 'Minimum' },
];
};
export enum Granularity {
ThirtySecond = '30 second',
@ -583,6 +594,9 @@ export function ChartSeriesForm({
}
}
};
const metricAggFns = getMetricAggFns(
legacyMetricNameToNameAndDataType(field)?.dataType,
);
return (
<div>
@ -616,9 +630,9 @@ export function ChartSeriesForm({
/>
) : (
<Select
options={METRIC_AGG_FNS}
options={metricAggFns}
className="ds-select"
value={METRIC_AGG_FNS.find(
value={metricAggFns.find(
v => v.value === aggFn.replace('_rate', ''),
)}
onChange={opt => _setAggFn(opt?.value ?? 'sum')}
@ -920,6 +934,9 @@ export function ChartSeriesFormCompact({
}
}
};
const metricAggFns = getMetricAggFns(
legacyMetricNameToNameAndDataType(field)?.dataType,
);
return (
<div>
@ -944,9 +961,9 @@ export function ChartSeriesFormCompact({
/>
) : (
<Select
options={METRIC_AGG_FNS}
options={metricAggFns}
className="ds-select w-auto text-nowrap"
value={METRIC_AGG_FNS.find(
value={metricAggFns.find(
v => v.value === aggFn.replace('_rate', ''),
)}
onChange={opt => _setAggFn(opt?.value ?? 'sum')}