Skip to content

Commit

Permalink
[Synthetics]Add availability metric to summary page (#135296)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Jul 12, 2022
1 parent cd8a4ae commit ec64c5d
Show file tree
Hide file tree
Showing 17 changed files with 6,878 additions and 41 deletions.
18 changes: 11 additions & 7 deletions x-pack/plugins/observability/e2e/synthetics_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@ export class SyntheticsRunner {
}

async loadTestData(e2eDir: string, dataArchives: string[]) {
console.log('Loading esArchiver...');
try {
console.log('Loading esArchiver...');

const esArchiver = this.getService('esArchiver');
const esArchiver = this.getService('esArchiver');

const promises = dataArchives.map((archive) => esArchiver.loadIfNeeded(e2eDir + archive));
const promises = dataArchives.map((archive) => esArchiver.loadIfNeeded(e2eDir + archive));

await Promise.all([
...promises,
esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'),
]);
await Promise.all([
...promises,
esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'),
]);
} catch (e) {
console.log(e);
}
}

getKibanaUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export const sampleMetricFormulaAttribute = {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Monitor availability',
label: 'Availability',
operationType: 'formula',
params: {
format: {
id: 'percent',
params: {
decimals: 2,
decimals: 1,
},
},
formula: "1- (count(kql='summary.down > 0') / count())",
Expand All @@ -57,7 +57,7 @@ export const sampleMetricFormulaAttribute = {
query: 'summary.down > 0',
},
isBucketed: false,
label: 'Part of Monitor availability',
label: 'Part of Availability',
operationType: 'count',
params: {
emptyAsNull: false,
Expand All @@ -69,7 +69,7 @@ export const sampleMetricFormulaAttribute = {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Part of Monitor availability',
label: 'Part of Availability',
operationType: 'count',
params: {
emptyAsNull: false,
Expand All @@ -81,7 +81,7 @@ export const sampleMetricFormulaAttribute = {
customLabel: true,
dataType: 'number',
isBucketed: false,
label: 'Part of Monitor availability',
label: 'Part of Availability',
operationType: 'math',
params: {
tinymathAst: {
Expand Down Expand Up @@ -148,7 +148,7 @@ export const sampleMetricFormulaAttribute = {
name: 'custom',
progression: 'fixed',
rangeMax: 1,
rangeMin: 0.8,
rangeMin: 0,
rangeType: 'number',
reverse: false,
steps: 3,
Expand All @@ -169,6 +169,8 @@ export const sampleMetricFormulaAttribute = {
},
type: 'palette',
},
size: 's',
titlePosition: 'bottom',
},
},
title: 'Prefilled from exploratory view app',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('SingleMetricAttributes', () => {
accessor: 'layer-0-column-1',
layerId: 'layer0',
layerType: 'data',
size: 's',
},
},
title: 'Prefilled from exploratory view app',
Expand Down Expand Up @@ -168,6 +169,7 @@ describe('SingleMetricAttributes', () => {
accessor: 'layer-0-column-1',
layerId: 'layer0',
layerType: 'data',
size: 's',
},
},
title: 'Prefilled from exploratory view app',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class SingleMetricLensAttributes extends LensAttributes {
format: {
id: 'percent',
params: {
decimals: 2,
decimals: 1,
},
},
},
Expand Down Expand Up @@ -159,6 +159,7 @@ export class SingleMetricLensAttributes extends LensAttributes {
layerId: 'layer0',
layerType: 'data',
...(this.metricStateOptions ?? {}),
size: 's',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getSyntheticsSingleMetricConfig({ dataView }: ConfigProps): Seri
{
id: 'monitor_availability',
columnType: FORMULA_COLUMN,
label: 'Monitor availability',
label: 'Availability',
formula: "1- (count(kql='summary.down > 0') / count())",
metricStateOptions: {
colorMode: 'Labels',
Expand All @@ -45,7 +45,7 @@ export function getSyntheticsSingleMetricConfig({ dataView }: ConfigProps): Seri
name: 'custom',
reverse: false,
rangeType: 'number',
rangeMin: 0.8,
rangeMin: 0,
rangeMax: 1,
progression: 'fixed',
stops: [
Expand All @@ -62,6 +62,7 @@ export function getSyntheticsSingleMetricConfig({ dataView }: ConfigProps): Seri
maxSteps: 5,
},
},
titlePosition: 'bottom',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import { Position } from '@elastic/charts';
import React, { useState } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiText, EuiTitle } from '@elastic/eui';
import styled from 'styled-components';
import { LensEmbeddableInput, LensPublicStart, XYState } from '@kbn/lens-plugin/public';
import {
FormulaPublicApi,
LensEmbeddableInput,
LensPublicStart,
XYState,
} from '@kbn/lens-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/common';
import { AllSeries, useTheme } from '../../../..';
import { SingleMetricLensAttributes } from '../configurations/lens_attributes/single_metric_attributes';
import { AllSeries, ReportTypes, useTheme } from '../../../..';
import { LayerConfig, LensAttributes } from '../configurations/lens_attributes';
import { AppDataType, ReportViewType } from '../types';
import { getLayerConfigs } from '../hooks/use_lens_attributes';
Expand Down Expand Up @@ -44,11 +50,13 @@ export interface ExploratoryEmbeddableProps {
singleMetricOptions?: SingleMetricOptions;
title?: string | JSX.Element;
withActions?: boolean | ActionTypes[];
align?: 'left' | 'right' | 'center';
}

export interface ExploratoryEmbeddableComponentProps extends ExploratoryEmbeddableProps {
lens: LensPublicStart;
indexPatterns: DataViewState;
lensFormulaHelper?: FormulaPublicApi;
}

// eslint-disable-next-line import/no-default-export
Expand All @@ -73,6 +81,8 @@ export default function Embeddable({
singleMetricOptions,
title,
withActions = true,
lensFormulaHelper,
align,
}: ExploratoryEmbeddableComponentProps) {
const LensComponent = lens?.EmbeddableComponent;
const LensSaveModalComponent = lens?.SaveModalComponent;
Expand All @@ -95,7 +105,11 @@ export default function Embeddable({

let lensAttributes;
try {
lensAttributes = new LensAttributes(layerConfigs, reportType);
if (reportType === ReportTypes.SINGLE_METRIC) {
lensAttributes = new SingleMetricLensAttributes(layerConfigs, reportType, lensFormulaHelper!);
} else {
lensAttributes = new LensAttributes(layerConfigs, reportType, lensFormulaHelper);
}
// eslint-disable-next-line no-empty
} catch (error) {}

Expand Down Expand Up @@ -133,7 +147,7 @@ export default function Embeddable({
}

return (
<Wrapper $customHeight={customHeight}>
<Wrapper $customHeight={customHeight} align={align}>
<EuiFlexGroup alignItems="center" gutterSize="none">
{title && (
<EuiFlexItem data-test-subj="exploratoryView-title">
Expand Down Expand Up @@ -206,6 +220,7 @@ export default function Embeddable({

const Wrapper = styled.div<{
$customHeight?: string | number;
align?: 'left' | 'right' | 'center';
}>`
height: 100%;
&&& {
Expand All @@ -225,11 +240,26 @@ const Wrapper = styled.div<{
.embPanel__optionsMenuPopover {
visibility: collapse;
}
.expExpressionRenderer__expression {
padding-top: 0;
}
&&&:hover {
.embPanel__optionsMenuPopover {
visibility: visible;
}
}
.legacyMtrVis > :first-child {
justify-content: ${(props) =>
props.align === 'left' ? `flex-start;` : props.align === 'right' ? `flex-end;` : 'center;'};
.legacyMtrVis__container {
padding-top: 4px;
padding-left: ${(props) => (props.align === 'left' ? `0` : '16px;')};
padding-right: ${(props) => (props.align === 'right' ? `0` : '16px;')};
}
> :first-child {
transform: none !important;
}
}
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import type { IUiSettingsClient } from '@kbn/core/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import { useFetcher } from '../../../..';
import type { ExploratoryEmbeddableProps, ExploratoryEmbeddableComponentProps } from './embeddable';
import { ObservabilityDataViews } from '../../../../utils/observability_data_views';
import type { DataViewState } from '../hooks/use_app_data_view';
Expand Down Expand Up @@ -43,6 +44,10 @@ export function getExploratoryViewEmbeddable(

const isDarkMode = uiSettings?.get('theme:darkMode');

const { data: lensHelper, loading: lensLoading } = useFetcher(async () => {
return lens.stateHelperApi();
}, []);

const loadIndexPattern = useCallback(
async ({ dataType }: { dataType: AppDataType }) => {
const dataTypesIndexPatterns = props.dataTypesIndexPatterns;
Expand Down Expand Up @@ -70,13 +75,18 @@ export function getExploratoryViewEmbeddable(
}
}, [series?.dataType, loadIndexPattern]);

if (Object.keys(indexPatterns).length === 0 || loading) {
if (Object.keys(indexPatterns).length === 0 || loading || !lensHelper || lensLoading) {
return <EuiLoadingSpinner />;
}

return (
<EuiThemeProvider darkMode={isDarkMode}>
<ExploratoryViewEmbeddable {...props} indexPatterns={indexPatterns} lens={lens} />
<ExploratoryViewEmbeddable
{...props}
indexPatterns={indexPatterns}
lens={lens}
lensFormulaHelper={lensHelper.formula}
/>
</EuiThemeProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface MetricOption {
timeScale?: string;
showPercentileAnnotations?: boolean;
formula?: string;
metricStateOptions?: Pick<MetricState, 'colorMode' | 'palette'>;
metricStateOptions?: Pick<MetricState, 'colorMode' | 'palette' | 'titlePosition'>;
palette?: PaletteOutput;
}

Expand Down
Binary file not shown.
Loading

0 comments on commit ec64c5d

Please sign in to comment.