[Exploratory view] Update mobile index pattern to account for metrics events (#125916)

This commit is contained in:
Shahzad 2022-02-17 16:22:56 +01:00 committed by GitHub
parent 12b38742da
commit f7cdf2ed93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 180 additions and 4 deletions

View file

@ -17,6 +17,7 @@ import { buildPhrasesFilter } from '../utils';
import {
METRIC_SYSTEM_CPU_USAGE,
METRIC_SYSTEM_MEMORY_USAGE,
PROCESSOR_EVENT,
SERVICE_ENVIRONMENT,
SERVICE_NAME,
TRANSACTION_DURATION,
@ -55,16 +56,34 @@ export function getMobileKPIDistributionConfig({ indexPattern }: ConfigProps): S
label: RESPONSE_LATENCY,
field: TRANSACTION_DURATION,
id: TRANSACTION_DURATION,
columnFilters: [
{
language: 'kuery',
query: `${PROCESSOR_EVENT}: transaction`,
},
],
},
{
label: SYSTEM_MEMORY_USAGE,
field: METRIC_SYSTEM_MEMORY_USAGE,
id: METRIC_SYSTEM_MEMORY_USAGE,
columnFilters: [
{
language: 'kuery',
query: `${PROCESSOR_EVENT}: metric`,
},
],
},
{
label: CPU_USAGE,
field: METRIC_SYSTEM_CPU_USAGE,
id: METRIC_SYSTEM_CPU_USAGE,
columnFilters: [
{
language: 'kuery',
query: `${PROCESSOR_EVENT}: metric`,
},
],
},
],
};

View file

@ -18,6 +18,7 @@ import { buildPhrasesFilter } from '../utils';
import {
METRIC_SYSTEM_CPU_USAGE,
METRIC_SYSTEM_MEMORY_USAGE,
PROCESSOR_EVENT,
SERVICE_ENVIRONMENT,
SERVICE_NAME,
TRANSACTION_DURATION,
@ -74,7 +75,7 @@ export function getMobileKPIConfig({ indexPattern }: ConfigProps): SeriesConfig
columnFilters: [
{
language: 'kuery',
query: `processor.event: transaction`,
query: `${PROCESSOR_EVENT}: transaction`,
},
],
timeScale: 'm',
@ -84,12 +85,24 @@ export function getMobileKPIConfig({ indexPattern }: ConfigProps): SeriesConfig
field: METRIC_SYSTEM_MEMORY_USAGE,
id: METRIC_SYSTEM_MEMORY_USAGE,
columnType: OPERATION_COLUMN,
columnFilters: [
{
language: 'kuery',
query: `${PROCESSOR_EVENT}: metric`,
},
],
},
{
label: CPU_USAGE,
field: METRIC_SYSTEM_CPU_USAGE,
id: METRIC_SYSTEM_CPU_USAGE,
columnType: OPERATION_COLUMN,
columnFilters: [
{
language: 'kuery',
query: `${PROCESSOR_EVENT}: metric`,
},
],
},
],
};

View file

@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { mockAppIndexPattern, mockIndexPattern } from '../../rtl_helpers';
import { LensAttributes } from '../lens_attributes';
import { METRIC_SYSTEM_MEMORY_USAGE, SERVICE_NAME } from '../constants/elasticsearch_fieldnames';
import { obsvReportConfigMap } from '../../obsv_exploratory_view';
import { testMobileKPIAttr } from '../test_data/mobile_test_attribute';
import { getLayerConfigs } from '../../hooks/use_lens_attributes';
import { IndexPatternState } from '../../hooks/use_app_index_pattern';
describe('Mobile kpi config test', function () {
mockAppIndexPattern();
let lnsAttr: LensAttributes;
const layerConfigs = getLayerConfigs(
[
{
time: { from: 'now-15m', to: 'now' },
reportDefinitions: { [SERVICE_NAME]: ['ios-integration-testing'] },
selectedMetricField: METRIC_SYSTEM_MEMORY_USAGE,
color: 'green',
name: 'test-series',
dataType: 'mobile',
},
],
'kpi-over-time',
{} as any,
{ mobile: mockIndexPattern } as IndexPatternState,
obsvReportConfigMap
);
beforeEach(() => {
lnsAttr = new LensAttributes(layerConfigs);
});
it('should return expected json', function () {
expect(lnsAttr.getJSON()).toEqual(testMobileKPIAttr);
});
});

