mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Use uuid v4 as an identifier instead of Date.now() (#27178)
This commit is contained in:
parent
c5a7afce44
commit
7121d1e63f
@ -1,3 +1,4 @@
|
|||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { DashboardTimeRangeConfig, setDashboardTimeRange } from './setDashboardTimeRange';
|
import { DashboardTimeRangeConfig, setDashboardTimeRange } from './setDashboardTimeRange';
|
||||||
import { DeleteDashboardConfig } from './deleteDashboard';
|
import { DeleteDashboardConfig } from './deleteDashboard';
|
||||||
import { e2e } from '../index';
|
import { e2e } from '../index';
|
||||||
@ -31,7 +32,7 @@ export const addDashboard = (config?: Partial<AddDashboardConfig>): any => {
|
|||||||
to: '2020-01-01 06:00:00',
|
to: '2020-01-01 06:00:00',
|
||||||
},
|
},
|
||||||
timezone: 'Coordinated Universal Time',
|
timezone: 'Coordinated Universal Time',
|
||||||
title: `e2e-${Date.now()}`,
|
title: `e2e-${uuidv4()}`,
|
||||||
variables: [],
|
variables: [],
|
||||||
...config,
|
...config,
|
||||||
} as AddDashboardConfig;
|
} as AddDashboardConfig;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { DeleteDataSourceConfig } from './deleteDataSource';
|
import { DeleteDataSourceConfig } from './deleteDataSource';
|
||||||
import { e2e } from '../index';
|
import { e2e } from '../index';
|
||||||
import { fromBaseUrl, getDataSourceId } from '../support/url';
|
import { fromBaseUrl, getDataSourceId } from '../support/url';
|
||||||
@ -24,7 +25,7 @@ export const addDataSource = (config?: Partial<AddDataSourceConfig>): any => {
|
|||||||
checkHealth: false,
|
checkHealth: false,
|
||||||
expectedAlertMessage: 'Data source is working',
|
expectedAlertMessage: 'Data source is working',
|
||||||
form: () => {},
|
form: () => {},
|
||||||
name: `e2e-${Date.now()}`,
|
name: `e2e-${uuidv4()}`,
|
||||||
skipTlsVerify: false,
|
skipTlsVerify: false,
|
||||||
type: 'TestData DB',
|
type: 'TestData DB',
|
||||||
...config,
|
...config,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { configurePanel, ConfigurePanelConfig } from './configurePanel';
|
import { configurePanel, ConfigurePanelConfig } from './configurePanel';
|
||||||
import { getScenarioContext } from '../support/scenarioContext';
|
import { getScenarioContext } from '../support/scenarioContext';
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ export const addPanel = (config?: Partial<AddPanelConfig>): any =>
|
|||||||
configurePanel(
|
configurePanel(
|
||||||
{
|
{
|
||||||
dataSourceName: lastAddedDataSource,
|
dataSourceName: lastAddedDataSource,
|
||||||
panelTitle: `e2e-${Date.now()}`,
|
panelTitle: `e2e-${uuidv4()}`,
|
||||||
visualizationName: 'Table',
|
visualizationName: 'Table',
|
||||||
...config,
|
...config,
|
||||||
} as AddPanelConfig,
|
} as AddPanelConfig,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Plugin } from '@grafana/slate-react';
|
import { Plugin } from '@grafana/slate-react';
|
||||||
import { Editor as CoreEditor, Annotation } from 'slate';
|
import { Editor as CoreEditor, Annotation } from 'slate';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
const BRACES: any = {
|
const BRACES: any = {
|
||||||
'[': ']',
|
'[': ']',
|
||||||
@ -43,7 +44,7 @@ export function BracesPlugin(): Plugin {
|
|||||||
keyEvent.preventDefault();
|
keyEvent.preventDefault();
|
||||||
const complement = BRACES[keyEvent.key];
|
const complement = BRACES[keyEvent.key];
|
||||||
const matchAnnotation = {
|
const matchAnnotation = {
|
||||||
key: `${MATCH_MARK}-${Date.now()}`,
|
key: `${MATCH_MARK}-${uuidv4()}`,
|
||||||
type: `${MATCH_MARK}-${complement}`,
|
type: `${MATCH_MARK}-${complement}`,
|
||||||
anchor: {
|
anchor: {
|
||||||
key: startKey,
|
key: startKey,
|
||||||
|
@ -4,7 +4,7 @@ import { Alert } from '@grafana/ui';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
appNotification: AppNotification;
|
appNotification: AppNotification;
|
||||||
onClearNotification: (id: number) => void;
|
onClearNotification: (id: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AppNotificationItem extends Component<Props> {
|
export default class AppNotificationItem extends Component<Props> {
|
||||||
|
@ -27,7 +27,7 @@ export class AppNotificationList extends PureComponent<Props> {
|
|||||||
appEvents.on(AppEvents.alertError, payload => notifyApp(createErrorNotification(...payload)));
|
appEvents.on(AppEvents.alertError, payload => notifyApp(createErrorNotification(...payload)));
|
||||||
}
|
}
|
||||||
|
|
||||||
onClearAppNotification = (id: number) => {
|
onClearAppNotification = (id: string) => {
|
||||||
this.props.clearAppNotification(id);
|
this.props.clearAppNotification(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { AppNotification, AppNotificationSeverity, AppNotificationTimeout } from 'app/types';
|
import { AppNotification, AppNotificationSeverity, AppNotificationTimeout } from 'app/types';
|
||||||
import { getMessageFromError } from 'app/core/utils/errors';
|
import { getMessageFromError } from 'app/core/utils/errors';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
const defaultSuccessNotification = {
|
const defaultSuccessNotification = {
|
||||||
title: '',
|
title: '',
|
||||||
@ -29,7 +30,7 @@ export const createSuccessNotification = (title: string, text = ''): AppNotifica
|
|||||||
...defaultSuccessNotification,
|
...defaultSuccessNotification,
|
||||||
title: title,
|
title: title,
|
||||||
text: text,
|
text: text,
|
||||||
id: Date.now(),
|
id: uuidv4(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const createErrorNotification = (
|
export const createErrorNotification = (
|
||||||
@ -41,7 +42,7 @@ export const createErrorNotification = (
|
|||||||
...defaultErrorNotification,
|
...defaultErrorNotification,
|
||||||
text: getMessageFromError(text),
|
text: getMessageFromError(text),
|
||||||
title,
|
title,
|
||||||
id: Date.now(),
|
id: uuidv4(),
|
||||||
component,
|
component,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -50,5 +51,5 @@ export const createWarningNotification = (title: string, text = ''): AppNotifica
|
|||||||
...defaultWarningNotification,
|
...defaultWarningNotification,
|
||||||
title: title,
|
title: title,
|
||||||
text: text,
|
text: text,
|
||||||
id: Date.now(),
|
id: uuidv4(),
|
||||||
});
|
});
|
||||||
|
@ -3,8 +3,8 @@ import { AppNotificationSeverity, AppNotificationTimeout } from 'app/types/';
|
|||||||
|
|
||||||
describe('clear alert', () => {
|
describe('clear alert', () => {
|
||||||
it('should filter alert', () => {
|
it('should filter alert', () => {
|
||||||
const id1 = 1540301236048;
|
const id1 = '1767d3d9-4b99-40eb-ab46-de734a66f21d';
|
||||||
const id2 = 1540301248293;
|
const id2 = '4767b3de-12dd-40e7-b58c-f778bd59d675';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
appNotifications: [
|
appNotifications: [
|
||||||
@ -48,9 +48,9 @@ describe('clear alert', () => {
|
|||||||
|
|
||||||
describe('notify', () => {
|
describe('notify', () => {
|
||||||
it('create notify message', () => {
|
it('create notify message', () => {
|
||||||
const id1 = 1540301236048;
|
const id1 = '696da53b-6ae7-4824-9e0e-d6a3b54a2c74';
|
||||||
const id2 = 1540301248293;
|
const id2 = '4477fcd9-246c-45a5-8818-e22a16683dae';
|
||||||
const id3 = 1540301248203;
|
const id3 = '55be87a8-bbab-45c7-b481-1f9d46f0d2ee';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
appNotifications: [
|
appNotifications: [
|
||||||
|
@ -13,7 +13,7 @@ const appNotificationsSlice = createSlice({
|
|||||||
...state,
|
...state,
|
||||||
appNotifications: state.appNotifications.concat([action.payload]),
|
appNotifications: state.appNotifications.concat([action.payload]),
|
||||||
}),
|
}),
|
||||||
clearAppNotification: (state, action: PayloadAction<number>): AppNotificationsState => ({
|
clearAppNotification: (state, action: PayloadAction<string>): AppNotificationsState => ({
|
||||||
...state,
|
...state,
|
||||||
appNotifications: state.appNotifications.filter(appNotification => appNotification.id !== action.payload),
|
appNotifications: state.appNotifications.filter(appNotification => appNotification.id !== action.payload),
|
||||||
}),
|
}),
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import store from 'app/core/store';
|
import store from 'app/core/store';
|
||||||
import kbn from 'app/core/utils/kbn';
|
import kbn from 'app/core/utils/kbn';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { getNextRefIdChar } from './query';
|
import { getNextRefIdChar } from './query';
|
||||||
// Types
|
// Types
|
||||||
import { RefreshPicker } from '@grafana/ui';
|
import { RefreshPicker } from '@grafana/ui';
|
||||||
@ -265,7 +266,7 @@ export function parseUrlState(initial: string | undefined): ExploreUrlState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function generateKey(index = 0): string {
|
export function generateKey(index = 0): string {
|
||||||
return `Q-${Date.now()}-${Math.random()}-${index}`;
|
return `Q-${uuidv4()}-${index}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateEmptyQuery(queries: DataQuery[], index = 0): DataQuery {
|
export function generateEmptyQuery(queries: DataQuery[], index = 0): DataQuery {
|
||||||
|
@ -37,7 +37,7 @@ import {
|
|||||||
import { updateLocation } from '../../../core/actions';
|
import { updateLocation } from '../../../core/actions';
|
||||||
import { serializeStateToUrlParam } from '@grafana/data/src/utils/url';
|
import { serializeStateToUrlParam } from '@grafana/data/src/utils/url';
|
||||||
|
|
||||||
const QUERY_KEY_REGEX = /Q-([0-9]+)-([0-9.]+)-([0-9]+)/;
|
const QUERY_KEY_REGEX = /Q-(?:[a-z0-9]+-){5}(?:[0-9]+)/;
|
||||||
|
|
||||||
describe('Explore item reducer', () => {
|
describe('Explore item reducer', () => {
|
||||||
describe('scanning', () => {
|
describe('scanning', () => {
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
LoadingState,
|
LoadingState,
|
||||||
QueryResultMeta,
|
QueryResultMeta,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import InfluxSeries from './influx_series';
|
import InfluxSeries from './influx_series';
|
||||||
import InfluxQueryModel from './influx_query_model';
|
import InfluxQueryModel from './influx_query_model';
|
||||||
import ResponseParser from './response_parser';
|
import ResponseParser from './response_parser';
|
||||||
@ -311,7 +312,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
// TODO: eventually use the real /health endpoint
|
// TODO: eventually use the real /health endpoint
|
||||||
const request: DataQueryRequest<InfluxQuery> = {
|
const request: DataQueryRequest<InfluxQuery> = {
|
||||||
targets: [{ refId: 'test', query: 'buckets()' }],
|
targets: [{ refId: 'test', query: 'buckets()' }],
|
||||||
requestId: `${this.id}-health-${Date.now()}`,
|
requestId: `${this.id}-health-${uuidv4()}`,
|
||||||
dashboardId: 0,
|
dashboardId: 0,
|
||||||
panelId: 0,
|
panelId: 0,
|
||||||
interval: '1m',
|
interval: '1m',
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export interface AppNotification {
|
export interface AppNotification {
|
||||||
id: number;
|
id: string;
|
||||||
severity: AppNotificationSeverity;
|
severity: AppNotificationSeverity;
|
||||||
icon: string;
|
icon: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user