Skip to content

Commit

Permalink
Merge branch 'master' into reporting/register-routes-synchro
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jun 15, 2020
2 parents 6e8d535 + e3ba5e5 commit 7d604bc
Show file tree
Hide file tree
Showing 49 changed files with 1,825 additions and 794 deletions.
18 changes: 9 additions & 9 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@
/src/core/public/i18n/ @elastic/kibana-localization
/packages/kbn-i18n/ @elastic/kibana-localization

# Pulse
/packages/kbn-analytics/ @elastic/pulse
/src/plugins/kibana_usage_collection/ @elastic/pulse
/src/plugins/newsfeed/ @elastic/pulse
/src/plugins/telemetry/ @elastic/pulse
/src/plugins/telemetry_collection_manager/ @elastic/pulse
/src/plugins/telemetry_management_section/ @elastic/pulse
/src/plugins/usage_collection/ @elastic/pulse
/x-pack/plugins/telemetry_collection_xpack/ @elastic/pulse
# Kibana Telemetry
/packages/kbn-analytics/ @elastic/kibana-telemetry
/src/plugins/kibana_usage_collection/ @elastic/kibana-telemetry
/src/plugins/newsfeed/ @elastic/kibana-telemetry
/src/plugins/telemetry/ @elastic/kibana-telemetry
/src/plugins/telemetry_collection_manager/ @elastic/kibana-telemetry
/src/plugins/telemetry_management_section/ @elastic/kibana-telemetry
/src/plugins/usage_collection/ @elastic/kibana-telemetry
/x-pack/plugins/telemetry_collection_xpack/ @elastic/kibana-telemetry

# Kibana Alerting Services
/x-pack/plugins/alerts/ @elastic/kibana-alerting-services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ import { act } from '@testing-library/react-hooks';
import { expectTextsInDocument } from '../../../../../utils/testHelpers';

