Skip to content

Commit

Permalink
Merge branch 'main' into rule-execution-log-feedback-part-deux
Browse files Browse the repository at this point in the history
  • Loading branch information
spong authored May 3, 2022
2 parents 7f6ae5d + 02c21aa commit f8d0266
Show file tree
Hide file tree
Showing 51 changed files with 746 additions and 196 deletions.
1 change: 1 addition & 0 deletions .buildkite/scripts/pipelines/pull_request/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const SKIPPABLE_PATHS = [
/^\.github\//,
/\.md$/,
/^\.backportrc\.json$/,
/^nav-kibana-dev\.docnav\.json$/,
];

const REQUIRED_PATHS = [
Expand Down
7 changes: 6 additions & 1 deletion packages/kbn-ci-stats-reporter/src/ci_stats_reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { parseConfig, Config, CiStatsMetadata } from '@kbn/ci-stats-core';
import type { CiStatsTestGroupInfo, CiStatsTestRun } from './ci_stats_test_group_types';

const BASE_URL = 'https://ci-stats.kibana.dev';
const SECOND = 1000;
const MINUTE = 60 * SECOND;

function limitMetaStrings(meta: CiStatsMetadata) {
return Object.fromEntries(
Expand Down Expand Up @@ -107,6 +109,7 @@ interface ReqOptions {
body: any;
bodyDesc: string;
query?: AxiosRequestConfig['params'];
timeout?: number;
}

/** Object that helps report data to the ci-stats service */
Expand Down Expand Up @@ -282,6 +285,7 @@ export class CiStatsReporter {
},
bodyDesc: `[${group.name}/${group.type}] Chunk of ${bufferBytes} bytes`,
body: buffer.join('\n'),
timeout: 5 * MINUTE,
});
buffer.length = 0;
bufferBytes = 0;
Expand Down Expand Up @@ -336,7 +340,7 @@ export class CiStatsReporter {
}
}