View file

@ -0,0 +1,86 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export const testMobileKPIAttr = {
title: 'Prefilled from exploratory view app',
description: '',
references: [
{
id: 'apm-*',
name: 'indexpattern-datasource-current-indexpattern',
type: 'index-pattern',
},
{
id: 'apm-*',
name: 'indexpattern-datasource-layer-layer0',
type: 'index-pattern',
},
],
visualizationType: 'lnsXY',
state: {
datasourceStates: {
indexpattern: {
layers: {
layer0: {
columnOrder: ['x-axis-column-layer0', 'y-axis-column-layer0'],
columns: {
'x-axis-column-layer0': {
sourceField: '@timestamp',
dataType: 'date',
isBucketed: true,
label: '@timestamp',
operationType: 'date_histogram',
params: { interval: 'auto' },
scale: 'interval',
},
'y-axis-column-layer0': {
isBucketed: false,
label: 'Median of System memory usage',
operationType: 'median',
scale: 'ratio',
sourceField: 'system.memory.usage',
dataType: 'number',
filter: {
query:
'service.name: "ios-integration-testing" and agent.name: (iOS/swift or open-telemetry/swift) and processor.event: metric',
language: 'kuery',
},
},
},
incompleteColumns: {},
},
},
},
},
visualization: {
legend: { isVisible: true, showSingleSeries: true, position: 'right' },
valueLabels: 'hide',
fittingFunction: 'Linear',
curveType: 'CURVE_MONOTONE_X',
axisTitlesVisibilitySettings: { x: true, yLeft: true, yRight: true },
tickLabelsVisibilitySettings: { x: true, yLeft: true, yRight: true },
gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true },
preferredSeriesType: 'line',
layers: [
{
accessors: ['y-axis-column-layer0'],
layerId: 'layer0',
layerType: 'data',
seriesType: 'line',
yConfig: [{ forAccessor: 'y-axis-column-layer0', color: 'green', axisMode: 'left' }],
xAccessor: 'x-axis-column-layer0',
},
],
},
query: {
query:
'service.name: "ios-integration-testing" and agent.name: (iOS/swift or open-telemetry/swift)',
language: 'kuery',
},
filters: [],
},
};

View file

@ -15,6 +15,7 @@ import { ObservabilityDataViews } from '../../../../utils/observability_data_vie
import { getDataHandler } from '../../../../data_handler';
import { useExploratoryView } from '../contexts/exploratory_view_config';
import { DataViewInsufficientAccessError } from '../../../../../../../../src/plugins/data_views/common';
import { getApmDataViewTitle } from '../utils/utils';
export interface IndexPatternContext {
loading: boolean;
@ -75,9 +76,9 @@ export function IndexPatternContextProvider({ children }: ProviderProps) {
break;
case 'apm':
case 'mobile':
const resultApm = await getDataHandler('apm')?.hasData();
const resultApm = await getDataHandler('apm')!.hasData();
hasDataT = Boolean(resultApm?.hasData);
indices = resultApm?.indices.transaction;
indices = getApmDataViewTitle(resultApm?.indices);
break;
}
setHasAppData((prevState) => ({ ...prevState, [dataType]: hasDataT }));

View file

@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { uniq } from 'lodash';
import { ApmIndicesConfig } from '../../../../../common/typings';
export function getApmDataViewTitle(apmIndicesConfig: ApmIndicesConfig) {
return uniq([apmIndicesConfig.transaction, apmIndicesConfig.metric]).join(',');
}