Dataplane: Deprecate timeseries-many in favor of timeseries-multi (#59070)

* deprecate timeseries-many in favor of timeseries-multi

* deprecate timeseries-many, do not just remove it

* undo changes to jsonc files

* update deprecation message

* return TimeSeriesMulti for prepareTimeSeries transformer
This commit is contained in:
Brendan O'Handley
2022-12-01 15:27:31 -05:00
committed by GitHub
parent f0adc69ada
commit f9ef0eb414
4 changed files with 93 additions and 29 deletions

View File

@@ -20,9 +20,9 @@ const wideInfo = {
),
};
const manyInfo = {
const multiInfo = {
label: 'Multi-frame time series',
value: timeSeriesFormat.TimeSeriesMany,
value: timeSeriesFormat.TimeSeriesMulti,
description: 'Creates a new frame for each time/number pair',
info: (
<ul>
@@ -50,7 +50,7 @@ const longInfo = {
),
};
const formats: Array<SelectableValue<timeSeriesFormat>> = [wideInfo, manyInfo, longInfo];
const formats: Array<SelectableValue<timeSeriesFormat>> = [wideInfo, multiInfo, longInfo];
export function PrepareTimeSeriesEditor(props: TransformerUIProps<PrepareTimeSeriesOptions>): React.ReactElement {
const { options, onChange } = props;
@@ -73,7 +73,19 @@ export function PrepareTimeSeriesEditor(props: TransformerUIProps<PrepareTimeSer
<Select
width={35}
options={formats}
value={formats.find((v) => v.value === options.format) || formats[0]}
value={
formats.find((v) => {
// migrate previously selected timeSeriesMany to multi
if (
v.value === timeSeriesFormat.TimeSeriesMulti &&
options.format === timeSeriesFormat.TimeSeriesMany
) {
return true;
} else {
return v.value === options.format;
}
}) || formats[0]
}
onChange={onSelectFormat}
className="flex-grow-1"
/>

View File

@@ -12,7 +12,7 @@ import {
import { prepareTimeSeriesTransformer, PrepareTimeSeriesOptions, timeSeriesFormat } from './prepareTimeSeries';
describe('Prepare time series transformer', () => {
it('should transform wide to many', () => {
it('should transform wide to multi', () => {
const source = [
toDataFrame({
name: 'wide',
@@ -26,7 +26,7 @@ describe('Prepare time series transformer', () => {
];
const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};
expect(prepareTimeSeriesTransformer.transformer(config)(source)).toEqual([
@@ -38,7 +38,7 @@ describe('Prepare time series transformer', () => {
{ name: 'count', type: FieldType.number, values: [10, 20, 30, 40, 50, 60] },
],
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
length: 6,
}),
@@ -50,7 +50,7 @@ describe('Prepare time series transformer', () => {
{ name: 'more', type: FieldType.number, values: [2, 3, 4, 5, 6, 7] },
],
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
length: 6,
}),
@@ -72,7 +72,7 @@ describe('Prepare time series transformer', () => {
];
const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};
const frames = prepareTimeSeriesTransformer.transformer(config)(source);
@@ -146,7 +146,7 @@ describe('Prepare time series transformer', () => {
`);
});
it('should transform all wide to many when mixed', () => {
it('should transform all wide to multi when mixed', () => {
const source = [
toDataFrame({
name: 'wide',
@@ -168,7 +168,7 @@ describe('Prepare time series transformer', () => {
];
const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};
expect(prepareTimeSeriesTransformer.transformer(config)(source)).toEqual([
@@ -181,7 +181,7 @@ describe('Prepare time series transformer', () => {
],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
toEquableDataFrame({
@@ -193,7 +193,7 @@ describe('Prepare time series transformer', () => {
],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
toEquableDataFrame({
@@ -205,7 +205,7 @@ describe('Prepare time series transformer', () => {
],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
]);
@@ -232,7 +232,7 @@ describe('Prepare time series transformer', () => {
];
const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};
expect(toEquableDataFrames(prepareTimeSeriesTransformer.transformer(config)(source))).toEqual(
@@ -240,7 +240,7 @@ describe('Prepare time series transformer', () => {
source.map((frame) => ({
...frame,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}))
)
@@ -270,13 +270,13 @@ describe('Prepare time series transformer', () => {
];
const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};
expect(prepareTimeSeriesTransformer.transformer(config)(source)).toEqual([]);
});
it('should convert long to many', () => {
it('should convert long to multi', () => {
const source = [
toDataFrame({
name: 'long',
@@ -289,6 +289,52 @@ describe('Prepare time series transformer', () => {
}),
];
const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMulti,
};
const frames = prepareTimeSeriesTransformer.transformer(config)(source);
expect(frames).toEqual([
toEquableDataFrame({
name: 'long',
refId: 'X',
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
{ name: 'value', labels: { region: 'a' }, type: FieldType.number, values: [10, 30, 50] },
],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMulti,
},
}),
toEquableDataFrame({
name: 'long',
refId: 'X',
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
{ name: 'value', labels: { region: 'b' }, type: FieldType.number, values: [20, 40, 60] },
],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMulti,
},
}),
]);
});
it('should migrate many to multi and still convert correctly', () => {
const source = [
toDataFrame({
name: 'wants-to-be-many',
refId: 'X',
fields: [
{ name: 'time', type: FieldType.time, values: [1, 1, 2, 2, 3, 3] },
{ name: 'value', type: FieldType.number, values: [10, 20, 30, 40, 50, 60] },
{ name: 'region', type: FieldType.string, values: ['a', 'b', 'a', 'b', 'a', 'b'] },
],
}),
];
const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
};
@@ -296,7 +342,7 @@ describe('Prepare time series transformer', () => {
const frames = prepareTimeSeriesTransformer.transformer(config)(source);
expect(frames).toEqual([
toEquableDataFrame({
name: 'long',
name: 'wants-to-be-many',
refId: 'X',
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
@@ -304,11 +350,11 @@ describe('Prepare time series transformer', () => {
],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
toEquableDataFrame({
name: 'long',
name: 'wants-to-be-many',
refId: 'X',
fields: [
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
@@ -316,7 +362,7 @@ describe('Prepare time series transformer', () => {
],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
]);

View File

@@ -24,10 +24,12 @@ import { Labels } from 'app/types/unified-alerting-dto';
*
* @internal -- TBD
*/
export enum timeSeriesFormat {
TimeSeriesWide = 'wide', // [time,...values]
TimeSeriesMany = 'many', // All frames have [time,number]
TimeSeriesWide = 'wide',
TimeSeriesMany = 'many',
TimeSeriesLong = 'long',
TimeSeriesMulti = 'multi',
}
export type PrepareTimeSeriesOptions = {
@@ -37,7 +39,7 @@ export type PrepareTimeSeriesOptions = {
/**
* Convert to [][time,number]
*/
export function toTimeSeriesMany(data: DataFrame[]): DataFrame[] {
export function toTimeSeriesMulti(data: DataFrame[]): DataFrame[] {
if (!Array.isArray(data) || data.length === 0) {
return data;
}
@@ -104,7 +106,7 @@ export function toTimeSeriesMany(data: DataFrame[]): DataFrame[] {
refId: frame.refId,
meta: {
...frame.meta,
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
fields: [
{
@@ -126,7 +128,7 @@ export function toTimeSeriesMany(data: DataFrame[]): DataFrame[] {
refId: frame.refId,
meta: {
...frame.meta,
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
fields: [timeField, field],
length: frame.length,
@@ -291,8 +293,8 @@ export const prepareTimeSeriesTransformer: SynchronousDataTransformerInfo<Prepar
transformer: (options: PrepareTimeSeriesOptions) => {
const format = options?.format ?? timeSeriesFormat.TimeSeriesWide;
if (format === timeSeriesFormat.TimeSeriesMany) {
return toTimeSeriesMany;
if (format === timeSeriesFormat.TimeSeriesMany || timeSeriesFormat.TimeSeriesMulti) {
return toTimeSeriesMulti;
} else if (format === timeSeriesFormat.TimeSeriesLong) {
return toTimeSeriesLong;
}