private async req<T>({ auth, body, bodyDesc, path, query }: ReqOptions) {
private async req<T>({ auth, body, bodyDesc, path, query, timeout = 60 * SECOND }: ReqOptions) {
let attempt = 0;
const maxAttempts = 5;

Expand Down Expand Up @@ -365,6 +369,7 @@ export class CiStatsReporter {
// if it can be serialized into a string, send it
maxBodyLength: Infinity,
maxContentLength: Infinity,
timeout,
});

return resp.data;
Expand Down
11 changes: 8 additions & 3 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,8 @@ var _ciStatsCore = __webpack_require__("../../node_modules/@kbn/ci-stats-core/ta
*/
// @ts-expect-error not "public", but necessary to prevent Jest shimming from breaking things
const BASE_URL = 'https://ci-stats.kibana.dev';
const SECOND = 1000;
const MINUTE = 60 * SECOND;

function limitMetaStrings(meta) {
return Object.fromEntries(Object.entries(meta).map(([key, value]) => {
Expand Down Expand Up @@ -1782,7 +1784,8 @@ class CiStatsReporter {
groupType: group.type
},
bodyDesc: `[${group.name}/${group.type}] Chunk of ${bufferBytes} bytes`,
body: buffer.join('\n')
body: buffer.join('\n'),
timeout: 5 * MINUTE
});
buffer.length = 0;
bufferBytes = 0;
Expand Down Expand Up @@ -1851,7 +1854,8 @@ class CiStatsReporter {
body,
bodyDesc,
path,
query
query,
timeout = 60 * SECOND
}) {
let attempt = 0;
const maxAttempts = 5;
Expand Down Expand Up @@ -1879,7 +1883,8 @@ class CiStatsReporter {
adapter: _http.default,
// if it can be serialized into a string, send it
maxBodyLength: Infinity,
maxContentLength: Infinity
maxContentLength: Infinity,
timeout
});
return resp.data;
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { euiLightVars as themeLight, euiDarkVars as themeDark } from '@kbn/ui-theme';
import { i18n } from '@kbn/i18n';
import { DiscoverGridContext } from './discover_grid_context';
import { ElasticSearchHit } from '../../types';

Expand All @@ -36,6 +37,11 @@ export const SelectButton = ({ rowIndex, setCellProps }: EuiDataGridCellValueEle
const id = useMemo(() => getDocId(doc), [doc]);
const checked = useMemo(() => selectedDocs.includes(id), [selectedDocs, id]);

const toggleDocumentSelectionLabel = i18n.translate('discover.grid.selectDoc', {
defaultMessage: `Select document '{rowNumber}'`,
values: { rowNumber: rowIndex + 1 },
});

useEffect(() => {
if (expanded && doc && expanded._id === doc._id) {
setCellProps({
Expand All @@ -51,7 +57,7 @@ export const SelectButton = ({ rowIndex, setCellProps }: EuiDataGridCellValueEle
return (
<EuiCheckbox
id={id}
label=""
aria-label={toggleDocumentSelectionLabel}
checked={checked}
data-test-subj={`dscGridSelectDoc-${id}`}
onChange={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { random, mean } from 'lodash';
import { SanitizedRule, AlertSummary } from '../types';
import { IValidatedEvent } from '@kbn/event-log-plugin/server';
import { IValidatedEvent, millisToNanos, nanosToMillis } from '@kbn/event-log-plugin/server';
import { EVENT_LOG_ACTIONS, EVENT_LOG_PROVIDER, LEGACY_EVENT_LOG_ACTIONS } from '../plugin';
import { alertSummaryFromEventLog } from './alert_summary_from_event_log';

Expand Down Expand Up @@ -643,7 +643,7 @@ export class EventsFactory {
event: {
provider: EVENT_LOG_PROVIDER,
action: EVENT_LOG_ACTIONS.execute,
duration: random(2000, 180000) * 1000 * 1000,
duration: millisToNanos(random(2000, 180000)),
},
};

Expand Down Expand Up @@ -710,7 +710,7 @@ export class EventsFactory {
return this.events
.filter((ev) => ev?.event?.action === 'execute' && ev?.event?.duration !== undefined)
.reduce((res: Record<string, number>, ev) => {
res[ev?.['@timestamp']!] = ev?.event?.duration! / (1000 * 1000);
res[ev?.['@timestamp']!] = nanosToMillis(ev?.event?.duration!);
return res;
}, {});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
*/

import { mean } from 'lodash';
import { IEvent } from '@kbn/event-log-plugin/server';
import { IEvent, nanosToMillis } from '@kbn/event-log-plugin/server';
import { SanitizedRule, AlertSummary, AlertStatus } from '../types';
import { EVENT_LOG_ACTIONS, EVENT_LOG_PROVIDER, LEGACY_EVENT_LOG_ACTIONS } from '../plugin';

const Millis2Nanos = 1000 * 1000;

export interface AlertSummaryFromEventLogParams {
rule: SanitizedRule<{ bar: boolean }>;
events: IEvent[];
Expand Down Expand Up @@ -111,7 +109,7 @@ export function alertSummaryFromEventLog(params: AlertSummaryFromEventLogParams)
}

if (event?.event?.duration) {
const eventDirationMillis = event.event.duration / Millis2Nanos;
const eventDirationMillis = nanosToMillis(event.event.duration);
eventDurations.push(eventDirationMillis);
eventDurationsWithTimestamp[event['@timestamp']!] = eventDirationMillis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function createAlertEventLogRecordObject(params: CreateAlertEventLogRecor
category: [ruleType.producer],
...(state?.start ? { start: state.start as string } : {}),
...(state?.end ? { end: state.end as string } : {}),
...(state?.duration !== undefined ? { duration: state.duration as number } : {}),
...(state?.duration !== undefined ? { duration: state.duration as string } : {}),
},
kibana: {
alert: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ const findResults = {
kind: 'action',
start: '2022-03-23T17:37:07.105Z',
end: '2022-03-23T17:37:07.105Z',
duration: 0,
duration: '0',
outcome: 'failure',
},
kibana: {
Expand Down Expand Up @@ -345,7 +345,7 @@ const findResults = {
kind: 'action',
start: '2022-03-23T17:37:07.101Z',
end: '2022-03-23T17:37:07.102Z',
duration: 1000000,
duration: '1000000',
outcome: 'failure',
},
kibana: {
Expand Down Expand Up @@ -394,7 +394,7 @@ const findResults = {
kind: 'action',
start: '2022-03-23T17:37:07.098Z',
end: '2022-03-23T17:37:07.098Z',
duration: 0,
duration: '0',
outcome: 'failure',
},
kibana: {
Expand Down Expand Up @@ -443,7 +443,7 @@ const findResults = {
kind: 'action',
start: '2022-03-23T17:37:07.095Z',
end: '2022-03-23T17:37:07.096Z',
duration: 1000000,
duration: '1000000',
outcome: 'failure',
},
kibana: {
Expand Down Expand Up @@ -492,7 +492,7 @@ const findResults = {
kind: 'action',
start: '2022-03-23T17:37:07.084Z',
end: '2022-03-23T17:37:07.086Z',
duration: 2000000,
duration: '2000000',
outcome: 'failure',
},
kibana: {
Expand Down Expand Up @@ -543,7 +543,7 @@ const findResults = {
start: '2022-03-23T17:23:05.131Z',
outcome: 'failure',
end: '2022-03-23T17:23:05.248Z',
duration: 117000000,
duration: '117000000',
reason: 'execute',
},
kibana: {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/task_runner/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DATE_1969 = '1969-12-31T00:00:00.000Z';
export const DATE_1970 = '1970-01-01T00:00:00.000Z';
export const DATE_1970_5_MIN = '1969-12-31T23:55:00.000Z';
export const DATE_9999 = '9999-12-31T12:34:56.789Z';
export const MOCK_DURATION = 86400000000000;
export const MOCK_DURATION = '86400000000000';

export const SAVED_OBJECT = {
id: '1',
Expand Down
Loading

0 comments on commit f8d0266

Please sign in to comment.