Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exploratory view] Label field filters/breakdowns #113766

Merged
merged 7 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
TBT_LABEL,
URL_LABEL,
BACKEND_TIME_LABEL,
LABELS_FIELD,
} from './labels';

export const DEFAULT_TIME = { from: 'now-1h', to: 'now' };
Expand Down Expand Up @@ -85,6 +86,8 @@ export const FieldLabels: Record<string, string> = {
'performance.metric': METRIC_LABEL,
'Business.KPI': KPI_LABEL,
'http.request.method': REQUEST_METHOD,
LABEL_FIELDS_FILTER: LABELS_FIELD,
LABEL_FIELDS_BREAKDOWN: 'Labels field',
};

export const DataViewLabels: Record<ReportViewType, string> = {
Expand Down Expand Up @@ -113,3 +116,6 @@ export const TERMS_COLUMN = 'TERMS_COLUMN';
export const OPERATION_COLUMN = 'operation';

export const REPORT_METRIC_FIELD = 'REPORT_METRIC_FIELD';

export const LABEL_FIELDS_FILTER = 'LABEL_FIELDS_FILTER';
export const LABEL_FIELDS_BREAKDOWN = 'LABEL_FIELDS_BREAKDOWN';
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ export const TAGS_LABEL = i18n.translate('xpack.observability.expView.fieldLabel
export const METRIC_LABEL = i18n.translate('xpack.observability.expView.fieldLabels.metric', {
defaultMessage: 'Metric',
});
export const LABELS_FIELD = i18n.translate('xpack.observability.expView.fieldLabels.labels', {
defaultMessage: 'Labels:',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to have a colon?

});
export const LABELS_BREAKDOWN = i18n.translate(
'xpack.observability.expView.fieldLabels.chooseField',
{
defaultMessage: 'Labels field',
}
);
export const KPI_LABEL = i18n.translate('xpack.observability.expView.fieldLabels.kpi', {
defaultMessage: 'KPI',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/

import { ConfigProps, SeriesConfig } from '../../types';
import { FieldLabels, REPORT_METRIC_FIELD, ReportTypes, USE_BREAK_DOWN_COLUMN } from '../constants';
import {
FieldLabels,
LABEL_FIELDS_FILTER,
REPORT_METRIC_FIELD,
ReportTypes,
USE_BREAK_DOWN_COLUMN,
} from '../constants';
import { buildPhraseFilter } from '../utils';
import { SERVICE_NAME } from '../constants/elasticsearch_fieldnames';
import { MOBILE_APP, NUMBER_OF_DEVICES } from '../constants/labels';
Expand All @@ -27,7 +33,7 @@ export function getMobileDeviceDistributionConfig({ indexPattern }: ConfigProps)
},
],
hasOperationType: false,
filterFields: Object.keys(MobileFields),
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhraseFilter('agent.name', 'iOS/swift', indexPattern),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/

import { ConfigProps, SeriesConfig } from '../../types';
import { FieldLabels, RECORDS_FIELD, REPORT_METRIC_FIELD, ReportTypes } from '../constants';
import {
FieldLabels,
LABEL_FIELDS_FILTER,
RECORDS_FIELD,
REPORT_METRIC_FIELD,
ReportTypes,
} from '../constants';
import { buildPhrasesFilter } from '../utils';
import {
METRIC_SYSTEM_CPU_USAGE,
Expand All @@ -33,7 +39,7 @@ export function getMobileKPIDistributionConfig({ indexPattern }: ConfigProps): S
},
],
hasOperationType: false,
filterFields: Object.keys(MobileFields),
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], indexPattern),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { ConfigProps, SeriesConfig } from '../../types';
import {
FieldLabels,
LABEL_FIELDS_FILTER,
OPERATION_COLUMN,
RECORDS_FIELD,
REPORT_METRIC_FIELD,
Expand Down Expand Up @@ -45,7 +46,7 @@ export function getMobileKPIConfig({ indexPattern }: ConfigProps): SeriesConfig
},
],
hasOperationType: true,
filterFields: Object.keys(MobileFields),
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], indexPattern),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ConfigProps, SeriesConfig } from '../../types';
import {
FieldLabels,
FILTER_RECORDS,
LABEL_FIELDS_FILTER,
REPORT_METRIC_FIELD,
ReportTypes,
USE_BREAK_DOWN_COLUMN,
Expand Down Expand Up @@ -75,6 +76,7 @@ export function getCoreWebVitalsConfig({ indexPattern }: ConfigProps): SeriesCon
field: USER_AGENT_NAME,
nested: USER_AGENT_VERSION,
},
LABEL_FIELDS_FILTER,
],
breakdownFields: [
SERVICE_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
REPORT_METRIC_FIELD,
RECORDS_PERCENTAGE_FIELD,
ReportTypes,
LABEL_FIELDS_FILTER,
} from '../constants';
import { buildPhraseFilter } from '../utils';
import {
Expand Down Expand Up @@ -71,6 +72,7 @@ export function getRumDistributionConfig({ indexPattern }: ConfigProps): SeriesC
field: USER_AGENT_NAME,
nested: USER_AGENT_VERSION,
},
LABEL_FIELDS_FILTER,
],
breakdownFields: [USER_AGENT_NAME, USER_AGENT_OS, CLIENT_GEO_COUNTRY_NAME, USER_AGENT_DEVICE],
definitionFields: [SERVICE_NAME, SERVICE_ENVIRONMENT],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { ConfigProps, SeriesConfig } from '../../types';
import {
FieldLabels,
LABEL_FIELDS_BREAKDOWN,
LABEL_FIELDS_FILTER,
OPERATION_COLUMN,
RECORDS_FIELD,
REPORT_METRIC_FIELD,
Expand Down Expand Up @@ -72,8 +74,15 @@ export function getKPITrendsLensConfig({ indexPattern }: ConfigProps): SeriesCon
field: USER_AGENT_NAME,
nested: USER_AGENT_VERSION,
},
LABEL_FIELDS_FILTER,
],
breakdownFields: [
USER_AGENT_NAME,
USER_AGENT_OS,
CLIENT_GEO_COUNTRY_NAME,
USER_AGENT_DEVICE,
LABEL_FIELDS_BREAKDOWN,
],
breakdownFields: [USER_AGENT_NAME, USER_AGENT_OS, CLIENT_GEO_COUNTRY_NAME, USER_AGENT_DEVICE],
baseFilters: [
...buildPhraseFilter(TRANSACTION_TYPE, 'page-load', indexPattern),
...buildPhraseFilter(PROCESSOR_EVENT, 'transaction', indexPattern),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import { EuiSuperSelect } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useSeriesStorage } from '../../hooks/use_series_storage';
import { USE_BREAK_DOWN_COLUMN } from '../../configurations/constants';
import { LABEL_FIELDS_BREAKDOWN, USE_BREAK_DOWN_COLUMN } from '../../configurations/constants';
import { SeriesConfig, SeriesUrl } from '../../types';

