Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/grafana-data/src/types/dataFrameTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
export enum DataFrameType {
TimeSeriesWide = 'timeseries-wide',
TimeSeriesLong = 'timeseries-long',

/** @deprecated in favor of TimeSeriesMulti */
TimeSeriesMany = 'timeseries-many',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change in our public (typescript) API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question! @kylebrandt @ryantxu Is this supposed to be a breaking change or not? We need to consider the typescript API as Josh mentioned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is and isn't a breaking changes for plugins is tricky to define for the frontend. Typescript is not a runtime concern, so this will not break any existing plugins from running. But it could prevent them from being built.

From the outside, a simple way out would be to actually deprecate (rather than remove) the enum value with @deprecated jsdoc annotation, and then remove in grafana 10.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup deprecating not removing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add something to point to the replacement, e.g. "use TimeSeriesMulti instead", or "@deprecated in favor of TimeSeriesMulti"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the text @kylebrandt


TimeSeriesMulti = 'timeseries-multi',

/** Directory listing */
DirectoryListing = 'directory-listing',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -26,7 +26,7 @@ describe('Prepare time series transformer', () => {
];

const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};

expect(prepareTimeSeriesTransformer.transformer(config)(source)).toEqual([
Expand All @@ -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,
}),
Expand All @@ -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,
}),
Expand All @@ -72,7 +72,7 @@ describe('Prepare time series transformer', () => {
];

const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};

const frames = prepareTimeSeriesTransformer.transformer(config)(source);
Expand Down Expand Up @@ -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',
Expand All @@ -168,7 +168,7 @@ describe('Prepare time series transformer', () => {
];

const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};

expect(prepareTimeSeriesTransformer.transformer(config)(source)).toEqual([
Expand All @@ -181,7 +181,7 @@ describe('Prepare time series transformer', () => {
],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
toEquableDataFrame({
Expand All @@ -193,7 +193,7 @@ describe('Prepare time series transformer', () => {
],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
toEquableDataFrame({
Expand All @@ -205,7 +205,7 @@ describe('Prepare time series transformer', () => {
],
length: 6,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
]);
Expand All @@ -232,15 +232,15 @@ describe('Prepare time series transformer', () => {
];

const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};

expect(toEquableDataFrames(prepareTimeSeriesTransformer.transformer(config)(source))).toEqual(
toEquableDataFrames(
source.map((frame) => ({
...frame,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}))
)
Expand Down Expand Up @@ -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',
Expand All @@ -290,7 +290,7 @@ describe('Prepare time series transformer', () => {
];

const config: PrepareTimeSeriesOptions = {
format: timeSeriesFormat.TimeSeriesMany,
format: timeSeriesFormat.TimeSeriesMulti,
};

const frames = prepareTimeSeriesTransformer.transformer(config)(source);
Expand All @@ -304,7 +304,7 @@ describe('Prepare time series transformer', () => {
],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
}),
toEquableDataFrame({
Expand All @@ -316,7 +316,53 @@ describe('Prepare time series transformer', () => {
],
length: 3,
meta: {
type: DataFrameType.TimeSeriesMany,
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,
};

const frames = prepareTimeSeriesTransformer.transformer(config)(source);
expect(frames).toEqual([
toEquableDataFrame({
name: 'wants-to-be-many',
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: 'wants-to-be-many',
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,
},
}),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;
}
Expand Down Expand Up @@ -104,7 +106,7 @@ export function toTimeSeriesMany(data: DataFrame[]): DataFrame[] {
refId: frame.refId,
meta: {
...frame.meta,
type: DataFrameType.TimeSeriesMany,
type: DataFrameType.TimeSeriesMulti,
},
fields: [
{
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down