describe('ErrorMarker', () => {
const mark = {
const mark = ({
id: 'agent',
offset: 10000,
type: 'errorMark',
verticalLine: true,
error: {
trace: { id: '123' },
transaction: { id: '456' },
error: { grouping_key: '123' },
error: {
grouping_key: '123',
log: {
message:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
},
},
service: { name: 'bar' },
},
serviceColor: '#fff',
} as ErrorMark;
} as unknown) as ErrorMark;

function openPopover(errorMark: ErrorMark) {
const component = render(<ErrorMarker mark={errorMark} />);
Expand Down Expand Up @@ -76,4 +82,34 @@ describe('ErrorMarker', () => {
const errorLink = component.getByTestId('errorLink') as HTMLAnchorElement;
expect(getKueryDecoded(errorLink.hash)).toEqual('kuery=');
});
it('truncates the error message text', () => {
const { trace, transaction, ...withoutTraceAndTransaction } = mark.error;
const newMark = {
...mark,
error: withoutTraceAndTransaction,
} as ErrorMark;
const component = openPopover(newMark);
const errorLink = component.getByTestId('errorLink') as HTMLAnchorElement;
expect(errorLink.innerHTML).toHaveLength(241);
});

describe('when the error message is not longer than 240 characters', () => {
it('truncates the error message text', () => {
const newMark = ({
...mark,
error: {
...mark.error,
error: {
grouping_key: '123',
log: {
message: 'Blah.',
},
},
},
} as unknown) as ErrorMark;
const component = openPopover(newMark);
const errorLink = component.getByTestId('errorLink') as HTMLAnchorElement;
expect(errorLink.innerHTML).toHaveLength(5);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const TimeLegend = styled(Legend)`
const ErrorLink = styled(ErrorDetailLink)`
display: block;
margin: ${px(units.half)} 0 ${px(units.half)} 0;
overflow-wrap: break-word;
`;

const Button = styled(Legend)`
Expand All @@ -42,6 +43,16 @@ const Button = styled(Legend)`
align-items: flex-end;
`;

// We chose 240 characters because it fits most error messages and it's still easily readable on a screen.
function truncateMessage(errorMessage?: string) {
const maxLength = 240;
if (typeof errorMessage === 'string' && errorMessage.length > maxLength) {
return errorMessage.substring(0, maxLength) + '…';
} else {
return errorMessage;
}
}

export const ErrorMarker: React.FC<Props> = ({ mark }) => {
const { urlParams } = useUrlParams();
const [isPopoverOpen, showPopover] = useState(false);
Expand Down Expand Up @@ -73,6 +84,10 @@ export const ErrorMarker: React.FC<Props> = ({ mark }) => {
rangeTo,
};

const errorMessage =
error.error.log?.message || error.error.exception?.[0]?.message;
const truncatedErrorMessage = truncateMessage(errorMessage);

return (
<EuiPopover
id="popover"
Expand All @@ -99,8 +114,9 @@ export const ErrorMarker: React.FC<Props> = ({ mark }) => {
serviceName={error.service.name}
errorGroupId={error.error.grouping_key}
query={query}
title={errorMessage}
>
{error.error.log?.message || error.error.exception?.[0]?.message}
{truncatedErrorMessage}
</ErrorLink>
</EuiText>
</Popover>
Expand Down
18 changes: 18 additions & 0 deletions x-pack/plugins/infra/common/alerting/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export * from './types';
export const INFRA_ALERT_PREVIEW_PATH = '/api/infra/alerting/preview';

export const TOO_MANY_BUCKETS_PREVIEW_EXCEPTION = 'TOO_MANY_BUCKETS_PREVIEW_EXCEPTION';
export interface TooManyBucketsPreviewExceptionMetadata {
TOO_MANY_BUCKETS_PREVIEW_EXCEPTION: any;
maxBuckets: number;
}
export const isTooManyBucketsPreviewException = (
value: any
): value is TooManyBucketsPreviewExceptionMetadata =>
Boolean(value && value.TOO_MANY_BUCKETS_PREVIEW_EXCEPTION);
82 changes: 82 additions & 0 deletions x-pack/plugins/infra/common/alerting/metrics/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as rt from 'io-ts';

// TODO: Have threshold and inventory alerts import these types from this file instead of from their
// local directories
export const METRIC_THRESHOLD_ALERT_TYPE_ID = 'metrics.alert.threshold';
export const METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID = 'metrics.alert.inventory.threshold';

export enum Comparator {
GT = '>',
LT = '<',
GT_OR_EQ = '>=',
LT_OR_EQ = '<=',
BETWEEN = 'between',
OUTSIDE_RANGE = 'outside',
}

export enum Aggregators {
COUNT = 'count',
AVERAGE = 'avg',
SUM = 'sum',
MIN = 'min',
MAX = 'max',
RATE = 'rate',
CARDINALITY = 'cardinality',
P95 = 'p95',
P99 = 'p99',
}

// Alert Preview API
const baseAlertRequestParamsRT = rt.intersection([
rt.partial({
filterQuery: rt.union([rt.string, rt.undefined]),
sourceId: rt.string,
}),
rt.type({
lookback: rt.union([rt.literal('h'), rt.literal('d'), rt.literal('w'), rt.literal('M')]),
criteria: rt.array(rt.any),
alertInterval: rt.string,
}),
]);

const metricThresholdAlertPreviewRequestParamsRT = rt.intersection([
baseAlertRequestParamsRT,
rt.partial({
groupBy: rt.union([rt.string, rt.array(rt.string), rt.undefined]),
}),
rt.type({
alertType: rt.literal(METRIC_THRESHOLD_ALERT_TYPE_ID),
}),
]);
export type MetricThresholdAlertPreviewRequestParams = rt.TypeOf<
typeof metricThresholdAlertPreviewRequestParamsRT
>;

const inventoryAlertPreviewRequestParamsRT = rt.intersection([
baseAlertRequestParamsRT,
rt.type({
nodeType: rt.string,
alertType: rt.literal(METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID),
}),
]);

export const alertPreviewRequestParamsRT = rt.union([
metricThresholdAlertPreviewRequestParamsRT,
inventoryAlertPreviewRequestParamsRT,
]);

export const alertPreviewSuccessResponsePayloadRT = rt.type({
numberOfGroups: rt.number,
resultTotals: rt.type({
fired: rt.number,
noData: rt.number,
error: rt.number,
tooManyBuckets: rt.number,
}),
});
Loading

0 comments on commit 7d604bc

Please sign in to comment.