Skip to content

Commit

Permalink
[Exploratory view] Use index patterns for formatting (#96280) (#96721)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Apr 12, 2021
1 parent 8d534f4 commit 4be6268
Show file tree
Hide file tree
Showing 64 changed files with 469 additions and 123 deletions.
6 changes: 6 additions & 0 deletions src/plugins/data/public/index_patterns/index_pattern.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sinon from 'sinon';

import { CoreSetup } from 'src/core/public';
import { SerializedFieldFormat } from 'src/plugins/expressions/public';
import { IFieldType, FieldSpec } from '../../common/index_patterns';
import { IndexPattern, indexPatterns, KBN_FIELD_TYPES, fieldList } from '../';
import { getFieldFormatsRegistry } from '../test_utils';
Expand Down Expand Up @@ -51,6 +52,7 @@ export class StubIndexPattern {
_reindexFields: Function;
stubSetFieldFormat: Function;
fields?: FieldSpec[];
setFieldFormat: (fieldName: string, format: SerializedFieldFormat) => void;

constructor(
pattern: string,
Expand All @@ -74,6 +76,10 @@ export class StubIndexPattern {
this.metaFields = ['_id', '_type', '_source'];
this.fieldFormatMap = {};

this.setFieldFormat = (fieldName: string, format: SerializedFieldFormat) => {
this.fieldFormatMap[fieldName] = format;
};

this.getComputedFields = IndexPattern.prototype.getComputedFields.bind(this);
this.flattenHit = indexPatterns.flattenHitWrapper(
(this as unknown) as IndexPattern,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type {
YAxisMode,
XYCurveType,
} from './xy_visualization/types';
export type { DataType } from './types';
export type { DataType, OperationMetadata } from './types';
export type {
PieVisualizationState,
PieLayerState,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const createStartContract = (): Start => {
}),
canUseEditor: jest.fn(() => true),
navigateToPrefilledEditor: jest.fn(),
getXyVisTypes: jest.fn().mockReturnValue(new Promise(() => visualizationTypes)),
getXyVisTypes: jest.fn().mockReturnValue(new Promise((resolve) => resolve(visualizationTypes))),
};
return startContract;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import { ConfigProps, DataSeries } from '../types';
import { FieldLabels } from './constants';
import { buildPhraseFilter } from './utils';
import { OperationType } from '../../../../../../lens/public';
import { ConfigProps, DataSeries } from '../../types';
import { FieldLabels } from '../constants';
import { buildPhraseFilter } from '../utils';
import { OperationType } from '../../../../../../../lens/public';

export function getServiceLatencyLensConfig({ seriesId, indexPattern }: ConfigProps): DataSeries {
return {
Expand All @@ -20,7 +20,7 @@ export function getServiceLatencyLensConfig({ seriesId, indexPattern }: ConfigPr
sourceField: '@timestamp',
},
yAxisColumn: {
operationType: 'avg' as OperationType,
operationType: 'average' as OperationType,
sourceField: 'transaction.duration.us',
label: 'Latency',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import { ConfigProps, DataSeries } from '../types';
import { FieldLabels } from './constants';
import { buildPhraseFilter } from './utils';
import { OperationType } from '../../../../../../lens/public';
import { ConfigProps, DataSeries } from '../../types';
import { FieldLabels } from '../constants/constants';
import { buildPhraseFilter } from '../utils';
import { OperationType } from '../../../../../../../lens/public';

export function getServiceThroughputLensConfig({
seriesId,
Expand All @@ -23,7 +23,7 @@ export function getServiceThroughputLensConfig({
sourceField: '@timestamp',
},
yAxisColumn: {
operationType: 'avg' as OperationType,
operationType: 'average' as OperationType,
sourceField: 'transaction.duration.us',
label: 'Throughput',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
* 2.0.
*/

import { AppDataType, ReportViewTypeId } from '../types';
import {
CLS_FIELD,
FCP_FIELD,
FID_FIELD,
LCP_FIELD,
TBT_FIELD,
} from './data/elasticsearch_fieldnames';
import { AppDataType, ReportViewTypeId } from '../../types';
import { CLS_FIELD, FCP_FIELD, FID_FIELD, LCP_FIELD, TBT_FIELD } from './elasticsearch_fieldnames';

export const FieldLabels: Record<string, string> = {
'user_agent.name': 'Browser family',
Expand All @@ -24,10 +18,10 @@ export const FieldLabels: Record<string, string> = {
'service.name': 'Service Name',
'service.environment': 'Environment',

[LCP_FIELD]: 'Largest contentful paint',
[FCP_FIELD]: 'First contentful paint',
[TBT_FIELD]: 'Total blocking time',
[FID_FIELD]: 'First input delay',
[LCP_FIELD]: 'Largest contentful paint (Seconds)',
[FCP_FIELD]: 'First contentful paint (Seconds)',
[TBT_FIELD]: 'Total blocking time (Seconds)',
[FID_FIELD]: 'First input delay (Seconds)',
[CLS_FIELD]: 'Cumulative layout shift',

'monitor.id': 'Monitor Id',
Expand All @@ -38,6 +32,7 @@ export const FieldLabels: Record<string, string> = {
'monitor.name': 'Monitor name',
'monitor.type': 'Monitor Type',
'url.port': 'Port',
'url.full': 'Url',
tags: 'Tags',

// custom
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 * from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
*/

import { ReportViewTypes } from '../types';
import { getPerformanceDistLensConfig } from './performance_dist_config';
import { getMonitorDurationConfig } from './monitor_duration_config';
import { getServiceLatencyLensConfig } from './service_latency_config';
import { getMonitorPingsConfig } from './monitor_pings_config';
import { getServiceThroughputLensConfig } from './service_throughput_config';
import { getKPITrendsLensConfig } from './kpi_trends_config';
import { getCPUUsageLensConfig } from './cpu_usage_config';
import { getMemoryUsageLensConfig } from './memory_usage_config';
import { getNetworkActivityLensConfig } from './network_activity_config';
import { getLogsFrequencyLensConfig } from './logs_frequency_config';
import { getPerformanceDistLensConfig } from './rum/performance_dist_config';
import { getMonitorDurationConfig } from './synthetics/monitor_duration_config';
import { getServiceLatencyLensConfig } from './apm/service_latency_config';
import { getMonitorPingsConfig } from './synthetics/monitor_pings_config';
import { getServiceThroughputLensConfig } from './apm/service_throughput_config';
import { getKPITrendsLensConfig } from './rum/kpi_trends_config';
import { getCPUUsageLensConfig } from './metrics/cpu_usage_config';
import { getMemoryUsageLensConfig } from './metrics/memory_usage_config';
import { getNetworkActivityLensConfig } from './metrics/network_activity_config';
import { getLogsFrequencyLensConfig } from './logs/logs_frequency_config';
import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import { LensAttributes } from './lens_attributes';
import { mockIndexPattern } from '../rtl_helpers';
import { getDefaultConfigs } from './default_configs';
import { sampleAttribute } from './data/sample_attribute';
import { LCP_FIELD, SERVICE_NAME } from './data/elasticsearch_fieldnames';
import { USER_AGENT_NAME } from './data/elasticsearch_fieldnames';
import { sampleAttribute } from './test_data/sample_attribute';
import { LCP_FIELD, SERVICE_NAME, USER_AGENT_NAME } from './constants/elasticsearch_fieldnames';

describe('Lens Attribute', () => {
const reportViewConfig = getDefaultConfigs({
Expand Down Expand Up @@ -93,7 +92,7 @@ describe('Lens Attribute', () => {
expect(lnsAttr.getNumberColumn('transaction.duration.us')).toEqual({
dataType: 'number',
isBucketed: true,
label: 'Page load time',
label: 'Page load time (Seconds)',
operationType: 'range',
params: {
maxBars: 'auto',
Expand Down Expand Up @@ -129,7 +128,7 @@ describe('Lens Attribute', () => {
expect(lnsAttr.getXAxis()).toEqual({
dataType: 'number',
isBucketed: true,
label: 'Page load time',
label: 'Page load time (Seconds)',
operationType: 'range',
params: {
maxBars: 'auto',
Expand All @@ -154,7 +153,7 @@ describe('Lens Attribute', () => {
'x-axis-column': {
dataType: 'number',
isBucketed: true,
label: 'Page load time',
label: 'Page load time (Seconds)',
operationType: 'range',
params: {
maxBars: 'auto',
Expand Down Expand Up @@ -318,7 +317,7 @@ describe('Lens Attribute', () => {
'x-axis-column': {
dataType: 'number',
isBucketed: true,
label: 'Page load time',
label: 'Page load time (Seconds)',
operationType: 'range',
params: {
maxBars: 'auto',
Expand Down Expand Up @@ -363,7 +362,7 @@ describe('Lens Attribute', () => {
'x-axis-column': {
dataType: 'number',
isBucketed: true,
label: 'Page load time',
label: 'Page load time (Seconds)',
operationType: 'range',
params: {
maxBars: 'auto',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { DataSeries } from '../types';
import { FieldLabels } from './constants';
import { DataSeries } from '../../types';
import { FieldLabels } from '../constants';

interface Props {
seriesId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { DataSeries } from '../types';
import { FieldLabels } from './constants';
import { OperationType } from '../../../../../../lens/public';
import { DataSeries } from '../../types';
import { FieldLabels } from '../constants';
import { OperationType } from '../../../../../../../lens/public';

interface Props {
seriesId: string;
Expand All @@ -23,7 +23,7 @@ export function getCPUUsageLensConfig({ seriesId }: Props): DataSeries {
sourceField: '@timestamp',
},
yAxisColumn: {
operationType: 'avg' as OperationType,
operationType: 'average' as OperationType,
sourceField: 'system.cpu.user.pct',
label: 'CPU Usage %',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { DataSeries } from '../types';
import { FieldLabels } from './constants';
import { OperationType } from '../../../../../../lens/public';
import { DataSeries } from '../../types';
import { FieldLabels } from '../constants';
import { OperationType } from '../../../../../../../lens/public';

interface Props {
seriesId: string;
Expand All @@ -23,7 +23,7 @@ export function getMemoryUsageLensConfig({ seriesId }: Props): DataSeries {
sourceField: '@timestamp',
},
yAxisColumn: {
operationType: 'avg' as OperationType,
operationType: 'average' as OperationType,
sourceField: 'system.memory.used.pct',
label: 'Memory Usage %',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { DataSeries } from '../types';
import { FieldLabels } from './constants';
import { OperationType } from '../../../../../../lens/public';
import { DataSeries } from '../../types';
import { FieldLabels } from '../constants';
import { OperationType } from '../../../../../../../lens/public';

interface Props {
seriesId: string;
Expand All @@ -23,7 +23,7 @@ export function getNetworkActivityLensConfig({ seriesId }: Props): DataSeries {
sourceField: '@timestamp',
},
yAxisColumn: {
operationType: 'avg' as OperationType,
operationType: 'average' as OperationType,
sourceField: 'system.memory.used.pct',
},
hasMetricType: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 { FieldFormat } from '../../types';
import {
FCP_FIELD,
FID_FIELD,
LCP_FIELD,
TBT_FIELD,
TRANSACTION_DURATION,
} from '../constants/elasticsearch_fieldnames';

export const rumFieldFormats: FieldFormat[] = [
{
field: TRANSACTION_DURATION,
format: {
id: 'duration',
params: {
inputFormat: 'microseconds',
outputFormat: 'asSeconds',
showSuffix: true,
outputPrecision: 1,
},
},
},
{
field: FCP_FIELD,
format: {
id: 'duration',
params: {
inputFormat: 'milliseconds',
outputFormat: 'asSeconds',
showSuffix: true,
},
},
},
{
field: LCP_FIELD,
format: {
id: 'duration',
params: {
inputFormat: 'milliseconds',
outputFormat: 'asSeconds',
showSuffix: true,
},
},
},
{
field: TBT_FIELD,
format: {
id: 'duration',
params: {
inputFormat: 'milliseconds',
outputFormat: 'asSeconds',
showSuffix: true,
},
},
},
{
field: FID_FIELD,
format: {
id: 'duration',
params: {
inputFormat: 'milliseconds',
outputFormat: 'asSeconds',
showSuffix: true,
},
},
},
];
Loading

0 comments on commit 4be6268

Please sign in to comment.