Skip to content

Commit

Permalink
Merge branch 'main' into align-pipeline-card-styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikep86 authored Dec 8, 2023
2 parents 456b9de + a5528e3 commit 458637c
Show file tree
Hide file tree
Showing 37 changed files with 1,605 additions and 1,481 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@
"deep-freeze-strict": "^1.1.1",
"deepmerge": "^4.2.2",
"del": "^6.1.0",
"diff": "^5.1.0",
"elastic-apm-node": "^4.2.0",
"email-addresses": "^5.0.0",
"execa": "^5.1.1",
Expand Down Expand Up @@ -1032,6 +1033,7 @@
"react": "^17.0.2",
"react-ace": "^7.0.5",
"react-color": "^2.13.8",
"react-diff-view": "^3.2.0",
"react-dom": "^17.0.2",
"react-dropzone": "^4.2.9",
"react-fast-compare": "^2.0.4",
Expand Down Expand Up @@ -1092,6 +1094,7 @@
"type-detect": "^4.0.8",
"typescript-fsa": "^3.0.0",
"typescript-fsa-reducers": "^1.2.2",
"unidiff": "^1.0.4",
"unified": "9.2.2",
"use-resize-observer": "^9.1.0",
"usng.js": "^0.4.5",
Expand Down Expand Up @@ -1348,6 +1351,7 @@
"@types/dedent": "^0.7.0",
"@types/deep-freeze-strict": "^1.1.0",
"@types/delete-empty": "^2.0.0",
"@types/diff": "^5.0.8",
"@types/ejs": "^3.0.6",
"@types/enzyme": "^3.10.12",
"@types/eslint": "^8.44.2",
Expand Down Expand Up @@ -1511,7 +1515,6 @@
"debug": "^2.6.9",
"delete-empty": "^2.0.0",
"dependency-check": "^4.1.0",
"diff": "^4.0.1",
"dpdm": "3.9.0",
"ejs": "^3.1.8",
"enzyme": "^3.11.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ it('rewrites ftr reports with minimal changes', async () => {
reportPath: Path.resolve(__dirname, './__fixtures__/ftr_report.xml'),
});

