Skip to content

Commit

Permalink
[Synthetics] Fix usage of synthetics-* index pattern the synthetics a…
Browse files Browse the repository at this point in the history
…pp (#152473)

Co-authored-by: Dominique Clarke <[email protected]>
  • Loading branch information
shahzad31 and dominiqueclarke authored Mar 28, 2023
1 parent 32371a4 commit 55afbba
Show file tree
Hide file tree
Showing 50 changed files with 686 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ journey('Exploratory view', async ({ page, params }) => {
reportType: 'kpi-over-time',
allSeries: [
{
dataType: 'synthetics',
dataType: 'uptime',
time: {
from: moment().subtract(10, 'y').toISOString(),
to: moment().toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const getContent = (
weight: 2,
},
{
id: 'synthetics',
id: 'uptime',
title: i18n.translate('xpack.observability.statusVisualization.uptime.title', {
defaultMessage: 'Uptime',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function UptimeSection({ bucketSize }: Props) {
const { data, status } = useFetcher(
() => {
if (bucketSize && absoluteStart && absoluteEnd) {
return getDataHandler('synthetics')?.fetchData({
return getDataHandler('uptime')?.fetchData({
absoluteTime: { start: absoluteStart, end: absoluteEnd },
relativeTime: { start: relativeStart, end: relativeEnd },
timeZone,
Expand All @@ -75,7 +75,7 @@ export function UptimeSection({ bucketSize }: Props) {
]
);

if (!hasDataMap.synthetics?.hasData) {
if (!hasDataMap.uptime?.hasData) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('useExpViewTimeRange', function () {
infra_logs: mockDataView,
infra_metrics: mockDataView,
synthetics: mockDataView,
uptime: mockDataView,
alerts: mockDataView,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n';

export enum DataTypes {
SYNTHETICS = 'synthetics',
UPTIME = 'uptime',
UX = 'ux',
MOBILE = 'mobile',
METRICS = 'infra_metrics',
Expand All @@ -27,6 +28,10 @@ export const DataTypesLabels: Record<string, string> = {
}
),

[DataTypes.UPTIME]: i18n.translate('xpack.observability.overview.exploratoryView.uptimeLabel', {
defaultMessage: 'Uptime',
}),

[DataTypes.METRICS]: i18n.translate('xpack.observability.overview.exploratoryView.metricsLabel', {
defaultMessage: 'Metrics',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import { getLogsKPIConfig } from './configurations/infra_logs/kpi_over_time_conf
import { getSingleMetricConfig } from './configurations/rum/single_metric_config';

export const dataTypes: Array<{ id: AppDataType; label: string }> = [
{
id: DataTypes.UPTIME,
label: DataTypesLabels[DataTypes.UPTIME],
},
{
id: DataTypes.SYNTHETICS,
label: DataTypesLabels[DataTypes.SYNTHETICS],
Expand Down Expand Up @@ -85,6 +89,12 @@ export const obsvReportConfigMap = {
getSyntheticsSingleMetricConfig,
getSyntheticsHeatmapConfig,
],
[DataTypes.UPTIME]: [
getSyntheticsKPIConfig,
getSyntheticsDistributionConfig,
getSyntheticsSingleMetricConfig,
getSyntheticsHeatmapConfig,
],
[DataTypes.MOBILE]: [
getMobileKPIConfig,
getMobileKPIDistributionConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ interface Props {
const AddDataComponents: Record<AppDataType, React.FC | null> = {
mobile: MobileAddData,
ux: UXAddData,
synthetics: SyntheticsAddData,
uptime: SyntheticsAddData,
synthetics: null,
apm: null,
infra_logs: null,
infra_metrics: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ interface FormatType extends SerializedFieldFormat<FieldFormatParams> {

export type AppDataType =
| 'synthetics'
| 'uptime'
| 'ux'
| 'infra_logs'
| 'infra_metrics'
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/observability/public/context/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export const ALERT_APP = 'alert';
export const UX_APP = 'ux';
export const SYNTHETICS_APP = 'synthetics';
export const UPTIME_APP = 'uptime';
export const APM_APP = 'apm';
export const INFRA_LOGS_APP = 'infra_logs';
export const INFRA_METRICS_APP = 'infra_metrics';
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function unregisterAll() {
unregisterDataHandler({ appName: 'apm' });
unregisterDataHandler({ appName: 'infra_logs' });
unregisterDataHandler({ appName: 'infra_metrics' });
unregisterDataHandler({ appName: 'synthetics' });
unregisterDataHandler({ appName: 'uptime' });
unregisterDataHandler({ appName: 'ux' });
}

Expand Down Expand Up @@ -73,7 +73,7 @@ describe('HasDataContextProvider', () => {
expect(result.current).toEqual({
hasDataMap: {
apm: { hasData: undefined, status: 'success' },
synthetics: { hasData: undefined, status: 'success' },
uptime: { hasData: undefined, status: 'success' },
infra_logs: { hasData: undefined, status: 'success' },
infra_metrics: { hasData: undefined, status: 'success' },
ux: { hasData: undefined, status: 'success' },
Expand All @@ -98,7 +98,7 @@ describe('HasDataContextProvider', () => {
},
{ appName: 'infra_metrics', hasData: async () => ({ hasData: false }) },
{
appName: 'synthetics',
appName: 'uptime',
hasData: async () => ({ hasData: false }),
},
{
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('HasDataContextProvider', () => {
expect(result.current).toEqual({
hasDataMap: {
apm: { hasData: false, status: 'success' },
synthetics: {
uptime: {
hasData: false,
status: 'success',
},
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('HasDataContextProvider', () => {
hasData: async () => ({ hasData: false, indices: 'metric-*' }),
},
{
appName: 'synthetics',
appName: 'uptime',
hasData: async () => ({ hasData: false, indices: 'heartbeat-*, synthetics-*' }),
},
{
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('HasDataContextProvider', () => {
expect(result.current).toEqual({
hasDataMap: {
apm: { hasData: true, status: 'success' },
synthetics: {
uptime: {
hasData: false,
indices: 'heartbeat-*, synthetics-*',
status: 'success',
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('HasDataContextProvider', () => {
hasData: async () => ({ hasData: true, indices: 'metric-*' }),
},
{
appName: 'synthetics',
appName: 'uptime',
hasData: async () => ({ hasData: true, indices: 'heartbeat-*, synthetics-*' }),
},
{
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('HasDataContextProvider', () => {
hasData: true,
status: 'success',
},
synthetics: {
uptime: {
hasData: true,
indices: 'heartbeat-*, synthetics-*',
status: 'success',
Expand Down Expand Up @@ -309,7 +309,7 @@ describe('HasDataContextProvider', () => {
expect(result.current).toEqual({
hasDataMap: {
apm: { hasData: true, indices: sampleAPMIndices, status: 'success' },
synthetics: { hasData: undefined, status: 'success' },
uptime: { hasData: undefined, status: 'success' },
infra_logs: { hasData: undefined, status: 'success' },
infra_metrics: { hasData: undefined, status: 'success' },
ux: { hasData: undefined, status: 'success' },
Expand Down Expand Up @@ -358,7 +358,7 @@ describe('HasDataContextProvider', () => {
indices: sampleAPMIndices,
status: 'success',
},
synthetics: { hasData: undefined, status: 'success' },
uptime: { hasData: undefined, status: 'success' },
infra_logs: { hasData: undefined, status: 'success' },
infra_metrics: { hasData: undefined, status: 'success' },
ux: { hasData: undefined, status: 'success' },
Expand Down Expand Up @@ -391,7 +391,7 @@ describe('HasDataContextProvider', () => {
hasData: async () => ({ hasData: true, indices: 'metric-*' }),
},
{
appName: 'synthetics',
appName: 'uptime',
hasData: async () => ({ hasData: true, indices: 'heartbeat-*, synthetics-*' }),
},
{
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('HasDataContextProvider', () => {
expect(result.current).toEqual({
hasDataMap: {
apm: { hasData: undefined, status: 'failure' },
synthetics: {
uptime: {
hasData: true,
indices: 'heartbeat-*, synthetics-*',
status: 'success',
Expand Down Expand Up @@ -465,7 +465,7 @@ describe('HasDataContextProvider', () => {
},
},
{
appName: 'synthetics',
appName: 'uptime',
hasData: async () => {
throw new Error('BOOMMMMM');
},
Expand Down Expand Up @@ -498,7 +498,7 @@ describe('HasDataContextProvider', () => {
expect(result.current).toEqual({
hasDataMap: {
apm: { hasData: undefined, status: 'failure' },
synthetics: { hasData: undefined, status: 'failure' },
uptime: { hasData: undefined, status: 'failure' },
infra_logs: { hasData: undefined, status: 'failure' },
infra_metrics: { hasData: undefined, status: 'failure' },
ux: { hasData: undefined, status: 'failure' },
Expand Down Expand Up @@ -544,7 +544,7 @@ describe('HasDataContextProvider', () => {
expect(result.current).toEqual({
hasDataMap: {
apm: { hasData: undefined, status: 'success' },
synthetics: { hasData: undefined, status: 'success' },
uptime: { hasData: undefined, status: 'success' },
infra_logs: { hasData: undefined, status: 'success' },
infra_metrics: { hasData: undefined, status: 'success' },
ux: { hasData: undefined, status: 'success' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
APM_APP,
INFRA_LOGS_APP,
INFRA_METRICS_APP,
SYNTHETICS_APP,
UPTIME_APP,
UX_APP,
} from './constants';
import { getDataHandler } from '../data_handler';
Expand Down Expand Up @@ -50,7 +50,7 @@ export const HasDataContext = createContext({} as HasDataContextValue);

const apps: DataContextApps[] = [
APM_APP,
SYNTHETICS_APP,
UPTIME_APP,
INFRA_LOGS_APP,
INFRA_METRICS_APP,
UX_APP,
Expand Down Expand Up @@ -100,7 +100,7 @@ export function HasDataContextProvider({ children }: { children: React.ReactNode
serviceName: resultUx?.serviceName as string,
});
break;
case SYNTHETICS_APP:
case UPTIME_APP:
const resultSy = await getDataHandler(app)?.hasData();
updateState({ hasData: resultSy?.hasData, indices: resultSy?.indices });

Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/observability/public/data_handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('registerDataHandler', () => {
});
describe('Uptime', () => {
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: async () => {
return {
title: 'uptime',
Expand Down Expand Up @@ -226,13 +226,13 @@ describe('registerDataHandler', () => {
});

it('registered data handler', () => {
const dataHandler = getDataHandler('synthetics');
const dataHandler = getDataHandler('uptime');
expect(dataHandler?.fetchData).toBeDefined();
expect(dataHandler?.hasData).toBeDefined();
});

it('returns data when fetchData is called', async () => {
const dataHandler = getDataHandler('synthetics');
const dataHandler = getDataHandler('uptime');
const response = await dataHandler?.fetchData(params);
expect(response).toEqual({
title: 'uptime',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const getEmptySections = ({ http }: { http: HttpSetup }): ISection[] => {
href: http.basePath.prepend('/app/home#/tutorial_directory/metrics'),
},
{
id: 'synthetics',
id: 'uptime',
title: i18n.translate('xpack.observability.emptySection.apps.uptime.title', {
defaultMessage: 'Uptime',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function unregisterAll() {
unregisterDataHandler({ appName: 'apm' });
unregisterDataHandler({ appName: 'infra_logs' });
unregisterDataHandler({ appName: 'infra_metrics' });
unregisterDataHandler({ appName: 'synthetics' });
unregisterDataHandler({ appName: 'uptime' });
}

const sampleAPMIndices = { transaction: 'apm-*' } as ApmIndicesConfig;
Expand Down Expand Up @@ -235,7 +235,7 @@ storiesOf('app/Overview', module)
hasData: async () => ({ hasData: false, indices: 'metric-*' }),
});
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: fetchUptimeData,
hasData: async () => ({ hasData: false, indices: 'heartbeat-*,synthetics-*' }),
});
Expand Down Expand Up @@ -323,7 +323,7 @@ storiesOf('app/Overview', module)
hasData: async () => ({ hasData: true, indices: 'metric-*' }),
});
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: fetchUptimeData,
hasData: async () => ({ hasData: true, indices: 'heartbeat-*,synthetics-*' }),
});
Expand All @@ -349,7 +349,7 @@ storiesOf('app/Overview', module)
hasData: async () => ({ hasData: true, indices: 'metric-*' }),
});
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: fetchUptimeData,
hasData: async () => ({ hasData: true, indices: 'heartbeat-*,synthetics-*' }),
});
Expand Down Expand Up @@ -377,7 +377,7 @@ storiesOf('app/Overview', module)
hasData: async () => ({ hasData: true, indices: 'metric-*' }),
});
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: fetchUptimeData,
hasData: async () => ({ hasData: true, indices: 'heartbeat-*,synthetics-*' }),
});
Expand All @@ -402,7 +402,7 @@ storiesOf('app/Overview', module)
hasData: async () => ({ hasData: true, indices: 'metric-*' }),
});
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: async () => emptyUptimeResponse,
hasData: async () => ({ hasData: true, indices: 'heartbeat-*,synthetics-*' }),
});
Expand Down Expand Up @@ -434,7 +434,7 @@ storiesOf('app/Overview', module)
hasData: async () => ({ hasData: true, indices: 'metric-*' }),
});
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: async () => {
throw new Error('Error fetching Uptime data');
},
Expand Down Expand Up @@ -472,7 +472,7 @@ storiesOf('app/Overview', module)
},
});
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: fetchUptimeData,
// @ts-ignore throws an error instead
hasData: async () => {
Expand Down Expand Up @@ -509,7 +509,7 @@ storiesOf('app/Overview', module)
},
});
registerDataHandler({
appName: 'synthetics',
appName: 'uptime',
fetchData: fetchUptimeData,
// @ts-ignore throws an error instead
hasData: async () => {
Expand Down
Loading

0 comments on commit 55afbba

Please sign in to comment.