interface Props {
Expand Down Expand Up @@ -62,9 +62,13 @@ export function Breakdowns({ seriesConfig, seriesId, series }: Props) {
dropdownDisplay: label,
}));

const valueOfSelected =
let valueOfSelected =
selectedBreakdown || (hasUseBreakdownColumn ? options[0].value : NO_BREAKDOWN);

if (selectedBreakdown?.startsWith('labels.')) {
valueOfSelected = LABEL_FIELDS_BREAKDOWN;
}

return (
<EuiSuperSelect
options={options}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 { EuiComboBox, EuiFlexItem } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { SeriesConfig, SeriesUrl } from '../../types';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useSeriesStorage } from '../../hooks/use_series_storage';
import { LABEL_FIELDS_BREAKDOWN } from '../../configurations/constants';

interface Props {
seriesId: number;
series: SeriesUrl;
seriesConfig?: SeriesConfig;
}
export function LabelsBreakdown({ series, seriesId }: Props) {
const { indexPattern } = useAppIndexPatternContext(series.dataType);

const labelFields = indexPattern?.fields.filter((field) => field.name.startsWith('labels.'));

const { setSeries } = useSeriesStorage();

const { breakdown } = series;

const hasLabelBreakdown =
breakdown === LABEL_FIELDS_BREAKDOWN || breakdown?.startsWith('labels.');

if (!hasLabelBreakdown) {
return null;
}

const labelFieldOptions = labelFields?.map((field) => {
return {
label: field.name,
value: field.name,
};
});

return (
<EuiFlexItem grow={false} style={{ minWidth: 200 }}>
<EuiComboBox
selectedOptions={labelFieldOptions?.filter((labelField) => labelField.label === breakdown)}
options={labelFieldOptions}
placeholder={CHOOSE_BREAKDOWN_FIELD}
onChange={(value) => {
setSeries(seriesId, {
...series,
breakdown: value?.[0]?.label ?? LABEL_FIELDS_BREAKDOWN,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user hits apply before a label is actually selected, and it falls back to LABEL_FIELDS_BREAKDOWN, the view will break. Not sure if this is the biggest issue, as this is a pretty big edge case. If we add back in auto apply though, I'm thinking this would break.

Screen Shot 2021-10-06 at 10 00 32 AM

});
}}
singleSelection={{ asPlainText: true }}
/>
</EuiFlexItem>
);
}

export const CHOOSE_BREAKDOWN_FIELD = i18n.translate(
'xpack.observability.expView.seriesBuilder.labelField',
{
defaultMessage: 'Choose label field',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('FilterExpanded', function () {
series={mockSeries}
label={'Browser Family'}
field={USER_AGENT_NAME}
filters={[]}
baseFilters={[]}
/>,
{ initSeries }
);
Expand All @@ -45,7 +45,7 @@ describe('FilterExpanded', function () {
series={mockSeries}
label={'Browser Family'}
field={USER_AGENT_NAME}
filters={[]}
baseFilters={[]}
/>,
{ initSeries }
);
Expand All @@ -69,7 +69,7 @@ describe('FilterExpanded', function () {
series={mockSeries}
label={'Browser Family'}
field={USER_AGENT_NAME}
filters={[]}
baseFilters={[]}
/>,
{ initSeries }
);
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('FilterExpanded', function () {
series={mockUxSeries}
label={'Browser Family'}
field={USER_AGENT_NAME}
filters={[]}
baseFilters={[]}
/>,
{ initSeries }
);
Expand Down
Loading