expect(createPatch('ftr.xml', FTR_REPORT, xml, { context: 0 })).toMatchInlineSnapshot(`
expect(createPatch('ftr.xml', FTR_REPORT, xml)).toMatchInlineSnapshot(`
Index: ftr.xml
===================================================================
--- ftr.xml [object Object]
--- ftr.xml
+++ ftr.xml
@@ -1,53 +1,56 @@
‹?xml version="1.0" encoding="utf-8"?›
Expand Down Expand Up @@ -149,10 +149,10 @@ it('rewrites jest reports with minimal changes', async () => {
reportPath: Path.resolve(__dirname, './__fixtures__/jest_report.xml'),
});

expect(createPatch('jest.xml', JEST_REPORT, xml, { context: 0 })).toMatchInlineSnapshot(`
expect(createPatch('jest.xml', JEST_REPORT, xml)).toMatchInlineSnapshot(`
Index: jest.xml
===================================================================
--- jest.xml [object Object]
--- jest.xml
+++ jest.xml
@@ -3,13 +3,17 @@
‹testsuite name="x-pack/legacy/plugins/code/server/lsp/abstract_launcher.test.ts" timestamp="2019-06-07T03:42:21" time="14.504" tests="5" failures="1" skipped="0" file="/var/lib/jenkins/workspace/elastic+kibana+master/JOB/x-pack-intake/node/immutable/kibana/x-pack/legacy/plugins/code/server/lsp/abstract_launcher.test.ts"›
Expand Down Expand Up @@ -196,10 +196,10 @@ it('rewrites mocha reports with minimal changes', async () => {
reportPath: Path.resolve(__dirname, './__fixtures__/mocha_report.xml'),
});

expect(createPatch('mocha.xml', MOCHA_REPORT, xml, { context: 0 })).toMatchInlineSnapshot(`
expect(createPatch('mocha.xml', MOCHA_REPORT, xml)).toMatchInlineSnapshot(`
Index: mocha.xml
===================================================================
--- mocha.xml [object Object]
--- mocha.xml
+++ mocha.xml
@@ -1,13 +1,16 @@
‹?xml version="1.0" encoding="utf-8"?›
Expand Down Expand Up @@ -273,10 +273,10 @@ it('rewrites cypress reports with minimal changes', async () => {
reportPath: Path.resolve(__dirname, './__fixtures__/cypress_report.xml'),
});

expect(createPatch('cypress.xml', CYPRESS_REPORT, xml, { context: 0 })).toMatchInlineSnapshot(`
expect(createPatch('cypress.xml', CYPRESS_REPORT, xml)).toMatchInlineSnapshot(`
Index: cypress.xml
===================================================================
--- cypress.xml [object Object]
--- cypress.xml
+++ cypress.xml
@@ -1,25 +1,16 @@
-‹?xml version="1.0" encoding="UTF-8"?›
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { translateTimeRelativeToWeek } from './translate_timestamp';

describe('translateTimeRelativeToWeek', () => {
const sourceReference = '2018-01-02T00:00:00'; // Tuesday
const targetReference = '2018-04-25T18:24:58.650'; // Wednesday

describe('2 weeks before', () => {
test('should properly adjust timestamp when day is before targetReference day of week', () => {
const source = '2017-12-18T23:50:00'; // Monday, -2 week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-09T23:50:00'); // Monday 2 week before targetReference week
});

test('should properly adjust timestamp when day is same as targetReference day of week', () => {
const source = '2017-12-20T23:50:00'; // Wednesday, -2 week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-11T23:50:00'); // Wednesday 2 week before targetReference week
});

test('should properly adjust timestamp when day is after targetReference day of week', () => {
const source = '2017-12-22T16:16:50'; // Friday, -2 week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-13T16:16:50'); // Friday 2 week before targetReference week
});
});

describe('week before', () => {
test('should properly adjust timestamp when day is before targetReference day of week', () => {
const source = '2017-12-25T23:50:00'; // Monday, -1 week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-16T23:50:00'); // Monday 1 week before targetReference week
});

test('should properly adjust timestamp when day is same as targetReference day of week', () => {
const source = '2017-12-27T23:50:00'; // Wednesday, -1 week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-18T23:50:00'); // Wednesday 1 week before targetReference week
});

test('should properly adjust timestamp when day is after targetReference day of week', () => {
const source = '2017-12-29T16:16:50'; // Friday, -1 week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-20T16:16:50'); // Friday 1 week before targetReference week
});
});

describe('same week', () => {
test('should properly adjust timestamp when day is before targetReference day of week', () => {
const source = '2018-01-01T23:50:00'; // Monday, same week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-23T23:50:00'); // Monday same week as targetReference
});

test('should properly adjust timestamp when day is same as targetReference day of week', () => {
const source = '2018-01-03T23:50:00'; // Wednesday, same week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-25T23:50:00'); // Wednesday same week as targetReference
});

test('should properly adjust timestamp when day is after targetReference day of week', () => {
const source = '2018-01-05T16:16:50'; // Friday, same week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-27T16:16:50'); // Friday same week as targetReference
});
});

describe('week after', () => {
test('should properly adjust timestamp when day is before targetReference day of week', () => {
const source = '2018-01-08T23:50:00'; // Monday, 1 week after relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-04-30T23:50:00'); // Monday 1 week after targetReference week
});

test('should properly adjust timestamp when day is same as targetReference day of week', () => {
const source = '2018-01-10T23:50:00'; // Wednesday, same week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-05-02T23:50:00'); // Wednesday 1 week after targetReference week
});

test('should properly adjust timestamp when day is after targetReference day of week', () => {
const source = '2018-01-12T16:16:50'; // Friday, same week relative to sourceReference
const timestamp = translateTimeRelativeToWeek(source, sourceReference, targetReference);
expect(timestamp).toBe('2018-05-04T16:16:50'); // Friday 1 week after targetReference week
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

const MILLISECONDS_IN_DAY = 86400000;
const MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24;

function iso8601ToDateIgnoringTime(iso8601: string) {
const split = iso8601.split('-');
Expand All @@ -24,13 +24,13 @@ export function dateToIso8601IgnoringTime(date: Date) {
const dateItem = new Date(date);
const year = dateItem.getFullYear();
const month = dateItem.getMonth() + 1;
const monthString = month < 10 ? `0${month}` : `${month}`;
const dateString = dateItem.getDate() < 10 ? `0${dateItem.getDate()}` : `${dateItem.getDate()}`;
const monthString = String.prototype.padStart.call(month, 2, '0');
const dateString = String.prototype.padStart.call(dateItem.getDate(), 2, '0');
return `${year}-${monthString}-${dateString}`;
}

// Translate source timestamp by targetReference timestamp,
// perserving the distance between source and sourceReference
// preserving the distance between source and sourceReference
export function translateTimeRelativeToDifference(
source: string,
sourceReference: any,
Expand All @@ -47,7 +47,7 @@ export function translateTimeRelativeToDifference(
}

// Translate source timestamp by targetReference timestamp,
// perserving the week distance between source and sourceReference and day of week of the source timestamp
// preserving the week distance between source and sourceReference and day of week of the source timestamp
export function translateTimeRelativeToWeek(
source: string,
sourceReference: any,
Expand All @@ -59,10 +59,11 @@ export function translateTimeRelativeToWeek(
// If these dates were in the same week, how many days apart would they be?
const dayOfWeekDelta = sourceReferenceDate.getDay() - targetReferenceDate.getDay();

// If we pretend that the targetReference is actually the same day of the week as the
// sourceReference, then we can translate the source to the target while preserving their
// days of the week.
// Given that we assume the target reference is in the same week as the source reference
// and we'd computed how many days apart they'd be apart.
// We then compute the value of the days apart in milliseconds to normalize our target reference
const normalizationDelta = dayOfWeekDelta * MILLISECONDS_IN_DAY;

const normalizedTargetReference = dateToIso8601IgnoringTime(
new Date(targetReferenceDate.getTime() + normalizationDelta)
);
Expand Down
19 changes: 13 additions & 6 deletions test/api_integration/apis/home/sample_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

import expect from '@kbn/expect';
import type { Response } from 'superagent';
import differenceInMilliseconds from 'date-fns/differenceInMilliseconds';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const es = getService('es');

const MILLISECOND_IN_WEEK = 1000 * 60 * 60 * 24 * 7;
const SPACES = ['default', 'other'];
/**
* default ID of the flights overview dashboard
* @see src/plugins/home/server/services/sample_data/data_sets/flights/index.ts
* @see {@link src/plugins/home/server/services/sample_data/data_sets/flights/index.ts}
*/
const FLIGHTS_OVERVIEW_DASHBOARD_ID = '7adfa750-4c81-11e8-b3d7-01146121b73d';
const FLIGHTS_CANVAS_APPLINK_PATH =
Expand Down Expand Up @@ -72,8 +72,14 @@ export default function ({ getService }: FtrProviderContext) {
});
});

// FLAKY: https://github.com/elastic/kibana/issues/166572
describe.skip('dates', () => {
describe('dates', () => {
// dates being compared are not arbitrary, but rather the dates of the earliest and latest timestamp of the flight sample data
// this can be verified in the flight data archive here {@link src/plugins/home/server/services/sample_data/data_sets/flights/flights.json.gz}
const sampleDataTimeIntervalInMS = differenceInMilliseconds(
new Date('2018-02-11T14:54:34'),
new Date('2018-01-01T00:00:00')
);

it('should load elasticsearch index containing sample data with dates relative to current time', async () => {
const resp = await es.search<{ timestamp: string }>({
index: 'kibana_sample_data_flights',
Expand All @@ -83,8 +89,9 @@ export default function ({ getService }: FtrProviderContext) {
const doc = resp.hits.hits[0];
const docMilliseconds = Date.parse(doc._source!.timestamp);
const nowMilliseconds = Date.now();

const delta = Math.abs(nowMilliseconds - docMilliseconds);
expect(delta).to.be.lessThan(MILLISECOND_IN_WEEK * 5);
expect(delta).to.be.lessThan(sampleDataTimeIntervalInMS);
});

it('should load elasticsearch index containing sample data with dates relative to now parameter', async () => {
Expand All @@ -100,7 +107,7 @@ export default function ({ getService }: FtrProviderContext) {
const docMilliseconds = Date.parse(doc._source!.timestamp);
const nowMilliseconds = Date.parse(nowString);
const delta = Math.abs(nowMilliseconds - docMilliseconds);
expect(delta).to.be.lessThan(MILLISECOND_IN_WEEK * 5);
expect(delta).to.be.lessThan(sampleDataTimeIntervalInMS);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* 2.0.
*/

import React from 'react';
import React, { useState } from 'react';

import { useActions, useValues } from 'kea';

import { EuiSelectable, useIsWithinMaxBreakpoint } from '@elastic/eui';
import { EuiSelectable, useEuiTheme, useIsWithinMaxBreakpoint } from '@elastic/eui';

import { MLInferenceLogic, MLInferencePipelineOption } from './ml_inference_logic';
import { PipelineSelectOption, PipelineSelectOptionProps } from './pipeline_select_option';
Expand All @@ -23,6 +23,15 @@ export const PipelineSelect: React.FC = () => {

const { pipelineName } = configuration;

const { euiTheme } = useEuiTheme();
const largeScreenRowHeight = euiTheme.base * 6;
const smallScreenRowHeight = euiTheme.base * 8;
const maxVisibleOptions = 4.5;
const rowHeight: number = useIsWithinMaxBreakpoint('s')
? smallScreenRowHeight
: largeScreenRowHeight;
const [height, setHeight] = useState(maxVisibleOptions * rowHeight);

const getPipelineOptions = (
pipelineOptions: MLInferencePipelineOption[]
): PipelineSelectOptionProps[] => {
Expand Down Expand Up @@ -50,14 +59,20 @@ export const PipelineSelect: React.FC = () => {
options={getPipelineOptions(existingInferencePipelines)}
listProps={{
bordered: true,
rowHeight: useIsWithinMaxBreakpoint('s') ? 120 : 90,
showIcons: true,
onFocusBadge: false,
rowHeight,
}}
searchProps={{
onChange: (_, matchingOptions) => {
setHeight(Math.min(maxVisibleOptions, matchingOptions.length) * rowHeight);
},
}}
searchable
singleSelection="always"
onChange={onChange}
renderOption={renderPipelineOption}
height={height}
>
{(list, search) => (
<>
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/monitoring/common/types/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ export interface AlertNodeStats {
}

export interface AlertCpuUsageNodeStats extends AlertNodeStats {
cpuUsage?: number;
limitsChanged?: boolean;
unexpectedLimits?: boolean;
cpuUsage: number;
containerUsage: number;
containerPeriods: number;
containerQuota: number;
}

export interface AlertThreadPoolRejectionsStats {
Expand Down
Loading

0 comments on commit 458637c

Please sign in to comment.