From 639f8b7ca2ae74ebd4c2775e956a9c58742dcf9d Mon Sep 17 00:00:00 2001 From: Uladzislau Lasitsa Date: Mon, 13 Jul 2020 13:28:42 +0300 Subject: [PATCH 01/28] Migrated agg table karma tests to jest (#71224) * Migrated karma tests to jest * Add comment Co-authored-by: Elastic Machine --- .../public/__tests__/vis_type_table/legacy.ts | 39 ----- .../public/agg_table/agg_table.test.js} | 153 ++++++++++-------- .../public/agg_table/agg_table_group.test.js} | 50 +++--- .../public/agg_table}/tabified_data.js | 0 .../public/paginated_table/rows.js | 5 +- 5 files changed, 125 insertions(+), 122 deletions(-) delete mode 100644 src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/legacy.ts rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_table/agg_table.js => plugins/vis_type_table/public/agg_table/agg_table.test.js} (75%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_table/agg_table_group.js => plugins/vis_type_table/public/agg_table/agg_table_group.test.js} (74%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_table => plugins/vis_type_table/public/agg_table}/tabified_data.js (100%) diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/legacy.ts b/src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/legacy.ts deleted file mode 100644 index 216afe5920408..0000000000000 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/legacy.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -import { PluginInitializerContext } from 'kibana/public'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { npStart, npSetup } from 'ui/new_platform'; -import { - TableVisPlugin, - TablePluginSetupDependencies, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../../../plugins/vis_type_table/public/plugin'; - -const plugins: Readonly = { - expressions: npSetup.plugins.expressions, - visualizations: npSetup.plugins.visualizations, -}; - -const pluginInstance = new TableVisPlugin({} as PluginInitializerContext); - -export const setup = pluginInstance.setup(npSetup.core, plugins); -export const start = pluginInstance.start(npStart.core, { - data: npStart.plugins.data, - kibanaLegacy: npStart.plugins.kibanaLegacy, -}); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/agg_table.js b/src/plugins/vis_type_table/public/agg_table/agg_table.test.js similarity index 75% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/agg_table.js rename to src/plugins/vis_type_table/public/agg_table/agg_table.test.js index 88eb299e3c3a8..0362bd55963d9 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/agg_table.js +++ b/src/plugins/vis_type_table/public/agg_table/agg_table.test.js @@ -19,44 +19,71 @@ import $ from 'jquery'; import moment from 'moment'; -import ngMock from 'ng_mock'; -import expect from '@kbn/expect'; +import angular from 'angular'; +import 'angular-mocks'; import sinon from 'sinon'; -import './legacy'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { npStart } from 'ui/new_platform'; import { round } from 'lodash'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { getInnerAngular } from '../../../../../../plugins/vis_type_table/public/get_inner_angular'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { initTableVisLegacyModule } from '../../../../../../plugins/vis_type_table/public/table_vis_legacy_module'; +import { getFieldFormatsRegistry } from '../../../../test_utils/public/stub_field_formats'; +import { coreMock } from '../../../../core/public/mocks'; +import { initAngularBootstrap } from '../../../kibana_legacy/public'; +import { setUiSettings } from '../../../data/public/services'; +import { UI_SETTINGS } from '../../../data/public/'; +import { CSV_SEPARATOR_SETTING, CSV_QUOTE_VALUES_SETTING } from '../../../share/public'; + +import { setFormatService } from '../services'; +import { getInnerAngular } from '../get_inner_angular'; +import { initTableVisLegacyModule } from '../table_vis_legacy_module'; import { tabifiedData } from './tabified_data'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { configureAppAngularModule } from '../../../../../../plugins/kibana_legacy/public/angular'; + +const uiSettings = new Map(); describe('Table Vis - AggTable Directive', function () { + const core = coreMock.createStart(); + + core.uiSettings.set = jest.fn((key, value) => { + uiSettings.set(key, value); + }); + + core.uiSettings.get = jest.fn((key) => { + const defaultValues = { + dateFormat: 'MMM D, YYYY @ HH:mm:ss.SSS', + 'dateFormat:tz': 'UTC', + [UI_SETTINGS.SHORT_DOTS_ENABLE]: true, + [UI_SETTINGS.FORMAT_CURRENCY_DEFAULT_PATTERN]: '($0,0.[00])', + [UI_SETTINGS.FORMAT_NUMBER_DEFAULT_PATTERN]: '0,0.[000]', + [UI_SETTINGS.FORMAT_PERCENT_DEFAULT_PATTERN]: '0,0.[000]%', + [UI_SETTINGS.FORMAT_NUMBER_DEFAULT_LOCALE]: 'en', + [UI_SETTINGS.FORMAT_DEFAULT_TYPE_MAP]: {}, + [CSV_SEPARATOR_SETTING]: ',', + [CSV_QUOTE_VALUES_SETTING]: true, + }; + + return defaultValues[key] || uiSettings.get(key); + }); + let $rootScope; let $compile; let settings; const initLocalAngular = () => { - const tableVisModule = getInnerAngular('kibana/table_vis', npStart.core); - configureAppAngularModule(tableVisModule, npStart.core, true); + const tableVisModule = getInnerAngular('kibana/table_vis', core); initTableVisLegacyModule(tableVisModule); }; - beforeEach(initLocalAngular); - - beforeEach(ngMock.module('kibana/table_vis')); - beforeEach( - ngMock.inject(function ($injector, config) { + beforeEach(() => { + setUiSettings(core.uiSettings); + setFormatService(getFieldFormatsRegistry(core)); + initAngularBootstrap(); + initLocalAngular(); + angular.mock.module('kibana/table_vis'); + angular.mock.inject(($injector, config) => { settings = config; $rootScope = $injector.get('$rootScope'); $compile = $injector.get('$compile'); - }) - ); + }); + }); let $scope; beforeEach(function () { @@ -66,7 +93,7 @@ describe('Table Vis - AggTable Directive', function () { $scope.$destroy(); }); - it('renders a simple response properly', function () { + test('renders a simple response properly', function () { $scope.dimensions = { metrics: [{ accessor: 0, format: { id: 'number' }, params: {} }], buckets: [], @@ -78,12 +105,12 @@ describe('Table Vis - AggTable Directive', function () { ); $scope.$digest(); - expect($el.find('tbody').length).to.be(1); - expect($el.find('td').length).to.be(1); - expect($el.find('td').text()).to.eql('1,000'); + expect($el.find('tbody').length).toBe(1); + expect($el.find('td').length).toBe(1); + expect($el.find('td').text()).toEqual('1,000'); }); - it('renders nothing if the table is empty', function () { + test('renders nothing if the table is empty', function () { $scope.dimensions = {}; $scope.table = null; const $el = $compile('')( @@ -91,10 +118,10 @@ describe('Table Vis - AggTable Directive', function () { ); $scope.$digest(); - expect($el.find('tbody').length).to.be(0); + expect($el.find('tbody').length).toBe(0); }); - it('renders a complex response properly', async function () { + test('renders a complex response properly', async function () { $scope.dimensions = { buckets: [ { accessor: 0, params: {} }, @@ -112,37 +139,37 @@ describe('Table Vis - AggTable Directive', function () { $compile($el)($scope); $scope.$digest(); - expect($el.find('tbody').length).to.be(1); + expect($el.find('tbody').length).toBe(1); const $rows = $el.find('tbody tr'); - expect($rows.length).to.be.greaterThan(0); + expect($rows.length).toBeGreaterThan(0); function validBytes(str) { const num = str.replace(/,/g, ''); if (num !== '-') { - expect(num).to.match(/^\d+$/); + expect(num).toMatch(/^\d+$/); } } $rows.each(function () { // 6 cells in every row const $cells = $(this).find('td'); - expect($cells.length).to.be(6); + expect($cells.length).toBe(6); const txts = $cells.map(function () { return $(this).text().trim(); }); // two character country code - expect(txts[0]).to.match(/^(png|jpg|gif|html|css)$/); + expect(txts[0]).toMatch(/^(png|jpg|gif|html|css)$/); validBytes(txts[1]); // country - expect(txts[2]).to.match(/^\w\w$/); + expect(txts[2]).toMatch(/^\w\w$/); validBytes(txts[3]); // os - expect(txts[4]).to.match(/^(win|mac|linux)$/); + expect(txts[4]).toMatch(/^(win|mac|linux)$/); validBytes(txts[5]); }); }); @@ -153,9 +180,9 @@ describe('Table Vis - AggTable Directive', function () { moment.tz.setDefault(settings.get('dateFormat:tz')); } - const off = $scope.$on('change:config.dateFormat:tz', setDefaultTimezone); const oldTimezoneSetting = settings.get('dateFormat:tz'); settings.set('dateFormat:tz', 'UTC'); + setDefaultTimezone(); $scope.dimensions = { buckets: [ @@ -181,24 +208,24 @@ describe('Table Vis - AggTable Directive', function () { $compile($el)($scope); $scope.$digest(); - expect($el.find('tfoot').length).to.be(1); + expect($el.find('tfoot').length).toBe(1); const $rows = $el.find('tfoot tr'); - expect($rows.length).to.be(1); + expect($rows.length).toBe(1); const $cells = $($rows[0]).find('th'); - expect($cells.length).to.be(6); + expect($cells.length).toBe(6); for (let i = 0; i < 6; i++) { - expect($($cells[i]).text().trim()).to.be(expected[i]); + expect($($cells[i]).text().trim()).toBe(expected[i]); } settings.set('dateFormat:tz', oldTimezoneSetting); - off(); + setDefaultTimezone(); } - it('as count', async function () { + test('as count', async function () { await totalsRowTest('count', ['18', '18', '18', '18', '18', '18']); }); - it('as min', async function () { + test('as min', async function () { await totalsRowTest('min', [ '', '2014-09-28', @@ -208,7 +235,7 @@ describe('Table Vis - AggTable Directive', function () { '11', ]); }); - it('as max', async function () { + test('as max', async function () { await totalsRowTest('max', [ '', '2014-10-03', @@ -218,16 +245,16 @@ describe('Table Vis - AggTable Directive', function () { '837', ]); }); - it('as avg', async function () { + test('as avg', async function () { await totalsRowTest('avg', ['', '', '87,221.5', '', '64.667', '206.833']); }); - it('as sum', async function () { + test('as sum', async function () { await totalsRowTest('sum', ['', '', '1,569,987', '', '1,164', '3,723']); }); }); describe('aggTable.toCsv()', function () { - it('escapes rows and columns properly', function () { + test('escapes rows and columns properly', function () { const $el = $compile('')( $scope ); @@ -244,12 +271,12 @@ describe('Table Vis - AggTable Directive', function () { rows: [{ a: 1, b: 2, c: '"foobar"' }], }; - expect(aggTable.toCsv()).to.be( + expect(aggTable.toCsv()).toBe( 'one,two,"with double-quotes("")"' + '\r\n' + '1,2,"""foobar"""' + '\r\n' ); }); - it('exports rows and columns properly', async function () { + test('exports rows and columns properly', async function () { $scope.dimensions = { buckets: [ { accessor: 0, params: {} }, @@ -274,7 +301,7 @@ describe('Table Vis - AggTable Directive', function () { $tableScope.table = $scope.table; const raw = aggTable.toCsv(false); - expect(raw).to.be( + expect(raw).toBe( '"extension: Descending","Average bytes","geo.src: Descending","Average bytes","machine.os: Descending","Average bytes"' + '\r\n' + 'png,412032,IT,9299,win,0' + @@ -304,7 +331,7 @@ describe('Table Vis - AggTable Directive', function () { ); }); - it('exports formatted rows and columns properly', async function () { + test('exports formatted rows and columns properly', async function () { $scope.dimensions = { buckets: [ { accessor: 0, params: {} }, @@ -332,7 +359,7 @@ describe('Table Vis - AggTable Directive', function () { $tableScope.formattedColumns[0].formatter.convert = (v) => `${v}_formatted`; const formatted = aggTable.toCsv(true); - expect(formatted).to.be( + expect(formatted).toBe( '"extension: Descending","Average bytes","geo.src: Descending","Average bytes","machine.os: Descending","Average bytes"' + '\r\n' + '"png_formatted",412032,IT,9299,win,0' + @@ -363,7 +390,7 @@ describe('Table Vis - AggTable Directive', function () { }); }); - it('renders percentage columns', async function () { + test('renders percentage columns', async function () { $scope.dimensions = { buckets: [ { accessor: 0, params: {} }, @@ -390,8 +417,8 @@ describe('Table Vis - AggTable Directive', function () { $scope.$digest(); const $headings = $el.find('th'); - expect($headings.length).to.be(7); - expect($headings.eq(3).text().trim()).to.be('Average bytes percentages'); + expect($headings.length).toBe(7); + expect($headings.eq(3).text().trim()).toBe('Average bytes percentages'); const countColId = $scope.table.columns.find((col) => col.name === $scope.percentageCol).id; const counts = $scope.table.rows.map((row) => row[countColId]); @@ -400,7 +427,7 @@ describe('Table Vis - AggTable Directive', function () { $percentageColValues.each((i, value) => { const percentage = `${round((counts[i] / total) * 100, 3)}%`; - expect(value).to.be(percentage); + expect(value).toBe(percentage); }); }); @@ -420,7 +447,7 @@ describe('Table Vis - AggTable Directive', function () { window.Blob = origBlob; }); - it('calls _saveAs properly', function () { + test('calls _saveAs properly', function () { const $el = $compile('')($scope); $scope.$digest(); @@ -440,19 +467,19 @@ describe('Table Vis - AggTable Directive', function () { aggTable.csv.filename = 'somefilename.csv'; aggTable.exportAsCsv(); - expect(saveAs.callCount).to.be(1); + expect(saveAs.callCount).toBe(1); const call = saveAs.getCall(0); - expect(call.args[0]).to.be.a(FakeBlob); - expect(call.args[0].slices).to.eql([ + expect(call.args[0]).toBeInstanceOf(FakeBlob); + expect(call.args[0].slices).toEqual([ 'one,two,"with double-quotes("")"' + '\r\n' + '1,2,"""foobar"""' + '\r\n', ]); - expect(call.args[0].opts).to.eql({ + expect(call.args[0].opts).toEqual({ type: 'text/plain;charset=utf-8', }); - expect(call.args[1]).to.be('somefilename.csv'); + expect(call.args[1]).toBe('somefilename.csv'); }); - it('should use the export-title attribute', function () { + test('should use the export-title attribute', function () { const expected = 'export file name'; const $el = $compile( `` @@ -468,7 +495,7 @@ describe('Table Vis - AggTable Directive', function () { $tableScope.exportTitle = expected; $scope.$digest(); - expect(aggTable.csv.filename).to.equal(`${expected}.csv`); + expect(aggTable.csv.filename).toEqual(`${expected}.csv`); }); }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/agg_table_group.js b/src/plugins/vis_type_table/public/agg_table/agg_table_group.test.js similarity index 74% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/agg_table_group.js rename to src/plugins/vis_type_table/public/agg_table/agg_table_group.test.js index 99b397167009d..43913eed32f90 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/agg_table_group.js +++ b/src/plugins/vis_type_table/public/agg_table/agg_table_group.test.js @@ -18,38 +18,50 @@ */ import $ from 'jquery'; -import ngMock from 'ng_mock'; +import angular from 'angular'; +import 'angular-mocks'; import expect from '@kbn/expect'; -import './legacy'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { getInnerAngular } from '../../../../../../plugins/vis_type_table/public/get_inner_angular'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { initTableVisLegacyModule } from '../../../../../../plugins/vis_type_table/public/table_vis_legacy_module'; + +import { getFieldFormatsRegistry } from '../../../../test_utils/public/stub_field_formats'; +import { coreMock } from '../../../../core/public/mocks'; +import { initAngularBootstrap } from '../../../kibana_legacy/public'; +import { setUiSettings } from '../../../data/public/services'; +import { setFormatService } from '../services'; +import { getInnerAngular } from '../get_inner_angular'; +import { initTableVisLegacyModule } from '../table_vis_legacy_module'; import { tabifiedData } from './tabified_data'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { npStart } from 'ui/new_platform'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { configureAppAngularModule } from '../../../../../../plugins/kibana_legacy/public/angular'; + +const uiSettings = new Map(); describe('Table Vis - AggTableGroup Directive', function () { + const core = coreMock.createStart(); let $rootScope; let $compile; + core.uiSettings.set = jest.fn((key, value) => { + uiSettings.set(key, value); + }); + + core.uiSettings.get = jest.fn((key) => { + return uiSettings.get(key); + }); + const initLocalAngular = () => { - const tableVisModule = getInnerAngular('kibana/table_vis', npStart.core); - configureAppAngularModule(tableVisModule, npStart.core, true); + const tableVisModule = getInnerAngular('kibana/table_vis', core); initTableVisLegacyModule(tableVisModule); }; - beforeEach(initLocalAngular); - - beforeEach(ngMock.module('kibana/table_vis')); - beforeEach( - ngMock.inject(function ($injector) { + beforeEach(() => { + setUiSettings(core.uiSettings); + setFormatService(getFieldFormatsRegistry(core)); + initAngularBootstrap(); + initLocalAngular(); + angular.mock.module('kibana/table_vis'); + angular.mock.inject(($injector) => { $rootScope = $injector.get('$rootScope'); $compile = $injector.get('$compile'); - }) - ); + }); + }); let $scope; beforeEach(function () { diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/tabified_data.js b/src/plugins/vis_type_table/public/agg_table/tabified_data.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_table/tabified_data.js rename to src/plugins/vis_type_table/public/agg_table/tabified_data.js diff --git a/src/plugins/vis_type_table/public/paginated_table/rows.js b/src/plugins/vis_type_table/public/paginated_table/rows.js index d2192a5843644..d8f01a10c63fa 100644 --- a/src/plugins/vis_type_table/public/paginated_table/rows.js +++ b/src/plugins/vis_type_table/public/paginated_table/rows.js @@ -19,6 +19,7 @@ import $ from 'jquery'; import _ from 'lodash'; +import angular from 'angular'; import tableCellFilterHtml from './table_cell_filter.html'; export function KbnRows($compile) { @@ -65,7 +66,9 @@ export function KbnRows($compile) { if (column.filterable && contentsIsDefined) { $cell = createFilterableCell(contents); - $cellContent = $cell.find('[data-cell-content]'); + // in jest tests 'angular' is using jqLite. In jqLite the method find lookups only by tags. + // Because of this, we should change a way how we get cell content so that tests will pass. + $cellContent = angular.element($cell[0].querySelector('[data-cell-content]')); } else { $cell = $cellContent = createCell(); } From 3fc8c7af258293e9c8045ac2fed046582aa84f9f Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Mon, 13 Jul 2020 13:47:12 +0300 Subject: [PATCH 02/28] Validate incoming url timerange (#70948) * validate incoming url timerange * adjust discover test * fix tests * stabilize tests * oops Co-authored-by: Elastic Machine --- src/plugins/data/public/public.api.md | 2 +- .../state_sync/connect_to_query_state.ts | 5 +- .../data/public/query/timefilter/index.ts | 1 + .../timefilter/lib/validate_timerange.test.ts | 52 +++++++++++++++++++ .../timefilter/lib/validate_timerange.ts | 28 ++++++++++ test/functional/apps/discover/_discover.js | 24 +++++---- 6 files changed, 98 insertions(+), 14 deletions(-) create mode 100644 src/plugins/data/public/query/timefilter/lib/validate_timerange.test.ts create mode 100644 src/plugins/data/public/query/timefilter/lib/validate_timerange.ts diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 01fcefe27df3e..b532bacf5df25 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1991,7 +1991,7 @@ export const UI_SETTINGS: { // src/plugins/data/public/index.ts:393:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:394:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:397:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:40:60 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:41:60 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:52:5 - (ae-forgotten-export) The symbol "createFiltersFromValueClickAction" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:53:5 - (ae-forgotten-export) The symbol "createFiltersFromRangeSelectAction" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:61:5 - (ae-forgotten-export) The symbol "IndexPatternSelectProps" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/data/public/query/state_sync/connect_to_query_state.ts b/src/plugins/data/public/query/state_sync/connect_to_query_state.ts index e74497a5053b4..2e62dac87f6ef 100644 --- a/src/plugins/data/public/query/state_sync/connect_to_query_state.ts +++ b/src/plugins/data/public/query/state_sync/connect_to_query_state.ts @@ -24,6 +24,7 @@ import { BaseStateContainer } from '../../../../kibana_utils/public'; import { QuerySetup, QueryStart } from '../query_service'; import { QueryState, QueryStateChange } from './types'; import { FilterStateStore, COMPARE_ALL_OPTIONS, compareFilters } from '../../../common'; +import { validateTimeRange } from '../timefilter'; /** * Helper to setup two-way syncing of global data and a state container @@ -159,9 +160,9 @@ export const connectToQueryState = ( // cloneDeep is required because services are mutating passed objects // and state in state container is frozen if (syncConfig.time) { - const time = state.time || timefilter.getTimeDefaults(); + const time = validateTimeRange(state.time) ? state.time : timefilter.getTimeDefaults(); if (!_.isEqual(time, timefilter.getTime())) { - timefilter.setTime(_.cloneDeep(time)); + timefilter.setTime(_.cloneDeep(time!)); } } diff --git a/src/plugins/data/public/query/timefilter/index.ts b/src/plugins/data/public/query/timefilter/index.ts index f71061677ceb7..19386c10ab59f 100644 --- a/src/plugins/data/public/query/timefilter/index.ts +++ b/src/plugins/data/public/query/timefilter/index.ts @@ -24,3 +24,4 @@ export { Timefilter, TimefilterContract } from './timefilter'; export { TimeHistory, TimeHistoryContract } from './time_history'; export { changeTimeFilter, convertRangeFilterToTimeRangeString } from './lib/change_time_filter'; export { extractTimeFilter } from './lib/extract_time_filter'; +export { validateTimeRange } from './lib/validate_timerange'; diff --git a/src/plugins/data/public/query/timefilter/lib/validate_timerange.test.ts b/src/plugins/data/public/query/timefilter/lib/validate_timerange.test.ts new file mode 100644 index 0000000000000..e20849c21a717 --- /dev/null +++ b/src/plugins/data/public/query/timefilter/lib/validate_timerange.test.ts @@ -0,0 +1,52 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { validateTimeRange } from './validate_timerange'; + +describe('Validate timerange', () => { + test('Validate no range', () => { + const ok = validateTimeRange(); + + expect(ok).toBe(false); + }); + test('normal range', () => { + const ok = validateTimeRange({ + to: 'now', + from: 'now-7d', + }); + + expect(ok).toBe(true); + }); + test('bad from time', () => { + const ok = validateTimeRange({ + to: 'nowa', + from: 'now-7d', + }); + + expect(ok).toBe(false); + }); + test('bad to time', () => { + const ok = validateTimeRange({ + to: 'now', + from: 'nowa-7d', + }); + + expect(ok).toBe(false); + }); +}); diff --git a/src/plugins/data/public/query/timefilter/lib/validate_timerange.ts b/src/plugins/data/public/query/timefilter/lib/validate_timerange.ts new file mode 100644 index 0000000000000..f9e4aa0ae1cab --- /dev/null +++ b/src/plugins/data/public/query/timefilter/lib/validate_timerange.ts @@ -0,0 +1,28 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import dateMath from '@elastic/datemath'; +import { TimeRange } from '../../../../common'; + +export function validateTimeRange(time?: TimeRange): boolean { + if (!time) return false; + const momentDateFrom = dateMath.parse(time.from); + const momentDateTo = dateMath.parse(time.to); + return !!(momentDateFrom && momentDateFrom.isValid() && momentDateTo && momentDateTo.isValid()); +} diff --git a/test/functional/apps/discover/_discover.js b/test/functional/apps/discover/_discover.js index 47741c1ab8a0d..94a271987ecdf 100644 --- a/test/functional/apps/discover/_discover.js +++ b/test/functional/apps/discover/_discover.js @@ -254,6 +254,19 @@ export default function ({ getService, getPageObjects }) { }); }); + describe('invalid time range in URL', function () { + it('should get the default timerange', async function () { + const prevTime = await PageObjects.timePicker.getTimeConfig(); + await PageObjects.common.navigateToUrl('discover', '#/?_g=(time:(from:now-15m,to:null))', { + useActualUrl: true, + }); + await PageObjects.header.awaitKibanaChrome(); + const time = await PageObjects.timePicker.getTimeConfig(); + expect(time.start).to.be(prevTime.start); + expect(time.end).to.be(prevTime.end); + }); + }); + describe('empty query', function () { it('should update the histogram timerange when the query is resubmitted', async function () { await kibanaServer.uiSettings.update({ @@ -268,17 +281,6 @@ export default function ({ getService, getPageObjects }) { }); }); - describe('invalid time range in URL', function () { - it('should display a "Invalid time range toast"', async function () { - await PageObjects.common.navigateToUrl('discover', '#/?_g=(time:(from:now-15m,to:null))', { - useActualUrl: true, - }); - await PageObjects.header.awaitKibanaChrome(); - const toastMessage = await PageObjects.common.closeToast(); - expect(toastMessage).to.be('Invalid time range'); - }); - }); - describe('managing fields', function () { it('should add a field, sort by it, remove it and also sorting by it', async function () { await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings(); From cd2d1b8053da9ca37b44fc3edc9c83bd72eecc46 Mon Sep 17 00:00:00 2001 From: MadameSheema Date: Mon, 13 Jul 2020 13:00:44 +0200 Subject: [PATCH 03/28] [SIEM][Detections] Fixes text layout in Schedule step (#71306) * fixes text layout in schedule step * Removes unused import Co-authored-by: Garrett Spong Co-authored-by: Elastic Machine --- .../rules/step_schedule_rule/index.tsx | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_schedule_rule/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_schedule_rule/index.tsx index 60855bc5fa25f..fa0f4dbd3668c 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_schedule_rule/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_schedule_rule/index.tsx @@ -6,7 +6,6 @@ import React, { FC, memo, useCallback, useEffect, useState } from 'react'; import deepEqual from 'fast-deep-equal'; -import styled from 'styled-components'; import { setFieldValue } from '../../../pages/detection_engine/rules/helpers'; import { @@ -25,10 +24,6 @@ interface StepScheduleRuleProps extends RuleStepProps { defaultValues?: ScheduleStepRule | null; } -const RestrictedWidthContainer = styled.div` - max-width: 300px; -`; - const stepScheduleDefaultValue = { interval: '5m', isNew: true, @@ -93,29 +88,25 @@ const StepScheduleRuleComponent: FC = ({ <>
- - - - - - + +
From 3a17e81626c619ef1cac98215ab689c510d1fea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Mon, 13 Jul 2020 13:59:13 +0200 Subject: [PATCH 04/28] Bump backport to 5.5.1 (#71408) --- package.json | 2 +- scripts/backport.js | 7 ++++- yarn.lock | 71 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index d58da61047d28..cf735d3663a63 100644 --- a/package.json +++ b/package.json @@ -408,7 +408,7 @@ "babel-eslint": "^10.0.3", "babel-jest": "^25.5.1", "babel-plugin-istanbul": "^6.0.0", - "backport": "5.4.6", + "backport": "5.5.1", "chai": "3.5.0", "chance": "1.0.18", "cheerio": "0.22.0", diff --git a/scripts/backport.js b/scripts/backport.js index 2094534e2c4b3..dca5912cfb133 100644 --- a/scripts/backport.js +++ b/scripts/backport.js @@ -18,5 +18,10 @@ */ require('../src/setup_node_env/node_version_validator'); +var process = require('process'); + +// forward command line args to backport +var args = process.argv.slice(2); + var backport = require('backport'); -backport.run(); +backport.run({}, args); diff --git a/yarn.lock b/yarn.lock index 153f4e89fe969..d2de2e19f36f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8512,16 +8512,16 @@ backo2@1.0.2: resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" integrity sha1-MasayLEpNjRj41s+u2n038+6eUc= -backport@5.4.6: - version "5.4.6" - resolved "https://registry.yarnpkg.com/backport/-/backport-5.4.6.tgz#8d8d8cb7c0df4079a40c6f4892f393daa92c1ef8" - integrity sha512-O3fFmQXKZN5sP6R6GwXeobsEgoFzvnuTGj8/TTTjxt1xA07pfhTY67M16rr0eiDDtuSxAqWMX9Zo+5Q3DuxfpQ== +backport@5.5.1: + version "5.5.1" + resolved "https://registry.yarnpkg.com/backport/-/backport-5.5.1.tgz#2eeddbdc4cfc0530119bdb2b0c3c30bc7ef574dd" + integrity sha512-vQuGrxxMx9H64ywqsIYUHL8+/xvPeP0nnBa0YQt5S+XqW7etaqOoa5dFW0c77ADdqjfLlGUIvtc2i6UrmqeFUQ== dependencies: axios "^0.19.2" dedent "^0.7.0" del "^5.1.0" find-up "^4.1.0" - inquirer "^7.2.0" + inquirer "^7.3.1" lodash.flatmap "^4.5.0" lodash.isempty "^4.4.0" lodash.isstring "^4.0.1" @@ -8531,7 +8531,7 @@ backport@5.4.6: safe-json-stringify "^1.2.0" strip-json-comments "^3.1.0" winston "^3.3.3" - yargs "^15.3.1" + yargs "^15.4.0" bail@^1.0.0: version "1.0.2" @@ -9710,6 +9710,14 @@ chalk@^3.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a" + integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + chalk@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f" @@ -10163,6 +10171,11 @@ cli-width@^2.0.0: resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639" integrity sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk= +cli-width@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" + integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== + clipboard@^2.0.0: version "2.0.4" resolved "https://registry.yarnpkg.com/clipboard/-/clipboard-2.0.4.tgz#836dafd66cf0fea5d71ce5d5b0bf6e958009112d" @@ -17870,21 +17883,21 @@ inquirer@^7.0.0: strip-ansi "^5.1.0" through "^2.3.6" -inquirer@^7.2.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.2.0.tgz#63ce99d823090de7eb420e4bb05e6f3449aa389a" - integrity sha512-E0c4rPwr9ByePfNlTIB8z51kK1s2n6jrHuJeEHENl/sbq2G/S1auvibgEwNR4uSyiU+PiYHqSwsgGiXjG8p5ZQ== +inquirer@^7.3.1: + version "7.3.1" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.1.tgz#ac6aba1abdfdd5ad34e7069370411edba17f6439" + integrity sha512-/+vOpHQHhoh90Znev8BXiuw1TDQ7IDxWsQnFafUEoK5+4uN5Eoz1p+3GqOj/NtzEi9VzWKQcV9Bm+i8moxedsA== dependencies: ansi-escapes "^4.2.1" - chalk "^3.0.0" + chalk "^4.1.0" cli-cursor "^3.1.0" - cli-width "^2.0.0" + cli-width "^3.0.0" external-editor "^3.0.3" figures "^3.0.0" - lodash "^4.17.15" + lodash "^4.17.16" mute-stream "0.0.8" run-async "^2.4.0" - rxjs "^6.5.3" + rxjs "^6.6.0" string-width "^4.1.0" strip-ansi "^6.0.0" through "^2.3.6" @@ -20903,7 +20916,7 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@4.17.11, lodash@4.17.15, lodash@>4.17.4, lodash@^4, lodash@^4.0.0, lodash@^4.0.1, lodash@^4.10.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.15.19, lodash@^4.17.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1, lodash@~4.17.10, lodash@~4.17.15, lodash@~4.17.5: +lodash@4.17.11, lodash@4.17.15, lodash@>4.17.4, lodash@^4, lodash@^4.0.0, lodash@^4.0.1, lodash@^4.10.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.15.19, lodash@^4.17.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.16, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1, lodash@~4.17.10, lodash@~4.17.15, lodash@~4.17.5: version "4.17.19" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== @@ -27539,7 +27552,7 @@ rxjs-marbles@^5.0.6: dependencies: fast-equals "^2.0.0" -rxjs@6.5.5, rxjs@^6.5.3, rxjs@^6.5.5: +rxjs@6.5.5, rxjs@^6.5.5: version "6.5.5" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.5.tgz#c5c884e3094c8cfee31bf27eb87e54ccfc87f9ec" integrity sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ== @@ -27560,6 +27573,13 @@ rxjs@^6.1.0, rxjs@^6.3.3, rxjs@^6.4.0, rxjs@^6.5.1: dependencies: tslib "^1.9.0" +rxjs@^6.6.0: + version "6.6.0" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.0.tgz#af2901eedf02e3a83ffa7f886240ff9018bbec84" + integrity sha512-3HMA8z/Oz61DUHe+SdOiQyzIf4tOx5oQHmMir7IZEu6TMqCLHT4LRcmNaUS0NwOz8VLvmmBduMsoaUvMaIiqzg== + dependencies: + tslib "^1.9.0" + safe-buffer@5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" @@ -33416,7 +33436,7 @@ yargs-parser@^11.1.1: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@^18.1.1: +yargs-parser@^18.1.1, yargs-parser@^18.1.2: version "18.1.3" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0" integrity sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ== @@ -33529,6 +33549,23 @@ yargs@^15.0.2, yargs@^15.1.0, yargs@^15.3.1, yargs@~15.3.1: y18n "^4.0.0" yargs-parser "^18.1.1" +yargs@^15.4.0: + version "15.4.1" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8" + integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A== + dependencies: + cliui "^6.0.0" + decamelize "^1.2.0" + find-up "^4.1.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^4.2.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^18.1.2" + yargs@^3.15.0: version "3.32.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.32.0.tgz#03088e9ebf9e756b69751611d2a5ef591482c995" From 5ccc7e9a540f965b154d1a2ad43194da78b83b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Mon, 13 Jul 2020 13:14:04 +0100 Subject: [PATCH 05/28] Usage collection speed improvements (#71317) * Usage collection speed improvements * Remove commented code --- .../server/collectors/find_all.ts | 2 +- .../server/collector/collector_set.ts | 51 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/plugins/kibana_usage_collection/server/collectors/find_all.ts b/src/plugins/kibana_usage_collection/server/collectors/find_all.ts index e6363551eba9c..5bb4f20b5c5b1 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/find_all.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/find_all.ts @@ -28,7 +28,7 @@ export async function findAll( savedObjectsClient: ISavedObjectsRepository, opts: SavedObjectsFindOptions ): Promise>> { - const { page = 1, perPage = 100, ...options } = opts; + const { page = 1, perPage = 10000, ...options } = opts; const { saved_objects: savedObjects, total } = await savedObjectsClient.find({ ...options, page, diff --git a/src/plugins/usage_collection/server/collector/collector_set.ts b/src/plugins/usage_collection/server/collector/collector_set.ts index 2b60a45c4065d..fce17a46b7168 100644 --- a/src/plugins/usage_collection/server/collector/collector_set.ts +++ b/src/plugins/usage_collection/server/collector/collector_set.ts @@ -83,14 +83,16 @@ export class CollectorSet { ); } - const collectorTypesNotReady: string[] = []; - let allReady = true; - for (const collector of collectorSet.collectors.values()) { - if (!(await collector.isReady())) { - allReady = false; - collectorTypesNotReady.push(collector.type); - } - } + const collectorTypesNotReady = ( + await Promise.all( + [...collectorSet.collectors.values()].map(async (collector) => { + if (!(await collector.isReady())) { + return collector.type; + } + }) + ) + ).filter((collectorType): collectorType is string => !!collectorType); + const allReady = collectorTypesNotReady.length === 0; if (!allReady && this.maximumWaitTimeForAllCollectorsInS >= 0) { const nowTimestamp = +new Date(); @@ -119,21 +121,24 @@ export class CollectorSet { callCluster: LegacyAPICaller, collectors: Map> = this.collectors ) => { - const responses = []; - for (const collector of collectors.values()) { - this.logger.debug(`Fetching data from ${collector.type} collector`); - try { - responses.push({ - type: collector.type, - result: await collector.fetch(callCluster), - }); - } catch (err) { - this.logger.warn(err); - this.logger.warn(`Unable to fetch data from ${collector.type} collector`); - } - } - - return responses; + const responses = await Promise.all( + [...collectors.values()].map(async (collector) => { + this.logger.debug(`Fetching data from ${collector.type} collector`); + try { + return { + type: collector.type, + result: await collector.fetch(callCluster), + }; + } catch (err) { + this.logger.warn(err); + this.logger.warn(`Unable to fetch data from ${collector.type} collector`); + } + }) + ); + + return responses.filter( + (response): response is { type: string; result: unknown } => typeof response !== 'undefined' + ); }; /* From 4e9d9812c7e20e98be929d0979e4ed2467ae5ea4 Mon Sep 17 00:00:00 2001 From: Marco Liberati Date: Mon, 13 Jul 2020 14:27:48 +0200 Subject: [PATCH 06/28] Fix TSVB table trend slope value (#71087) Co-authored-by: Elastic Machine --- package.json | 1 - .../lib/vis_data/table/process_bucket.js | 15 +- .../lib/vis_data/table/process_bucket.test.js | 159 ++++++++++++++++++ yarn.lock | 5 - 4 files changed, 170 insertions(+), 10 deletions(-) create mode 100644 src/plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.test.js diff --git a/package.json b/package.json index cf735d3663a63..7889909b15244 100644 --- a/package.json +++ b/package.json @@ -256,7 +256,6 @@ "redux-actions": "^2.6.5", "redux-thunk": "^2.3.0", "regenerator-runtime": "^0.13.3", - "regression": "2.0.1", "request": "^2.88.0", "require-in-the-middle": "^5.0.2", "reselect": "^4.0.0", diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.js b/src/plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.js index 0f2a7e153bde0..909cee456c31f 100644 --- a/src/plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.js +++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.js @@ -20,11 +20,20 @@ import { buildProcessorFunction } from '../build_processor_function'; import { processors } from '../response_processors/table'; import { getLastValue } from '../../../../common/get_last_value'; -import regression from 'regression'; import { first, get } from 'lodash'; import { overwrite } from '../helpers'; import { getActiveSeries } from '../helpers/get_active_series'; +function trendSinceLastBucket(data) { + if (data.length < 2) { + return 0; + } + const currentBucket = data[data.length - 1]; + const prevBucket = data[data.length - 2]; + const trend = (currentBucket[1] - prevBucket[1]) / currentBucket[1]; + return Number.isNaN(trend) ? 0 : trend; +} + export function processBucket(panel) { return (bucket) => { const series = getActiveSeries(panel).map((series) => { @@ -38,14 +47,12 @@ export function processBucket(panel) { }; overwrite(bucket, series.id, { meta, timeseries }); } - const processor = buildProcessorFunction(processors, bucket, panel, series); const result = first(processor([])); if (!result) return null; const data = get(result, 'data', []); - const linearRegression = regression.linear(data); + result.slope = trendSinceLastBucket(data); result.last = getLastValue(data); - result.slope = linearRegression.equation[0]; return result; }); return { key: bucket.key, series }; diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.test.js b/src/plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.test.js new file mode 100644 index 0000000000000..a4f9c71a5953d --- /dev/null +++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.test.js @@ -0,0 +1,159 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { processBucket } from './process_bucket'; + +function createValueObject(key, value, seriesId) { + return { key_as_string: `${key}`, doc_count: value, key, [seriesId]: { value } }; +} + +function createBucketsObjects(size, sort, seriesId) { + const values = Array(size) + .fill(1) + .map((_, i) => i + 1); + if (sort === 'flat') { + return values.map((_, i) => createValueObject(i, 1, seriesId)); + } + if (sort === 'desc') { + return values.reverse().map((v, i) => createValueObject(i, v, seriesId)); + } + return values.map((v, i) => createValueObject(i, v, seriesId)); +} + +function createPanel(series) { + return { + type: 'table', + time_field: '', + series: series.map((seriesId) => ({ + id: seriesId, + metrics: [{ id: seriesId, type: 'count' }], + trend_arrows: 1, + })), + }; +} + +function createBuckets(series) { + return [ + { key: 'A', trend: 'asc', size: 10 }, + { key: 'B', trend: 'desc', size: 10 }, + { key: 'C', trend: 'flat', size: 10 }, + { key: 'D', trend: 'asc', size: 1, expectedTrend: 'flat' }, + ].map(({ key, trend, size, expectedTrend }) => { + const baseObj = { + key, + expectedTrend: expectedTrend || trend, + }; + for (const seriesId of series) { + baseObj[seriesId] = { + meta: { + timeField: 'timestamp', + seriesId: seriesId, + }, + buckets: createBucketsObjects(size, trend, seriesId), + }; + } + return baseObj; + }); +} + +function trendChecker(trend, slope) { + switch (trend) { + case 'asc': + return slope > 0; + case 'desc': + return slope <= 0; + case 'flat': + return slope === 0; + default: + throw Error(`Slope value ${slope} not valid for trend "${trend}"`); + } +} + +describe('processBucket(panel)', () => { + describe('single metric panel', () => { + let panel; + const SERIES_ID = 'series-id'; + + beforeEach(() => { + panel = createPanel([SERIES_ID]); + }); + + test('return the correct trend direction', () => { + const bucketProcessor = processBucket(panel); + const buckets = createBuckets([SERIES_ID]); + for (const bucket of buckets) { + const result = bucketProcessor(bucket); + expect(result.key).toEqual(bucket.key); + expect(trendChecker(bucket.expectedTrend, result.series[0].slope)).toBeTruthy(); + } + }); + + test('properly handle 0 values for trend', () => { + const bucketProcessor = processBucket(panel); + const bucketforNaNResult = { + key: 'NaNScenario', + expectedTrend: 'flat', + [SERIES_ID]: { + meta: { + timeField: 'timestamp', + seriesId: SERIES_ID, + }, + buckets: [ + // this is a flat case, but 0/0 has not a valid number result + createValueObject(0, 0, SERIES_ID), + createValueObject(1, 0, SERIES_ID), + ], + }, + }; + const result = bucketProcessor(bucketforNaNResult); + expect(result.key).toEqual(bucketforNaNResult.key); + expect(trendChecker(bucketforNaNResult.expectedTrend, result.series[0].slope)).toEqual(true); + }); + + test('have the side effect to create the timeseries property if missing on bucket', () => { + const bucketProcessor = processBucket(panel); + const buckets = createBuckets([SERIES_ID]); + for (const bucket of buckets) { + bucketProcessor(bucket); + expect(bucket[SERIES_ID].buckets).toBeUndefined(); + expect(bucket[SERIES_ID].timeseries).toBeDefined(); + } + }); + }); + + describe('multiple metrics panel', () => { + let panel; + const SERIES = ['series-id-1', 'series-id-2']; + + beforeEach(() => { + panel = createPanel(SERIES); + }); + + test('return the correct trend direction', () => { + const bucketProcessor = processBucket(panel); + const buckets = createBuckets(SERIES); + for (const bucket of buckets) { + const result = bucketProcessor(bucket); + expect(result.key).toEqual(bucket.key); + expect(trendChecker(bucket.expectedTrend, result.series[0].slope)).toBeTruthy(); + expect(trendChecker(bucket.expectedTrend, result.series[1].slope)).toBeTruthy(); + } + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index d2de2e19f36f5..290713d32d333 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26736,11 +26736,6 @@ regjsparser@^0.6.4: dependencies: jsesc "~0.5.0" -regression@2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/regression/-/regression-2.0.1.tgz#8d29c3e8224a10850c35e337e85a8b2fac3b0c87" - integrity sha1-jSnD6CJKEIUMNeM36FqLL6w7DIc= - rehype-parse@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/rehype-parse/-/rehype-parse-6.0.0.tgz#f681555f2598165bee2c778b39f9073d17b16bca" From a7d3b6d3442113dd7d34d2b4cde9ed4e3d532df4 Mon Sep 17 00:00:00 2001 From: Paul Tavares <56442535+paul-tavares@users.noreply.github.com> Date: Mon, 13 Jul 2020 08:51:36 -0400 Subject: [PATCH 07/28] [Security Solution][Endpoint] Policy Details handling saving over version changes (http 409) (#71386) * Handle applying update on latest Package Config if 1st update generated 409 * Unit Tests to cover the handling of http 409 --- .../policy/store/policy_details/index.test.ts | 310 +++++++++++++----- .../policy/store/policy_details/middleware.ts | 24 +- .../policy/store/policy_details/selectors.ts | 16 +- 3 files changed, 262 insertions(+), 88 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts index 102fd40c97672..d3ec0670d29c5 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/index.test.ts @@ -5,130 +5,270 @@ */ import { PolicyDetailsState } from '../../types'; -import { createStore, Dispatch, Store } from 'redux'; -import { policyDetailsReducer, PolicyDetailsAction } from './index'; +import { applyMiddleware, createStore, Dispatch, Store } from 'redux'; +import { policyDetailsReducer, PolicyDetailsAction, policyDetailsMiddlewareFactory } from './index'; import { policyConfig } from './selectors'; import { clone } from '../../models/policy_details_config'; import { factory as policyConfigFactory } from '../../../../../../common/endpoint/models/policy_config'; +import { PolicyData } from '../../../../../../common/endpoint/types'; +import { + createSpyMiddleware, + MiddlewareActionSpyHelper, +} from '../../../../../common/store/test_utils'; +import { + AppContextTestRender, + createAppRootMockRenderer, +} from '../../../../../common/mock/endpoint'; +import { HttpFetchOptions } from 'kibana/public'; describe('policy details: ', () => { - let store: Store; + let store: Store; let getState: typeof store['getState']; let dispatch: Dispatch; + let policyItem: PolicyData; - beforeEach(() => { - store = createStore(policyDetailsReducer); - getState = store.getState; - dispatch = store.dispatch; - - dispatch({ - type: 'serverReturnedPolicyDetailsData', - payload: { - policyItem: { - id: '', - name: '', - description: '', - created_at: '', - created_by: '', - updated_at: '', - updated_by: '', - config_id: '', + const generateNewPolicyItemMock = (): PolicyData => { + return { + id: '', + name: '', + description: '', + created_at: '', + created_by: '', + updated_at: '', + updated_by: '', + config_id: '', + enabled: true, + output_id: '', + inputs: [ + { + type: 'endpoint', enabled: true, - output_id: '', - inputs: [ - { - type: 'endpoint', - enabled: true, - streams: [], - config: { - artifact_manifest: { - value: { - manifest_version: 'WzAsMF0=', - schema_version: 'v1', - artifacts: {}, - }, - }, - policy: { - value: policyConfigFactory(), - }, + streams: [], + config: { + artifact_manifest: { + value: { + manifest_version: 'WzAsMF0=', + schema_version: 'v1', + artifacts: {}, }, }, - ], - namespace: '', - package: { - name: '', - title: '', - version: '', + policy: { + value: policyConfigFactory(), + }, }, - revision: 1, }, + ], + namespace: '', + package: { + name: '', + title: '', + version: '', }, - }); + revision: 1, + }; + }; + + beforeEach(() => { + policyItem = generateNewPolicyItemMock(); }); - describe('when the user has enabled windows process events', () => { + describe('When interacting with policy form', () => { beforeEach(() => { - const config = policyConfig(getState()); - if (!config) { - throw new Error(); - } - - const newPayload1 = clone(config); - newPayload1.windows.events.process = true; + store = createStore(policyDetailsReducer); + getState = store.getState; + dispatch = store.dispatch; dispatch({ - type: 'userChangedPolicyConfig', - payload: { policyConfig: newPayload1 }, + type: 'serverReturnedPolicyDetailsData', + payload: { + policyItem, + }, }); }); - it('windows process events is enabled', () => { - const config = policyConfig(getState()); - expect(config!.windows.events.process).toEqual(true); + describe('when the user has enabled windows process events', () => { + beforeEach(() => { + const config = policyConfig(getState()); + if (!config) { + throw new Error(); + } + + const newPayload1 = clone(config); + newPayload1.windows.events.process = true; + + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload1 }, + }); + }); + + it('windows process events is enabled', () => { + const config = policyConfig(getState()); + expect(config!.windows.events.process).toEqual(true); + }); }); - }); - describe('when the user has enabled mac file events', () => { - beforeEach(() => { - const config = policyConfig(getState()); - if (!config) { - throw new Error(); - } + describe('when the user has enabled mac file events', () => { + beforeEach(() => { + const config = policyConfig(getState()); + if (!config) { + throw new Error(); + } - const newPayload1 = clone(config); - newPayload1.mac.events.file = true; + const newPayload1 = clone(config); + newPayload1.mac.events.file = true; - dispatch({ - type: 'userChangedPolicyConfig', - payload: { policyConfig: newPayload1 }, + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload1 }, + }); + }); + + it('mac file events is enabled', () => { + const config = policyConfig(getState()); + expect(config!.mac.events.file).toEqual(true); }); }); - it('mac file events is enabled', () => { - const config = policyConfig(getState()); - expect(config!.mac.events.file).toEqual(true); + describe('when the user has enabled linux process events', () => { + beforeEach(() => { + const config = policyConfig(getState()); + if (!config) { + throw new Error(); + } + + const newPayload1 = clone(config); + newPayload1.linux.events.file = true; + + dispatch({ + type: 'userChangedPolicyConfig', + payload: { policyConfig: newPayload1 }, + }); + }); + + it('linux file events is enabled', () => { + const config = policyConfig(getState()); + expect(config!.linux.events.file).toEqual(true); + }); }); }); - describe('when the user has enabled linux process events', () => { + describe('when saving policy data', () => { + let waitForAction: MiddlewareActionSpyHelper['waitForAction']; + let http: AppContextTestRender['coreStart']['http']; + beforeEach(() => { - const config = policyConfig(getState()); - if (!config) { - throw new Error(); - } + let actionSpyMiddleware: MiddlewareActionSpyHelper['actionSpyMiddleware']; + const { coreStart, depsStart } = createAppRootMockRenderer(); + ({ actionSpyMiddleware, waitForAction } = createSpyMiddleware()); + http = coreStart.http; - const newPayload1 = clone(config); - newPayload1.linux.events.file = true; + store = createStore( + policyDetailsReducer, + undefined, + applyMiddleware(policyDetailsMiddlewareFactory(coreStart, depsStart), actionSpyMiddleware) + ); + getState = store.getState; + dispatch = store.dispatch; dispatch({ - type: 'userChangedPolicyConfig', - payload: { policyConfig: newPayload1 }, + type: 'serverReturnedPolicyDetailsData', + payload: { + policyItem, + }, + }); + }); + + it('should handle HTTP 409 (version missmatch) and still save the policy', async () => { + policyItem.inputs[0].config.policy.value.windows.events.dns = false; + + const http409Error: Error & { response?: { status: number } } = new Error('conflict'); + http409Error.response = { status: 409 }; + + // The most current Policy Item. Differences to `artifact_manifest` should be preserved, + // while the policy data should be overwritten on next `put`. + const mostCurrentPolicyItem = generateNewPolicyItemMock(); + mostCurrentPolicyItem.inputs[0].config.artifact_manifest.value.manifest_version = 'updated'; + mostCurrentPolicyItem.inputs[0].config.policy.value.windows.events.dns = true; + + http.put.mockRejectedValueOnce(http409Error); + http.get.mockResolvedValueOnce({ + item: mostCurrentPolicyItem, + success: true, + }); + http.put.mockResolvedValueOnce({ + item: policyItem, + success: true, + }); + + dispatch({ type: 'userClickedPolicyDetailsSaveButton' }); + await waitForAction('serverReturnedUpdatedPolicyDetailsData'); + + expect(http.put).toHaveBeenCalledTimes(2); + + const lastPutCallPayload = ((http.put.mock.calls[ + http.put.mock.calls.length - 1 + ] as unknown) as [string, HttpFetchOptions])[1]; + + expect(JSON.parse(lastPutCallPayload.body as string)).toEqual({ + name: '', + description: '', + config_id: '', + enabled: true, + output_id: '', + inputs: [ + { + type: 'endpoint', + enabled: true, + streams: [], + config: { + artifact_manifest: { + value: { manifest_version: 'updated', schema_version: 'v1', artifacts: {} }, + }, + policy: { + value: { + windows: { + events: { + dll_and_driver_load: true, + dns: false, + file: true, + network: true, + process: true, + registry: true, + security: true, + }, + malware: { mode: 'prevent' }, + logging: { file: 'info' }, + }, + mac: { + events: { process: true, file: true, network: true }, + malware: { mode: 'prevent' }, + logging: { file: 'info' }, + }, + linux: { + events: { process: true, file: true, network: true }, + logging: { file: 'info' }, + }, + }, + }, + }, + }, + ], + namespace: '', + package: { name: '', title: '', version: '' }, }); }); - it('linux file events is enabled', () => { - const config = policyConfig(getState()); - expect(config!.linux.events.file).toEqual(true); + it('should not attempt to handle other HTTP errors', async () => { + const http400Error: Error & { response?: { status: number } } = new Error('not found'); + + http400Error.response = { status: 400 }; + http.put.mockRejectedValueOnce(http400Error); + dispatch({ type: 'userClickedPolicyDetailsSaveButton' }); + + const failureAction = await waitForAction('serverReturnedPolicyDetailsUpdateFailure'); + expect(failureAction.payload?.error).toBeInstanceOf(Error); + expect(failureAction.payload?.error?.message).toEqual('not found'); }); }); }); diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts index cfa1a478619b7..1d9e3c2198b28 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/middleware.ts @@ -4,12 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ +import { IHttpFetchError } from 'kibana/public'; import { PolicyDetailsState, UpdatePolicyResponse } from '../../types'; import { policyIdFromParams, isOnPolicyDetailsPage, policyDetails, policyDetailsForUpdate, + getPolicyDataForUpdate, } from './selectors'; import { sendGetPackageConfig, @@ -66,7 +68,27 @@ export const policyDetailsMiddlewareFactory: ImmutableMiddlewareFactory { + if (!error.response || error.response.status !== 409) { + return Promise.reject(error); + } + // Handle 409 error (version conflict) here, by using the latest document + // for the package config and adding the updated policy to it, ensuring that + // any recent updates to `manifest_artifacts` are retained. + return sendGetPackageConfig(http, id).then((packageConfig) => { + const latestUpdatedPolicyItem = packageConfig.item; + latestUpdatedPolicyItem.inputs[0].config.policy = + updatedPolicyItem.inputs[0].config.policy; + + return sendPutPackageConfig( + http, + id, + getPolicyDataForUpdate(latestUpdatedPolicyItem) as NewPolicyData + ); + }); + } + ); } catch (error) { dispatch({ type: 'serverReturnedPolicyDetailsUpdateFailure', diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts index d2a5c1b7e14a3..cce0adf36bcce 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts +++ b/x-pack/plugins/security_solution/public/management/pages/policy/store/policy_details/selectors.ts @@ -11,6 +11,7 @@ import { Immutable, NewPolicyData, PolicyConfig, + PolicyData, UIPolicyConfig, } from '../../../../../../common/endpoint/types'; import { factory as policyConfigFactory } from '../../../../../../common/endpoint/models/policy_config'; @@ -20,6 +21,18 @@ import { ManagementRoutePolicyDetailsParams } from '../../../../types'; /** Returns the policy details */ export const policyDetails = (state: Immutable) => state.policyItem; +/** + * Given a Policy Data (package config) object, return back a new object with only the field + * needed for an Update/Create API action + * @param policy + */ +export const getPolicyDataForUpdate = ( + policy: PolicyData | Immutable +): NewPolicyData | Immutable => { + const { id, revision, created_by, created_at, updated_by, updated_at, ...newPolicy } = policy; + return newPolicy; +}; + /** * Return only the policy structure accepted for update/create */ @@ -27,8 +40,7 @@ export const policyDetailsForUpdate: ( state: Immutable ) => Immutable | undefined = createSelector(policyDetails, (policy) => { if (policy) { - const { id, revision, created_by, created_at, updated_by, updated_at, ...newPolicy } = policy; - return newPolicy; + return getPolicyDataForUpdate(policy); } }); From f4b4dc5faa42da788b7968f30d86c45b18a5c0d9 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Mon, 13 Jul 2020 14:55:11 +0200 Subject: [PATCH 08/28] [uiActions] Improve context menu keyboard support (#70705) * Improves position resolution logic by also tracking last clicked element. * Adds ownFocus prop, so can pick menu item with keyboard. * Also track if target element was removed from DOM. In that case tries to use previous element. won't work all the time, but works nicely in case context menu trigger by item in other context menu. Co-authored-by: Elastic Machine --- .../context_menu/open_context_menu.test.ts | 84 +++++++++++++ .../public/context_menu/open_context_menu.tsx | 117 ++++++++++++------ 2 files changed, 161 insertions(+), 40 deletions(-) create mode 100644 src/plugins/ui_actions/public/context_menu/open_context_menu.test.ts diff --git a/src/plugins/ui_actions/public/context_menu/open_context_menu.test.ts b/src/plugins/ui_actions/public/context_menu/open_context_menu.test.ts new file mode 100644 index 0000000000000..77ce04ba24b35 --- /dev/null +++ b/src/plugins/ui_actions/public/context_menu/open_context_menu.test.ts @@ -0,0 +1,84 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { createInteractionPositionTracker } from './open_context_menu'; +import { fireEvent } from '@testing-library/dom'; + +let targetEl: Element; +const top = 100; +const left = 100; +const right = 200; +const bottom = 200; +beforeEach(() => { + targetEl = document.createElement('div'); + jest.spyOn(targetEl, 'getBoundingClientRect').mockImplementation(() => ({ + top, + left, + right, + bottom, + width: right - left, + height: bottom - top, + x: left, + y: top, + toJSON: () => {}, + })); + document.body.append(targetEl); +}); +afterEach(() => { + targetEl.remove(); +}); + +test('should use last clicked element position if mouse position is outside target element', () => { + const { resolveLastPosition } = createInteractionPositionTracker(); + + fireEvent.click(targetEl, { clientX: 0, clientY: 0 }); + const { x, y } = resolveLastPosition(); + + expect(y).toBe(bottom); + expect(x).toBe(left + (right - left) / 2); +}); + +test('should use mouse position if mouse inside clicked element', () => { + const { resolveLastPosition } = createInteractionPositionTracker(); + + const mouseX = 150; + const mouseY = 150; + fireEvent.click(targetEl, { clientX: mouseX, clientY: mouseY }); + + const { x, y } = resolveLastPosition(); + + expect(y).toBe(mouseX); + expect(x).toBe(mouseY); +}); + +test('should use position of previous element, if latest element is no longer in DOM', () => { + const { resolveLastPosition } = createInteractionPositionTracker(); + + const detachedElement = document.createElement('div'); + const spy = jest.spyOn(detachedElement, 'getBoundingClientRect'); + + fireEvent.click(targetEl); + fireEvent.click(detachedElement); + + const { x, y } = resolveLastPosition(); + + expect(y).toBe(bottom); + expect(x).toBe(left + (right - left) / 2); + expect(spy).not.toBeCalled(); +}); diff --git a/src/plugins/ui_actions/public/context_menu/open_context_menu.tsx b/src/plugins/ui_actions/public/context_menu/open_context_menu.tsx index 5892c184f8a81..0d9a4c7be5670 100644 --- a/src/plugins/ui_actions/public/context_menu/open_context_menu.tsx +++ b/src/plugins/ui_actions/public/context_menu/open_context_menu.tsx @@ -26,14 +26,86 @@ import ReactDOM from 'react-dom'; let activeSession: ContextMenuSession | null = null; const CONTAINER_ID = 'contextMenu-container'; -let initialized = false; +/** + * Tries to find best position for opening context menu using mousemove and click event + * Returned position is relative to document + */ +export function createInteractionPositionTracker() { + let lastMouseX = 0; + let lastMouseY = 0; + const lastClicks: Array<{ el?: Element; mouseX: number; mouseY: number }> = []; + const MAX_LAST_CLICKS = 10; + + /** + * Track both `mouseup` and `click` + * `mouseup` is for clicks and brushes with mouse + * `click` is a fallback for keyboard interactions + */ + document.addEventListener('mouseup', onClick, true); + document.addEventListener('click', onClick, true); + document.addEventListener('mousemove', onMouseUpdate, { passive: true }); + document.addEventListener('mouseenter', onMouseUpdate, { passive: true }); + function onClick(event: MouseEvent) { + lastClicks.push({ + el: event.target as Element, + mouseX: event.clientX, + mouseY: event.clientY, + }); + if (lastClicks.length > MAX_LAST_CLICKS) { + lastClicks.shift(); + } + } + function onMouseUpdate(event: MouseEvent) { + lastMouseX = event.clientX; + lastMouseY = event.clientY; + } + + return { + resolveLastPosition: (): { x: number; y: number } => { + const lastClick = [...lastClicks] + .reverse() + .find(({ el }) => el && document.body.contains(el)); + if (!lastClick) { + // fallback to last mouse position + return { + x: lastMouseX, + y: lastMouseY, + }; + } + + const { top, left, bottom, right } = lastClick.el!.getBoundingClientRect(); + + const mouseX = lastClick.mouseX; + const mouseY = lastClick.mouseY; + + if (top <= mouseY && bottom >= mouseY && left <= mouseX && right >= mouseX) { + // click was inside target element + return { + x: mouseX, + y: mouseY, + }; + } else { + // keyboard edge case. no cursor position. use target element position instead + return { + x: left + (right - left) / 2, + y: bottom, + }; + } + }, + }; +} + +const { resolveLastPosition } = createInteractionPositionTracker(); function getOrCreateContainerElement() { let container = document.getElementById(CONTAINER_ID); - const y = getMouseY() + document.body.scrollTop; + let { x, y } = resolveLastPosition(); + y = y + window.scrollY; + x = x + window.scrollX; + if (!container) { container = document.createElement('div'); - container.style.left = getMouseX() + 'px'; + container.style.left = x + 'px'; container.style.top = y + 'px'; container.style.position = 'absolute'; @@ -44,38 +116,12 @@ function getOrCreateContainerElement() { container.id = CONTAINER_ID; document.body.appendChild(container); } else { - container.style.left = getMouseX() + 'px'; + container.style.left = x + 'px'; container.style.top = y + 'px'; } return container; } -let x: number = 0; -let y: number = 0; - -function initialize() { - if (!initialized) { - document.addEventListener('mousemove', onMouseUpdate, false); - document.addEventListener('mouseenter', onMouseUpdate, false); - initialized = true; - } -} - -function onMouseUpdate(e: any) { - x = e.pageX; - y = e.pageY; -} - -function getMouseX() { - return x; -} - -function getMouseY() { - return y; -} - -initialize(); - /** * A FlyoutSession describes the session of one opened flyout panel. It offers * methods to close the flyout panel again. If you open a flyout panel you should make @@ -87,16 +133,6 @@ initialize(); * @extends EventEmitter */ class ContextMenuSession extends EventEmitter { - /** - * Binds the current flyout session to an Angular scope, meaning this flyout - * session will be closed as soon as the Angular scope gets destroyed. - * @param {object} scope - An angular scope object to bind to. - */ - public bindToAngularScope(scope: ng.IScope): void { - const removeWatch = scope.$on('$destroy', () => this.close()); - this.on('closed', () => removeWatch()); - } - /** * Closes the opened flyout as long as it's still the open one. * If this is not the active session anymore, this method won't do anything. @@ -151,6 +187,7 @@ export function openContextMenu( panelPaddingSize="none" anchorPosition="downRight" withTitle + ownFocus={true} > Date: Mon, 13 Jul 2020 14:59:16 +0200 Subject: [PATCH 09/28] fix overflow (#70723) --- .../lens/public/visualization_container.scss | 3 +++ .../public/visualization_container.test.tsx | 9 +++++++++ .../lens/public/visualization_container.tsx | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/lens/public/visualization_container.scss diff --git a/x-pack/plugins/lens/public/visualization_container.scss b/x-pack/plugins/lens/public/visualization_container.scss new file mode 100644 index 0000000000000..e5c359112fe4b --- /dev/null +++ b/x-pack/plugins/lens/public/visualization_container.scss @@ -0,0 +1,3 @@ +.lnsVisualizationContainer { + overflow: auto; +} \ No newline at end of file diff --git a/x-pack/plugins/lens/public/visualization_container.test.tsx b/x-pack/plugins/lens/public/visualization_container.test.tsx index b29f0a5d783f9..454399ec90121 100644 --- a/x-pack/plugins/lens/public/visualization_container.test.tsx +++ b/x-pack/plugins/lens/public/visualization_container.test.tsx @@ -60,4 +60,13 @@ describe('VisualizationContainer', () => { expect(reportingEl.prop('style')).toEqual({ color: 'blue' }); }); + + test('combines class names with container class', () => { + const component = mount( + Hello! + ); + const reportingEl = component.find('[data-shared-item]').first(); + + expect(reportingEl.prop('className')).toEqual('myClass lnsVisualizationContainer'); + }); }); diff --git a/x-pack/plugins/lens/public/visualization_container.tsx b/x-pack/plugins/lens/public/visualization_container.tsx index fb7a1268192a8..3ca8d5de932d7 100644 --- a/x-pack/plugins/lens/public/visualization_container.tsx +++ b/x-pack/plugins/lens/public/visualization_container.tsx @@ -5,6 +5,9 @@ */ import React from 'react'; +import classNames from 'classnames'; + +import './visualization_container.scss'; interface Props extends React.HTMLAttributes { isReady?: boolean; @@ -15,9 +18,21 @@ interface Props extends React.HTMLAttributes { * This is a convenience component that wraps rendered Lens visualizations. It adds reporting * attributes (data-shared-item, data-render-complete, and data-title). */ -export function VisualizationContainer({ isReady = true, reportTitle, children, ...rest }: Props) { +export function VisualizationContainer({ + isReady = true, + reportTitle, + children, + className, + ...rest +}: Props) { return ( -
+
{children}
); From 84edc361f12d6620cf6f54e3c44aa5a38b0b9294 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 13 Jul 2020 15:22:21 +0200 Subject: [PATCH 10/28] [Discover] Migrate async import of embeddable factory to actual embeddable (#70920) --- .../discover/public/application/embeddable/index.ts | 1 - .../application/embeddable/search_embeddable.ts | 2 +- .../embeddable/search_embeddable_factory.ts | 7 ++++--- .../discover/public/application/embeddable/types.ts | 11 ++++++++++- src/plugins/discover/public/plugin.ts | 8 ++------ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/plugins/discover/public/application/embeddable/index.ts b/src/plugins/discover/public/application/embeddable/index.ts index b86a8daa119c5..1c4e06c7c3ade 100644 --- a/src/plugins/discover/public/application/embeddable/index.ts +++ b/src/plugins/discover/public/application/embeddable/index.ts @@ -20,4 +20,3 @@ export { SEARCH_EMBEDDABLE_TYPE } from './constants'; export * from './types'; export * from './search_embeddable_factory'; -export * from './search_embeddable'; diff --git a/src/plugins/discover/public/application/embeddable/search_embeddable.ts b/src/plugins/discover/public/application/embeddable/search_embeddable.ts index e03a6b938bc4f..9a3dd0d310ff7 100644 --- a/src/plugins/discover/public/application/embeddable/search_embeddable.ts +++ b/src/plugins/discover/public/application/embeddable/search_embeddable.ts @@ -38,7 +38,7 @@ import * as columnActions from '../angular/doc_table/actions/columns'; import searchTemplate from './search_template.html'; import { ISearchEmbeddable, SearchInput, SearchOutput } from './types'; import { SortOrder } from '../angular/doc_table/components/table_header/helpers'; -import { getSortForSearchSource } from '../angular/doc_table/lib/get_sort_for_search_source'; +import { getSortForSearchSource } from '../angular/doc_table'; import { getRequestInspectorStats, getResponseInspectorStats, diff --git a/src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts b/src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts index 1dc5947792d5c..f61fa361f0c0e 100644 --- a/src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts +++ b/src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts @@ -28,8 +28,8 @@ import { } from '../../../../embeddable/public'; import { TimeRange } from '../../../../data/public'; -import { SearchEmbeddable } from './search_embeddable'; -import { SearchInput, SearchOutput } from './types'; + +import { SearchInput, SearchOutput, SearchEmbeddable } from './types'; import { SEARCH_EMBEDDABLE_TYPE } from './constants'; interface StartServices { @@ -92,7 +92,8 @@ export class SearchEmbeddableFactory const savedObject = await getServices().getSavedSearchById(savedObjectId); const indexPattern = savedObject.searchSource.getField('index'); const { executeTriggerActions } = await this.getStartServices(); - return new SearchEmbeddable( + const { SearchEmbeddable: SearchEmbeddableClass } = await import('./search_embeddable'); + return new SearchEmbeddableClass( { savedSearch: savedObject, $rootScope, diff --git a/src/plugins/discover/public/application/embeddable/types.ts b/src/plugins/discover/public/application/embeddable/types.ts index 80576eb4ed7cb..d7fa9b3bc23d3 100644 --- a/src/plugins/discover/public/application/embeddable/types.ts +++ b/src/plugins/discover/public/application/embeddable/types.ts @@ -17,7 +17,12 @@ * under the License. */ -import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from 'src/plugins/embeddable/public'; +import { + Embeddable, + EmbeddableInput, + EmbeddableOutput, + IEmbeddable, +} from 'src/plugins/embeddable/public'; import { SortOrder } from '../angular/doc_table/components/table_header/helpers'; import { Filter, IIndexPattern, TimeRange, Query } from '../../../../data/public'; import { SavedSearch } from '../..'; @@ -40,3 +45,7 @@ export interface SearchOutput extends EmbeddableOutput { export interface ISearchEmbeddable extends IEmbeddable { getSavedSearch(): SavedSearch; } + +export interface SearchEmbeddable extends Embeddable { + type: string; +} diff --git a/src/plugins/discover/public/plugin.ts b/src/plugins/discover/public/plugin.ts index e97ac783c616f..20e13d204e0e9 100644 --- a/src/plugins/discover/public/plugin.ts +++ b/src/plugins/discover/public/plugin.ts @@ -66,6 +66,7 @@ import { DISCOVER_APP_URL_GENERATOR, DiscoverUrlGenerator, } from './url_generator'; +import { SearchEmbeddableFactory } from './application/embeddable'; declare module '../../share/public' { export interface UrlGeneratorStateMapping { @@ -345,12 +346,7 @@ export class DiscoverPlugin /** * register embeddable with a slimmer embeddable version of inner angular */ - private async registerEmbeddable( - core: CoreSetup, - plugins: DiscoverSetupPlugins - ) { - const { SearchEmbeddableFactory } = await import('./application/embeddable'); - + private registerEmbeddable(core: CoreSetup, plugins: DiscoverSetupPlugins) { if (!this.getEmbeddableInjector) { throw Error('Discover plugin method getEmbeddableInjector is undefined'); } From 06847519f1638030b001b2f46f9dde43cfa62b92 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Mon, 13 Jul 2020 16:26:33 +0300 Subject: [PATCH 11/28] [Functional test] Increase the timeout to click new vis function (#71226) Co-authored-by: Elastic Machine --- test/functional/services/listing_table.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/functional/services/listing_table.ts b/test/functional/services/listing_table.ts index 9a117458c7f76..fa42eb60fa410 100644 --- a/test/functional/services/listing_table.ts +++ b/test/functional/services/listing_table.ts @@ -179,9 +179,12 @@ export function ListingTableProvider({ getService, getPageObjects }: FtrProvider * @param promptBtnTestSubj testSubj locator for Prompt button */ public async clickNewButton(promptBtnTestSubj: string): Promise { - await retry.try(async () => { + await retry.tryForTime(20000, async () => { // newItemButton button is only visible when there are items in the listing table is displayed. - if (await testSubjects.exists('newItemButton')) { + const isnNewItemButtonPresent = await testSubjects.exists('newItemButton', { + timeout: 5000, + }); + if (isnNewItemButtonPresent) { await testSubjects.click('newItemButton'); } else { // no items exist, click createPromptButton to create new dashboard/visualization From 0f9c80d590b7b00850e5001754b07ca389d24e19 Mon Sep 17 00:00:00 2001 From: Brent Kimmel Date: Mon, 13 Jul 2020 09:26:43 -0400 Subject: [PATCH 12/28] [Security_Solution][Resolver] Style adjustments per UX (#71179) * SQUASH * WIP 2 * add block formatting on time to related list as well * M. Sherrier review: untranslate timestamp / remove top border on panel * redo dep * CI: replace missing import with type Co-authored-by: Elastic Machine --- .../panels/panel_content_process_detail.tsx | 49 +--- .../panels/panel_content_related_detail.tsx | 27 +- .../panels/panel_content_related_list.tsx | 20 +- .../view/panels/panel_content_utilities.tsx | 236 +++++++++--------- .../public/resolver/view/styles.tsx | 2 + 5 files changed, 165 insertions(+), 169 deletions(-) diff --git a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_process_detail.tsx b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_process_detail.tsx index 3127c7132df3d..5d90cd11d31af 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_process_detail.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_process_detail.tsx @@ -31,7 +31,7 @@ import { useResolverTheme } from '../assets'; const StyledDescriptionList = styled(EuiDescriptionList)` &.euiDescriptionList.euiDescriptionList--column dt.euiDescriptionList__title.desc-title { - max-width: 8em; + max-width: 10em; } `; @@ -56,73 +56,42 @@ export const ProcessDetails = memo(function ProcessDetails({ const dateTime = eventTime ? formatDate(eventTime) : ''; const createdEntry = { - title: i18n.translate( - 'xpack.securitySolution.endpoint.resolver.panel.processDescList.created', - { - defaultMessage: 'Created', - } - ), + title: '@timestamp', description: dateTime, }; const pathEntry = { - title: i18n.translate('xpack.securitySolution.endpoint.resolver.panel.processDescList.path', { - defaultMessage: 'Path', - }), + title: 'process.executable', description: processPath(processEvent), }; const pidEntry = { - title: i18n.translate('xpack.securitySolution.endpoint.resolver.panel.processDescList.pid', { - defaultMessage: 'PID', - }), + title: 'process.pid', description: processPid(processEvent), }; const userEntry = { - title: i18n.translate('xpack.securitySolution.endpoint.resolver.panel.processDescList.user', { - defaultMessage: 'User', - }), + title: 'user.name', description: (userInfoForProcess(processEvent) as { name: string }).name, }; const domainEntry = { - title: i18n.translate( - 'xpack.securitySolution.endpoint.resolver.panel.processDescList.domain', - { - defaultMessage: 'Domain', - } - ), + title: 'user.domain', description: (userInfoForProcess(processEvent) as { domain: string }).domain, }; const parentPidEntry = { - title: i18n.translate( - 'xpack.securitySolution.endpoint.resolver.panel.processDescList.parentPid', - { - defaultMessage: 'Parent PID', - } - ), + title: 'process.parent.pid', description: processParentPid(processEvent), }; const md5Entry = { - title: i18n.translate( - 'xpack.securitySolution.endpoint.resolver.panel.processDescList.md5hash', - { - defaultMessage: 'MD5', - } - ), + title: 'process.hash.md5', description: md5HashForProcess(processEvent), }; const commandLineEntry = { - title: i18n.translate( - 'xpack.securitySolution.endpoint.resolver.panel.processDescList.commandLine', - { - defaultMessage: 'Command Line', - } - ), + title: 'process.args', description: argsForProcess(processEvent), }; diff --git a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_related_detail.tsx b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_related_detail.tsx index f27ec56fef697..4544381d94955 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_related_detail.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_related_detail.tsx @@ -10,7 +10,13 @@ import { EuiSpacer, EuiText, EuiDescriptionList, EuiTextColor, EuiTitle } from ' import styled from 'styled-components'; import { useSelector } from 'react-redux'; import { FormattedMessage } from 'react-intl'; -import { CrumbInfo, formatDate, StyledBreadcrumbs, BoldCode } from './panel_content_utilities'; +import { + CrumbInfo, + formatDate, + StyledBreadcrumbs, + BoldCode, + StyledTime, +} from './panel_content_utilities'; import * as event from '../../../../common/endpoint/models/event'; import { ResolverEvent } from '../../../../common/endpoint/types'; import * as selectors from '../../store/selectors'; @@ -308,7 +314,7 @@ export const RelatedEventDetail = memo(function RelatedEventDetail({ return ( <> - + @@ -321,11 +327,13 @@ export const RelatedEventDetail = memo(function RelatedEventDetail({ defaultMessage="{category} {eventType}" /> - + + + @@ -340,14 +348,15 @@ export const RelatedEventDetail = memo(function RelatedEventDetail({ return ( {index === 0 ? null : } - - + + {sectionTitle} + - + + + diff --git a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_utilities.tsx b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_utilities.tsx index be0ba04c53233..374c4c94c7768 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_utilities.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_utilities.tsx @@ -1,114 +1,122 @@ -/* - * 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 { i18n } from '@kbn/i18n'; -import { EuiBreadcrumbs, EuiBreadcrumb, EuiCode, EuiBetaBadge } from '@elastic/eui'; -import styled from 'styled-components'; -import React, { memo } from 'react'; -import { useResolverTheme } from '../assets'; - -/** - * A bold version of EuiCode to display certain titles with - */ -export const BoldCode = styled(EuiCode)` - &.euiCodeBlock code.euiCodeBlock__code { - font-weight: 900; - } -`; - -const BetaHeader = styled(`header`)` - margin-bottom: 1em; -`; - -/** - * The two query parameters we read/write on to control which view the table presents: - */ -export interface CrumbInfo { - readonly crumbId: string; - readonly crumbEvent: string; -} - -const ThemedBreadcrumbs = styled(EuiBreadcrumbs)<{ background: string; text: string }>` - &.euiBreadcrumbs.euiBreadcrumbs--responsive { - background-color: ${(props) => props.background}; - color: ${(props) => props.text}; - padding: 1em; - border-radius: 5px; - } - - & .euiBreadcrumbSeparator { - background: ${(props) => props.text}; - } -`; - -const betaBadgeLabel = i18n.translate( - 'xpack.securitySolution.enpdoint.resolver.panelutils.betaBadgeLabel', - { - defaultMessage: 'BETA', - } -); - -/** - * Breadcrumb menu with adjustments per direction from UX team - */ -export const StyledBreadcrumbs = memo(function StyledBreadcrumbs({ - breadcrumbs, - truncate, -}: { - breadcrumbs: EuiBreadcrumb[]; - truncate?: boolean; -}) { - const { - colorMap: { resolverBreadcrumbBackground, resolverEdgeText }, - } = useResolverTheme(); - return ( - <> - - - - - - ); -}); - -/** - * Long formatter (to second) for DateTime - */ -export const formatter = new Intl.DateTimeFormat(i18n.getLocale(), { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', -}); - -const invalidDateText = i18n.translate( - 'xpack.securitySolution.enpdoint.resolver.panelutils.invaliddate', - { - defaultMessage: 'Invalid Date', - } -); -/** - * @returns {string} A nicely formatted string for a date - */ -export function formatDate( - /** To be passed through Date->Intl.DateTimeFormat */ timestamp: ConstructorParameters< - typeof Date - >[0] -): string { - const date = new Date(timestamp); - if (isFinite(date.getTime())) { - return formatter.format(date); - } else { - return invalidDateText; - } -} +/* + * 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 { i18n } from '@kbn/i18n'; +import { EuiBreadcrumbs, EuiCode, EuiBetaBadge } from '@elastic/eui'; +import styled from 'styled-components'; +import React, { memo } from 'react'; +import { useResolverTheme } from '../assets'; + +/** + * A bold version of EuiCode to display certain titles with + */ +export const BoldCode = styled(EuiCode)` + &.euiCodeBlock code.euiCodeBlock__code { + font-weight: 900; + } +`; + +const BetaHeader = styled(`header`)` + margin-bottom: 1em; +`; + +/** + * The two query parameters we read/write on to control which view the table presents: + */ +export interface CrumbInfo { + readonly crumbId: string; + readonly crumbEvent: string; +} + +const ThemedBreadcrumbs = styled(EuiBreadcrumbs)<{ background: string; text: string }>` + &.euiBreadcrumbs.euiBreadcrumbs--responsive { + background-color: ${(props) => props.background}; + color: ${(props) => props.text}; + padding: 1em; + border-radius: 5px; + } + + & .euiBreadcrumbSeparator { + background: ${(props) => props.text}; + } +`; + +const betaBadgeLabel = i18n.translate( + 'xpack.securitySolution.enpdoint.resolver.panelutils.betaBadgeLabel', + { + defaultMessage: 'BETA', + } +); + +/** + * A component to keep time representations in blocks so they don't wrap + * and look bad. + */ +export const StyledTime = memo(styled('time')` + display: inline-block; + text-align: start; +`); + +type Breadcrumbs = Parameters[0]['breadcrumbs']; +/** + * Breadcrumb menu with adjustments per direction from UX team + */ +export const StyledBreadcrumbs = memo(function StyledBreadcrumbs({ + breadcrumbs, +}: { + breadcrumbs: Breadcrumbs; +}) { + const { + colorMap: { resolverBreadcrumbBackground, resolverEdgeText }, + } = useResolverTheme(); + return ( + <> + + + + + + ); +}); + +/** + * Long formatter (to second) for DateTime + */ +export const formatter = new Intl.DateTimeFormat(i18n.getLocale(), { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', +}); + +const invalidDateText = i18n.translate( + 'xpack.securitySolution.enpdoint.resolver.panelutils.invaliddate', + { + defaultMessage: 'Invalid Date', + } +); +/** + * @returns {string} A nicely formatted string for a date + */ +export function formatDate( + /** To be passed through Date->Intl.DateTimeFormat */ timestamp: ConstructorParameters< + typeof Date + >[0] +): string { + const date = new Date(timestamp); + if (isFinite(date.getTime())) { + return formatter.format(date); + } else { + return invalidDateText; + } +} diff --git a/x-pack/plugins/security_solution/public/resolver/view/styles.tsx b/x-pack/plugins/security_solution/public/resolver/view/styles.tsx index 2a1e67f4a9fdc..4cdb29b283f1e 100644 --- a/x-pack/plugins/security_solution/public/resolver/view/styles.tsx +++ b/x-pack/plugins/security_solution/public/resolver/view/styles.tsx @@ -48,6 +48,8 @@ export const StyledPanel = styled(Panel)` overflow: auto; width: 25em; max-width: 50%; + border-radius: 0; + border-top: none; `; /** From ba195bad36aa3289a9e22c0b9c71bbfca8704e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Mon, 13 Jul 2020 15:37:10 +0200 Subject: [PATCH 13/28] [Logs UI] Unskip log highlight api integration test (#71058) This unskips one log highlighting API test, which was skipped due to changes in the Elasticsearch highlighting behavior. --- .../api_integration/apis/metrics_ui/log_entry_highlights.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts b/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts index 823c8159a136d..4e6da9d50dc2a 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts @@ -122,9 +122,7 @@ export default function ({ getService }: FtrProviderContext) { }); }); - // Skipped since it behaves differently in master and in the 7.X branch - // See https://github.com/elastic/kibana/issues/49959 - it.skip('highlights field columns', async () => { + it('highlights field columns', async () => { const { body } = await supertest .post(LOG_ENTRIES_HIGHLIGHTS_PATH) .set(COMMON_HEADERS) From 4b9902987f6f936f20db946ae9f78032d60c0eca Mon Sep 17 00:00:00 2001 From: Jorge Sanz Date: Mon, 13 Jul 2020 15:46:07 +0200 Subject: [PATCH 14/28] [Maps] Inclusive language (#71427) --- docs/maps/connect-to-ems.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/maps/connect-to-ems.asciidoc b/docs/maps/connect-to-ems.asciidoc index 2b88ffe2e2dda..45ced2e64aa73 100644 --- a/docs/maps/connect-to-ems.asciidoc +++ b/docs/maps/connect-to-ems.asciidoc @@ -19,7 +19,7 @@ Maps makes requests directly from the browser to EMS. To connect to EMS when your Kibana server and browser are in an internal network: . Set `map.proxyElasticMapsServiceInMaps` to `true` in your <> file to proxy EMS requests through the Kibana server. -. Update your firewall rules to whitelist connections from your Kibana server to the EMS domains. +. Update your firewall rules to allow connections from your Kibana server to the EMS domains. NOTE: Coordinate map and region map visualizations do not support `map.proxyElasticMapsServiceInMaps` and will not proxy EMS requests through the Kibana server. From 4bdd31e9c92c822fb3270cecd4465c4e7230028e Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Mon, 13 Jul 2020 08:57:42 -0500 Subject: [PATCH 15/28] [Metrics + Logs UI] Add test for logs and metrics telemetry (#70858) * Add test for logs and metrics telemetry * wait before you go * Remove kubenetes * Fix type check * Add back kubernetes test * Remove kubernetes Co-authored-by: Elastic Machine --- .../components/dropdown_button.tsx | 5 +- .../waffle/waffle_inventory_switcher.tsx | 4 ++ .../test/functional/apps/infra/home_page.ts | 54 +++++++++++++++++++ .../apps/infra/logs_source_configuration.ts | 35 ++++++++++++ .../page_objects/infra_home_page.ts | 23 ++++++++ 5 files changed, 120 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/dropdown_button.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/dropdown_button.tsx index 6e3ebee2dcb4b..62b25d5a36870 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/dropdown_button.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/dropdown_button.tsx @@ -9,13 +9,15 @@ import React, { ReactNode } from 'react'; import { withTheme, EuiTheme } from '../../../../../../observability/public'; interface Props { + 'data-test-subj'?: string; label: string; onClick: () => void; theme: EuiTheme | undefined; children: ReactNode; } -export const DropdownButton = withTheme(({ onClick, label, theme, children }: Props) => { +export const DropdownButton = withTheme((props: Props) => { + const { onClick, label, theme, children } = props; return ( { id: 'firstPanel', items: [ { + 'data-test-subj': 'goToHost', name: getDisplayNameForType('host'), onClick: goToHost, }, { + 'data-test-subj': 'goToPods', name: getDisplayNameForType('pod'), onClick: goToK8, }, { + 'data-test-subj': 'goToDocker', name: getDisplayNameForType('container'), onClick: goToDocker, }, @@ -117,6 +120,7 @@ export const WaffleInventorySwitcher: React.FC = () => { const button = ( diff --git a/x-pack/test/functional/apps/infra/home_page.ts b/x-pack/test/functional/apps/infra/home_page.ts index 28279d5e5b812..04f289b69bb71 100644 --- a/x-pack/test/functional/apps/infra/home_page.ts +++ b/x-pack/test/functional/apps/infra/home_page.ts @@ -4,15 +4,22 @@ * you may not use this file except in compliance with the Elastic License. */ +import moment from 'moment'; +import expect from '@kbn/expect/expect.js'; import { FtrProviderContext } from '../../ftr_provider_context'; import { DATES } from './constants'; const DATE_WITH_DATA = DATES.metricsAndLogs.hosts.withData; const DATE_WITHOUT_DATA = DATES.metricsAndLogs.hosts.withoutData; +const COMMON_REQUEST_HEADERS = { + 'kbn-xsrf': 'some-xsrf-token', +}; + export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); const pageObjects = getPageObjects(['common', 'infraHome']); + const supertest = getService('supertest'); describe('Home page', function () { this.tags('includeFirefox'); @@ -46,6 +53,53 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await pageObjects.infraHome.goToTime(DATE_WITHOUT_DATA); await pageObjects.infraHome.getNoMetricsDataPrompt(); }); + + it('records telemetry for hosts', async () => { + await pageObjects.infraHome.goToTime(DATE_WITH_DATA); + await pageObjects.infraHome.getWaffleMap(); + + const resp = await supertest + .post(`/api/telemetry/v2/clusters/_stats`) + .set(COMMON_REQUEST_HEADERS) + .set('Accept', 'application/json') + .send({ + timeRange: { + min: moment().subtract(1, 'hour').toISOString(), + max: moment().toISOString(), + }, + unencrypted: true, + }) + .expect(200) + .then((res: any) => res.body); + + expect( + resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_hosts + ).to.be.greaterThan(0); + }); + + it('records telemetry for docker', async () => { + await pageObjects.infraHome.goToTime(DATE_WITH_DATA); + await pageObjects.infraHome.getWaffleMap(); + await pageObjects.infraHome.goToDocker(); + + const resp = await supertest + .post(`/api/telemetry/v2/clusters/_stats`) + .set(COMMON_REQUEST_HEADERS) + .set('Accept', 'application/json') + .send({ + timeRange: { + min: moment().subtract(1, 'hour').toISOString(), + max: moment().toISOString(), + }, + unencrypted: true, + }) + .expect(200) + .then((res: any) => res.body); + + expect( + resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.infraops_docker + ).to.be.greaterThan(0); + }); }); }); }; diff --git a/x-pack/test/functional/apps/infra/logs_source_configuration.ts b/x-pack/test/functional/apps/infra/logs_source_configuration.ts index 7ec06e74289c9..04ffcc4847d54 100644 --- a/x-pack/test/functional/apps/infra/logs_source_configuration.ts +++ b/x-pack/test/functional/apps/infra/logs_source_configuration.ts @@ -5,16 +5,22 @@ */ import expect from '@kbn/expect'; +import moment from 'moment'; import { DATES } from './constants'; import { FtrProviderContext } from '../../ftr_provider_context'; +const COMMON_REQUEST_HEADERS = { + 'kbn-xsrf': 'some-xsrf-token', +}; + export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); const logsUi = getService('logsUi'); const infraSourceConfigurationForm = getService('infraSourceConfigurationForm'); const pageObjects = getPageObjects(['common', 'infraLogs']); const retry = getService('retry'); + const supertest = getService('supertest'); describe('Logs Source Configuration', function () { before(async () => { @@ -97,6 +103,35 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { expect(logStreamEntryColumns).to.have.length(3); }); + it('records telemetry for logs', async () => { + await logsUi.logStreamPage.navigateTo({ + logPosition: { + start: DATES.metricsAndLogs.stream.startWithData, + end: DATES.metricsAndLogs.stream.endWithData, + }, + }); + + await logsUi.logStreamPage.getStreamEntries(); + + const resp = await supertest + .post(`/api/telemetry/v2/clusters/_stats`) + .set(COMMON_REQUEST_HEADERS) + .set('Accept', 'application/json') + .send({ + timeRange: { + min: moment().subtract(1, 'hour').toISOString(), + max: moment().toISOString(), + }, + unencrypted: true, + }) + .expect(200) + .then((res: any) => res.body); + + expect( + resp[0].stack_stats.kibana.plugins.infraops.last_24_hours.hits.logs + ).to.be.greaterThan(0); + }); + it('can change the log columns', async () => { await pageObjects.infraLogs.navigateToTab('settings'); diff --git a/x-pack/test/functional/page_objects/infra_home_page.ts b/x-pack/test/functional/page_objects/infra_home_page.ts index 51dad594f21f5..ef6d2dc02eb80 100644 --- a/x-pack/test/functional/page_objects/infra_home_page.ts +++ b/x-pack/test/functional/page_objects/infra_home_page.ts @@ -33,6 +33,29 @@ export function InfraHomePageProvider({ getService }: FtrProviderContext) { return await testSubjects.find('waffleMap'); }, + async openInvenotrySwitcher() { + await testSubjects.click('openInventorySwitcher'); + return await testSubjects.find('goToHost'); + }, + + async goToHost() { + await testSubjects.click('openInventorySwitcher'); + await testSubjects.find('goToHost'); + return await testSubjects.click('goToHost'); + }, + + async goToPods() { + await testSubjects.click('openInventorySwitcher'); + await testSubjects.find('goToHost'); + return await testSubjects.click('goToPods'); + }, + + async goToDocker() { + await testSubjects.click('openInventorySwitcher'); + await testSubjects.find('goToHost'); + return await testSubjects.click('goToDocker'); + }, + async goToMetricExplorer() { return await testSubjects.click('infrastructureNavLink_/infrastructure/metrics-explorer'); }, From ddd3a9defd35b0a932bfdd7cf6b1a4a6157ca4ae Mon Sep 17 00:00:00 2001 From: MadameSheema Date: Mon, 13 Jul 2020 16:03:54 +0200 Subject: [PATCH 16/28] [SIEM][Detections] Fixes index patterns order (#71270) * fixes alphabetical order for index patterns * fixes cypress tests adding the new index pattern * fixes jest tests * fixes jest tests Co-authored-by: Elastic Machine --- x-pack/plugins/security_solution/common/constants.ts | 2 +- .../integration/alerts_detection_rules_custom.spec.ts | 1 + .../__snapshots__/drag_drop_context_wrapper.test.tsx.snap | 2 +- .../__snapshots__/event_details.test.tsx.snap | 4 ++-- .../public/common/containers/source/index.test.tsx | 4 ++-- .../detection_engine/rules/fetch_index_patterns.test.tsx | 8 ++++---- .../overview/components/overview_host/index.test.tsx | 2 +- .../overview/components/overview_network/index.test.tsx | 2 +- .../timeline/__snapshots__/timeline.test.tsx.snap | 2 +- .../body/column_headers/__snapshots__/index.test.tsx.snap | 2 +- .../__snapshots__/suricata_row_renderer.test.tsx.snap | 2 +- .../zeek/__snapshots__/zeek_details.test.tsx.snap | 2 +- .../zeek/__snapshots__/zeek_row_renderer.test.tsx.snap | 2 +- 13 files changed, 18 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/security_solution/common/constants.ts b/x-pack/plugins/security_solution/common/constants.ts index 7cd5692176ee3..4e9514feec74f 100644 --- a/x-pack/plugins/security_solution/common/constants.ts +++ b/x-pack/plugins/security_solution/common/constants.ts @@ -59,9 +59,9 @@ export const DEFAULT_INDEX_PATTERN = [ 'auditbeat-*', 'endgame-*', 'filebeat-*', + 'logs-*', 'packetbeat-*', 'winlogbeat-*', - 'logs-*', ]; /** This Kibana Advanced Setting enables the `Security news` feed widget */ diff --git a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts index 81832b3d9edea..a51ad4388c428 100644 --- a/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts @@ -131,6 +131,7 @@ describe.skip('Detection rules, custom', () => { 'auditbeat-*', 'endgame-*', 'filebeat-*', + 'logs-*', 'packetbeat-*', 'winlogbeat-*', ]; diff --git a/x-pack/plugins/security_solution/public/common/components/drag_and_drop/__snapshots__/drag_drop_context_wrapper.test.tsx.snap b/x-pack/plugins/security_solution/public/common/components/drag_and_drop/__snapshots__/drag_drop_context_wrapper.test.tsx.snap index 0c96d0320d198..16f095e5effbb 100644 --- a/x-pack/plugins/security_solution/public/common/components/drag_and_drop/__snapshots__/drag_drop_context_wrapper.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/common/components/drag_and_drop/__snapshots__/drag_drop_context_wrapper.test.tsx.snap @@ -369,9 +369,9 @@ exports[`DragDropContextWrapper rendering it renders against the snapshot 1`] = "auditbeat-*", "endgame-*", "filebeat-*", + "logs-*", "packetbeat-*", "winlogbeat-*", - "logs-*", ], "name": "event.end", "searchable": true, diff --git a/x-pack/plugins/security_solution/public/common/components/event_details/__snapshots__/event_details.test.tsx.snap b/x-pack/plugins/security_solution/public/common/components/event_details/__snapshots__/event_details.test.tsx.snap index 408a4c74e930f..9ca9cd6cce389 100644 --- a/x-pack/plugins/security_solution/public/common/components/event_details/__snapshots__/event_details.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/common/components/event_details/__snapshots__/event_details.test.tsx.snap @@ -377,9 +377,9 @@ exports[`EventDetails rendering should match snapshot 1`] = ` "auditbeat-*", "endgame-*", "filebeat-*", + "logs-*", "packetbeat-*", "winlogbeat-*", - "logs-*", ], "name": "event.end", "searchable": true, @@ -1070,9 +1070,9 @@ In other use cases the message field can be used to concatenate different values "auditbeat-*", "endgame-*", "filebeat-*", + "logs-*", "packetbeat-*", "winlogbeat-*", - "logs-*", ], "name": "event.end", "searchable": true, diff --git a/x-pack/plugins/security_solution/public/common/containers/source/index.test.tsx b/x-pack/plugins/security_solution/public/common/containers/source/index.test.tsx index b9daba9a40941..bfde17723aef4 100644 --- a/x-pack/plugins/security_solution/public/common/containers/source/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/containers/source/index.test.tsx @@ -29,7 +29,7 @@ describe('Index Fields & Browser Fields', () => { indexPattern: { fields: [], title: - 'apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,packetbeat-*,winlogbeat-*,logs-*', + 'apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,winlogbeat-*', }, indicesExist: true, loading: true, @@ -59,7 +59,7 @@ describe('Index Fields & Browser Fields', () => { indexPattern: { fields: mockIndexFields, title: - 'apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,packetbeat-*,winlogbeat-*,logs-*', + 'apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,winlogbeat-*', }, loading: false, errorMessage: null, diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/fetch_index_patterns.test.tsx b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/fetch_index_patterns.test.tsx index c282a204f19a5..0204a2980b9fc 100644 --- a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/fetch_index_patterns.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/fetch_index_patterns.test.tsx @@ -352,9 +352,9 @@ describe('useFetchIndexPatterns', () => { 'auditbeat-*', 'endgame-*', 'filebeat-*', + 'logs-*', 'packetbeat-*', 'winlogbeat-*', - 'logs-*', ], name: 'event.end', searchable: true, @@ -369,9 +369,9 @@ describe('useFetchIndexPatterns', () => { 'auditbeat-*', 'endgame-*', 'filebeat-*', + 'logs-*', 'packetbeat-*', 'winlogbeat-*', - 'logs-*', ], indicesExists: true, indexPatterns: { @@ -418,7 +418,7 @@ describe('useFetchIndexPatterns', () => { { name: 'event.end', searchable: true, type: 'date', aggregatable: true }, ], title: - 'apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,packetbeat-*,winlogbeat-*,logs-*', + 'apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,winlogbeat-*', }, }, result.current[1], @@ -450,9 +450,9 @@ describe('useFetchIndexPatterns', () => { 'auditbeat-*', 'endgame-*', 'filebeat-*', + 'logs-*', 'packetbeat-*', 'winlogbeat-*', - 'logs-*', ], indicesExists: false, isLoading: false, diff --git a/x-pack/plugins/security_solution/public/overview/components/overview_host/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/overview_host/index.test.tsx index bb9fd73d2df8e..d019a480a8045 100644 --- a/x-pack/plugins/security_solution/public/overview/components/overview_host/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/overview_host/index.test.tsx @@ -58,9 +58,9 @@ const mockOpenTimelineQueryResults: MockedProvidedQuery[] = [ 'auditbeat-*', 'endgame-*', 'filebeat-*', + 'logs-*', 'packetbeat-*', 'winlogbeat-*', - 'logs-*', ], inspect: false, }, diff --git a/x-pack/plugins/security_solution/public/overview/components/overview_network/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/overview_network/index.test.tsx index 0f6fce1486ee7..c7f7c4f4af254 100644 --- a/x-pack/plugins/security_solution/public/overview/components/overview_network/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/overview_network/index.test.tsx @@ -73,9 +73,9 @@ const mockOpenTimelineQueryResults: MockedProvidedQuery[] = [ 'auditbeat-*', 'endgame-*', 'filebeat-*', + 'logs-*', 'packetbeat-*', 'winlogbeat-*', - 'logs-*', ], inspect: false, }, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/__snapshots__/timeline.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/timeline/__snapshots__/timeline.test.tsx.snap index e38f6ad022d78..3508e12cb1be1 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/__snapshots__/timeline.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/__snapshots__/timeline.test.tsx.snap @@ -474,9 +474,9 @@ exports[`Timeline rendering renders correctly against snapshot 1`] = ` "auditbeat-*", "endgame-*", "filebeat-*", + "logs-*", "packetbeat-*", "winlogbeat-*", - "logs-*", ], "name": "event.end", "searchable": true, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/column_headers/__snapshots__/index.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/column_headers/__snapshots__/index.test.tsx.snap index 2436e71a89b86..a5610cabc1774 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/column_headers/__snapshots__/index.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/column_headers/__snapshots__/index.test.tsx.snap @@ -379,9 +379,9 @@ exports[`ColumnHeaders rendering renders correctly against snapshot 1`] = ` "auditbeat-*", "endgame-*", "filebeat-*", + "logs-*", "packetbeat-*", "winlogbeat-*", - "logs-*", ], "name": "event.end", "searchable": true, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/__snapshots__/suricata_row_renderer.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/__snapshots__/suricata_row_renderer.test.tsx.snap index cba4b9aa72a25..8672b542eb6c6 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/__snapshots__/suricata_row_renderer.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/__snapshots__/suricata_row_renderer.test.tsx.snap @@ -371,9 +371,9 @@ exports[`suricata_row_renderer renders correctly against snapshot 1`] = ` "auditbeat-*", "endgame-*", "filebeat-*", + "logs-*", "packetbeat-*", "winlogbeat-*", - "logs-*", ], "name": "event.end", "searchable": true, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/__snapshots__/zeek_details.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/__snapshots__/zeek_details.test.tsx.snap index e1000637147a8..d13c3de00c780 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/__snapshots__/zeek_details.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/__snapshots__/zeek_details.test.tsx.snap @@ -369,9 +369,9 @@ exports[`ZeekDetails rendering it renders the default ZeekDetails 1`] = ` "auditbeat-*", "endgame-*", "filebeat-*", + "logs-*", "packetbeat-*", "winlogbeat-*", - "logs-*", ], "name": "event.end", "searchable": true, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/__snapshots__/zeek_row_renderer.test.tsx.snap b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/__snapshots__/zeek_row_renderer.test.tsx.snap index d4c80441e6037..b8f28026dfdb5 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/__snapshots__/zeek_row_renderer.test.tsx.snap +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/__snapshots__/zeek_row_renderer.test.tsx.snap @@ -371,9 +371,9 @@ exports[`zeek_row_renderer renders correctly against snapshot 1`] = ` "auditbeat-*", "endgame-*", "filebeat-*", + "logs-*", "packetbeat-*", "winlogbeat-*", - "logs-*", ], "name": "event.end", "searchable": true, From 0a516cfbb921c6a22cdcf580fc6e8a149061e560 Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Mon, 13 Jul 2020 10:47:01 -0400 Subject: [PATCH 17/28] Improvements to our developer guide (#67764) * contributing guide -> asciidoc * Update docs/developer/contributing/index.asciidoc Co-authored-by: Peter Schretlen * Update CONTRIBUTING.md Co-authored-by: Peter Schretlen * Update docs/developer/best-practices/stability.asciidoc Co-authored-by: Peter Schretlen * Update docs/developer/contributing/index.asciidoc Co-authored-by: Peter Schretlen * address code review comments * Update docs/developer/contributing/development-documentation.asciidoc Co-authored-by: Peter Schretlen * review comment updates * fix bad ref Co-authored-by: Peter Schretlen --- CONTRIBUTING.md | 738 +----------------- docs/developer/add-data-guide.asciidoc | 38 - .../advanced/development-basepath.asciidoc | 18 + .../development-es-snapshots.asciidoc | 22 +- docs/developer/advanced/index.asciidoc | 12 + .../advanced/running-elasticsearch.asciidoc | 118 +++ .../architecture/add-data-tutorials.asciidoc | 38 + .../development-visualize-index.asciidoc | 8 +- docs/developer/architecture/index.asciidoc | 25 + .../security/feature-registration.asciidoc} | 20 +- .../architecture/security/index.asciidoc | 12 + .../{ => architecture}/security/rbac.asciidoc | 10 +- docs/developer/best-practices/index.asciidoc | 136 ++++ .../best-practices/security.asciidoc | 55 ++ .../best-practices/stability.asciidoc | 66 ++ .../development-accessibility-tests.asciidoc | 23 + .../development-documentation.asciidoc | 34 + .../development-functional-tests.asciidoc | 49 +- .../contributing/development-github.asciidoc | 112 +++ .../development-pull-request.asciidoc | 32 + .../contributing/development-tests.asciidoc | 96 +++ .../development-unit-tests.asciidoc | 86 +- docs/developer/contributing/index.asciidoc | 89 +++ .../interpreting-ci-failures.asciidoc | 10 +- .../kibana-issue-reporting.asciidoc | 46 ++ docs/developer/contributing/linting.asciidoc | 70 ++ .../{ => contributing}/pr-review.asciidoc | 28 +- docs/developer/core-development.asciidoc | 24 - .../core/development-basepath.asciidoc | 85 -- .../core/development-dependencies.asciidoc | 103 --- .../core/development-elasticsearch.asciidoc | 40 - .../core/development-modules.asciidoc | 63 -- .../getting-started/building-kibana.asciidoc | 39 + .../getting-started/debugging.asciidoc | 59 ++ .../development-plugin-resources.asciidoc | 52 +- docs/developer/getting-started/index.asciidoc | 144 ++++ .../running-kibana-advanced.asciidoc | 87 +++ .../getting-started/sample-data.asciidoc | 31 + docs/developer/getting-started/sass.asciidoc | 36 + docs/developer/index.asciidoc | 28 +- docs/developer/plugin-development.asciidoc | 24 - .../plugin/development-uiexports.asciidoc | 16 - ...external-plugin-functional-tests.asciidoc} | 16 +- ... => external-plugin-localization.asciidoc} | 22 +- docs/developer/plugin/index.asciidoc | 42 + docs/developer/security/index.asciidoc | 12 - 46 files changed, 1629 insertions(+), 1285 deletions(-) delete mode 100644 docs/developer/add-data-guide.asciidoc create mode 100644 docs/developer/advanced/development-basepath.asciidoc rename docs/developer/{core => advanced}/development-es-snapshots.asciidoc (90%) create mode 100644 docs/developer/advanced/index.asciidoc create mode 100644 docs/developer/advanced/running-elasticsearch.asciidoc create mode 100644 docs/developer/architecture/add-data-tutorials.asciidoc rename docs/developer/{visualize => architecture}/development-visualize-index.asciidoc (85%) create mode 100644 docs/developer/architecture/index.asciidoc rename docs/developer/{plugin/development-plugin-feature-registration.asciidoc => architecture/security/feature-registration.asciidoc} (96%) create mode 100644 docs/developer/architecture/security/index.asciidoc rename docs/developer/{ => architecture}/security/rbac.asciidoc (96%) create mode 100644 docs/developer/best-practices/index.asciidoc create mode 100644 docs/developer/best-practices/security.asciidoc create mode 100644 docs/developer/best-practices/stability.asciidoc create mode 100644 docs/developer/contributing/development-accessibility-tests.asciidoc create mode 100644 docs/developer/contributing/development-documentation.asciidoc rename docs/developer/{core => contributing}/development-functional-tests.asciidoc (90%) create mode 100644 docs/developer/contributing/development-github.asciidoc create mode 100644 docs/developer/contributing/development-pull-request.asciidoc create mode 100644 docs/developer/contributing/development-tests.asciidoc rename docs/developer/{core => contributing}/development-unit-tests.asciidoc (52%) create mode 100644 docs/developer/contributing/index.asciidoc rename docs/developer/{testing => contributing}/interpreting-ci-failures.asciidoc (87%) create mode 100644 docs/developer/contributing/kibana-issue-reporting.asciidoc create mode 100644 docs/developer/contributing/linting.asciidoc rename docs/developer/{ => contributing}/pr-review.asciidoc (90%) delete mode 100644 docs/developer/core-development.asciidoc delete mode 100644 docs/developer/core/development-basepath.asciidoc delete mode 100644 docs/developer/core/development-dependencies.asciidoc delete mode 100644 docs/developer/core/development-elasticsearch.asciidoc delete mode 100644 docs/developer/core/development-modules.asciidoc create mode 100644 docs/developer/getting-started/building-kibana.asciidoc create mode 100644 docs/developer/getting-started/debugging.asciidoc rename docs/developer/{plugin => getting-started}/development-plugin-resources.asciidoc (51%) create mode 100644 docs/developer/getting-started/index.asciidoc create mode 100644 docs/developer/getting-started/running-kibana-advanced.asciidoc create mode 100644 docs/developer/getting-started/sample-data.asciidoc create mode 100644 docs/developer/getting-started/sass.asciidoc delete mode 100644 docs/developer/plugin-development.asciidoc delete mode 100644 docs/developer/plugin/development-uiexports.asciidoc rename docs/developer/plugin/{development-plugin-functional-tests.asciidoc => external-plugin-functional-tests.asciidoc} (79%) rename docs/developer/plugin/{development-plugin-localization.asciidoc => external-plugin-localization.asciidoc} (87%) create mode 100644 docs/developer/plugin/index.asciidoc delete mode 100644 docs/developer/security/index.asciidoc diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0aeed7a34949..11c595a1ad983 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,739 +1,5 @@ # Contributing to Kibana -We understand that you may not have days at a time to work on Kibana. We ask that you read our contributing guidelines carefully so that you spend less time, overall, struggling to push your PR through our code review processes. +We understand that you may not have days at a time to work on Kibana. We ask that you read our [developer guide](https://www.elastic.co/guide/en/kibana/master/development.html) carefully so that you spend less time, overall, struggling to push your PR through our code review processes. -At the same time, reading the contributing guidelines will give you a better idea of how to post meaningful issues that will be more easily be parsed, considered, and resolved. A big win for everyone involved! :tada: - -## Table of Contents - -A high level overview of our contributing guidelines. - -- [Effective issue reporting in Kibana](#effective-issue-reporting-in-kibana) - - [Voicing the importance of an issue](#voicing-the-importance-of-an-issue) - - ["My issue isn't getting enough attention"](#my-issue-isnt-getting-enough-attention) - - ["I want to help!"](#i-want-to-help) -- [How We Use Git and GitHub](#how-we-use-git-and-github) - - [Forking](#forking) - - [Branching](#branching) - - [Commits and Merging](#commits-and-merging) - - [Rebasing and fixing merge conflicts](#rebasing-and-fixing-merge-conflicts) - - [What Goes Into a Pull Request](#what-goes-into-a-pull-request) -- [Contributing Code](#contributing-code) - - [Setting Up Your Development Environment](#setting-up-your-development-environment) - - [Increase node.js heap size](#increase-nodejs-heap-size) - - [Running Elasticsearch Locally](#running-elasticsearch-locally) - - [Nightly snapshot (recommended)](#nightly-snapshot-recommended) - - [Keeping data between snapshots](#keeping-data-between-snapshots) - - [Source](#source) - - [Archive](#archive) - - [Sample Data](#sample-data) - - [Running Elasticsearch Remotely](#running-elasticsearch-remotely) - - [Running remote clusters](#running-remote-clusters) - - [Running Kibana](#running-kibana) - - [Running Kibana in Open-Source mode](#running-kibana-in-open-source-mode) - - [Unsupported URL Type](#unsupported-url-type) - - [Customizing `config/kibana.dev.yml`](#customizing-configkibanadevyml) - - [Potential Optimization Pitfalls](#potential-optimization-pitfalls) - - [Setting Up SSL](#setting-up-ssl) - - [Linting](#linting) - - [Setup Guide for VS Code Users](#setup-guide-for-vs-code-users) - - [Internationalization](#internationalization) - - [Localization](#localization) - - [Styling with SASS](#styling-with-sass) - - [Testing and Building](#testing-and-building) - - [Debugging server code](#debugging-server-code) - - [Instrumenting with Elastic APM](#instrumenting-with-elastic-apm) - - [Unit testing frameworks](#unit-testing-frameworks) - - [Running specific Kibana tests](#running-specific-kibana-tests) - - [Debugging Unit Tests](#debugging-unit-tests) - - [Unit Testing Plugins](#unit-testing-plugins) - - [Automated Accessibility Testing](#automated-accessibility-testing) - - [Cross-browser compatibility](#cross-browser-compatibility) - - [Testing compatibility locally](#testing-compatibility-locally) - - [Running Browser Automation Tests](#running-browser-automation-tests) - - [Building OS packages](#building-os-packages) - - [Writing documentation](#writing-documentation) - - [Release Notes Process](#release-notes-process) -- [Signing the contributor license agreement](#signing-the-contributor-license-agreement) -- [Submitting a Pull Request](#submitting-a-pull-request) -- [Code Reviewing](#code-reviewing) - - [Getting to the Code Review Stage](#getting-to-the-code-review-stage) - - [Reviewing Pull Requests](#reviewing-pull-requests) - -Don't fret, it's not as daunting as the table of contents makes it out to be! - -## Effective issue reporting in Kibana - -### Voicing the importance of an issue - -We seriously appreciate thoughtful comments. If an issue is important to you, add a comment with a solid write up of your use case and explain why it's so important. Please avoid posting comments comprised solely of a thumbs up emoji 👍. - -Granted that you share your thoughts, we might even be able to come up with creative solutions to your specific problem. If everything you'd like to say has already been brought up but you'd still like to add a token of support, feel free to add a [👍 thumbs up reaction](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments) on the issue itself and on the comment which best summarizes your thoughts. - -### "My issue isn't getting enough attention" - -First of all, **sorry about that!** We want you to have a great time with Kibana. - -There's hundreds of open issues and prioritizing what to work on is an important aspect of our daily jobs. We prioritize issues according to impact and difficulty, so some issues can be neglected while we work on more pressing issues. - -Feel free to bump your issues if you think they've been neglected for a prolonged period. - -### "I want to help!" - -**Now we're talking**. If you have a bug fix or new feature that you would like to contribute to Kibana, please **find or open an issue about it before you start working on it.** Talk about what you would like to do. It may be that somebody is already working on it, or that there are particular issues that you should know about before implementing the change. - -We enjoy working with contributors to get their code accepted. There are many approaches to fixing a problem and it is important to find the best approach before writing too much code. - -## How We Use Git and GitHub - -### Forking - -We follow the [GitHub forking model](https://help.github.com/articles/fork-a-repo/) for collaborating -on Kibana code. This model assumes that you have a remote called `upstream` which points to the -official Kibana repo, which we'll refer to in later code snippets. - -### Branching - -* All work on the next major release goes into master. -* Past major release branches are named `{majorVersion}.x`. They contain work that will go into the next minor release. For example, if the next minor release is `5.2.0`, work for it should go into the `5.x` branch. -* Past minor release branches are named `{majorVersion}.{minorVersion}`. They contain work that will go into the next patch release. For example, if the next patch release is `5.3.1`, work for it should go into the `5.3` branch. -* All work is done on feature branches and merged into one of these branches. -* Where appropriate, we'll backport changes into older release branches. - -### Commits and Merging - -* Feel free to make as many commits as you want, while working on a branch. -* When submitting a PR for review, please perform an interactive rebase to present a logical history that's easy for the reviewers to follow. -* Please use your commit messages to include helpful information on your changes, e.g. changes to APIs, UX changes, bugs fixed, and an explanation of *why* you made the changes that you did. -* Resolve merge conflicts by rebasing the target branch over your feature branch, and force-pushing (see below for instructions). -* When merging, we'll squash your commits into a single commit. - -#### Rebasing and fixing merge conflicts - -Rebasing can be tricky, and fixing merge conflicts can be even trickier because it involves force pushing. This is all compounded by the fact that attempting to push a rebased branch remotely will be rejected by git, and you'll be prompted to do a `pull`, which is not at all what you should do (this will really mess up your branch's history). - -Here's how you should rebase master onto your branch, and how to fix merge conflicts when they arise. - -First, make sure master is up-to-date. - -``` -git checkout master -git fetch upstream -git rebase upstream/master -``` - -Then, check out your branch and rebase master on top of it, which will apply all of the new commits on master to your branch, and then apply all of your branch's new commits after that. - -``` -git checkout name-of-your-branch -git rebase master -``` - -You want to make sure there are no merge conflicts. If there are merge conflicts, git will pause the rebase and allow you to fix the conflicts before continuing. - -You can use `git status` to see which files contain conflicts. They'll be the ones that aren't staged for commit. Open those files, and look for where git has marked the conflicts. Resolve the conflicts so that the changes you want to make to the code have been incorporated in a way that doesn't destroy work that's been done in master. Refer to master's commit history on GitHub if you need to gain a better understanding of how code is conflicting and how best to resolve it. - -Once you've resolved all of the merge conflicts, use `git add -A` to stage them to be committed, and then use `git rebase --continue` to tell git to continue the rebase. - -When the rebase has completed, you will need to force push your branch because the history is now completely different than what's on the remote. **This is potentially dangerous** because it will completely overwrite what you have on the remote, so you need to be sure that you haven't lost any work when resolving merge conflicts. (If there weren't any merge conflicts, then you can force push without having to worry about this.) - -``` -git push origin name-of-your-branch --force -``` - -This will overwrite the remote branch with what you have locally. You're done! - -**Note that you should not run `git pull`**, for example in response to a push rejection like this: - -``` -! [rejected] name-of-your-branch -> name-of-your-branch (non-fast-forward) -error: failed to push some refs to 'https://github.com/YourGitHubHandle/kibana.git' -hint: Updates were rejected because the tip of your current branch is behind -hint: its remote counterpart. Integrate the remote changes (e.g. -hint: 'git pull ...') before pushing again. -hint: See the 'Note about fast-forwards' in 'git push --help' for details. -``` - -Assuming you've successfully rebased and you're happy with the code, you should force push instead. - -### What Goes Into a Pull Request - -* Please include an explanation of your changes in your PR description. -* Links to relevant issues, external resources, or related PRs are very important and useful. -* Please update any tests that pertain to your code, and add new tests where appropriate. -* See [Submitting a Pull Request](#submitting-a-pull-request) for more info. - -## Contributing Code - -These guidelines will help you get your Pull Request into shape so that a code review can start as soon as possible. - -### Setting Up Your Development Environment - -Fork, then clone the `kibana` repo and change directory into it - -```bash -git clone https://github.com/[YOUR_USERNAME]/kibana.git kibana -cd kibana -``` - -Install the version of Node.js listed in the `.node-version` file. This can be automated with tools such as [nvm](https://github.com/creationix/nvm), [nvm-windows](https://github.com/coreybutler/nvm-windows) or [avn](https://github.com/wbyoung/avn). As we also include a `.nvmrc` file you can switch to the correct version when using nvm by running: - -```bash -nvm use -``` - -Install the latest version of [yarn](https://yarnpkg.com). - -Bootstrap Kibana and install all the dependencies - -```bash -yarn kbn bootstrap -``` - -> Node.js native modules could be in use and node-gyp is the tool used to build them. There are tools you need to install per platform and python versions you need to be using. Please see https://github.com/nodejs/node-gyp#installation and follow the guide according your platform. - -(You can also run `yarn kbn` to see the other available commands. For more info about this tool, see https://github.com/elastic/kibana/tree/master/packages/kbn-pm.) - -When switching branches which use different versions of npm packages you may need to run; -```bash -yarn kbn clean -``` - -If you have failures during `yarn kbn bootstrap` you may have some corrupted packages in your yarn cache which you can clean with; -```bash -yarn cache clean -``` - -#### Increase node.js heap size - -Kibana is a big project and for some commands it can happen that the process hits the default heap limit and crashes with an out-of-memory error. If you run into this problem, you can increase maximum heap size by setting the `--max_old_space_size` option on the command line. To set the limit for all commands, simply add the following line to your shell config: `export NODE_OPTIONS="--max_old_space_size=2048"`. - -### Running Elasticsearch Locally - -There are a few options when it comes to running Elasticsearch locally: - -#### Nightly snapshot (recommended) - -These snapshots are built on a nightly basis which expire after a couple weeks. If running from an old, untracted branch this snapshot might not exist. In which case you might need to run from source or an archive. - -```bash -yarn es snapshot -``` - -##### Keeping data between snapshots - -If you want to keep the data inside your Elasticsearch between usages of this command, -you should use the following command, to keep your data folder outside the downloaded snapshot -folder: - -```bash -yarn es snapshot -E path.data=../data -``` - -The same parameter can be used with the source and archive command shown in the following -paragraphs. - -#### Source - -By default, it will reference an [elasticsearch](https://github.com/elastic/elasticsearch) checkout which is a sibling to the Kibana directory named `elasticsearch`. If you wish to use a checkout in another location you can provide that by supplying `--source-path` - -```bash -yarn es source -``` - -#### Archive - -Use this if you already have a distributable. For released versions, one can be obtained on the [Elasticsearch downloads](https://www.elastic.co/downloads/elasticsearch) page. - -```bash -yarn es archive -``` - -**Each of these will run Elasticsearch with a `basic` license. Additional options are available, pass `--help` for more information.** - -##### Sample Data - -If you're just getting started with Elasticsearch, you could use the following command to populate your instance with a few fake logs to hit the ground running. - -```bash -node scripts/makelogs --auth : -``` -> The default username and password combination are `elastic:changeme` - -> Make sure to execute `node scripts/makelogs` *after* elasticsearch is up and running! - -### Running Elasticsearch Remotely - -You can save some system resources, and the effort of generating sample data, if you have a remote Elasticsearch cluster to connect to. (**Elasticians: you do! Check with your team about where to find credentials**) - -You'll need to [create a `kibana.dev.yml`](#customizing-configkibanadevyml) and add the following to it: - -``` -elasticsearch.hosts: - - {{ url }} -elasticsearch.username: {{ username }} -elasticsearch.password: {{ password }} -elasticsearch.ssl.verificationMode: none -``` - -If many other users will be interacting with your remote cluster, you'll want to add the following to avoid causing conflicts: - -``` -kibana.index: '.{YourGitHubHandle}-kibana' -xpack.task_manager.index: '.{YourGitHubHandle}-task-manager-kibana' -``` - -### Running remote clusters -Setup remote clusters for cross cluster search (CCS) and cross cluster replication (CCR). - -Start your primary cluster by running: -```bash -yarn es snapshot -E path.data=../data_prod1 -``` - -Start your remote cluster by running: -```bash -yarn es snapshot -E transport.port=9500 -E http.port=9201 -E path.data=../data_prod2 -``` - -Once both clusters are running, start kibana. Kibana will connect to the primary cluster. - -Setup the remote cluster in Kibana from either `Management` -> `Elasticsearch` -> `Remote Clusters` UI or by running the following script in `Console`. -``` -PUT _cluster/settings -{ - "persistent": { - "cluster": { - "remote": { - "cluster_one": { - "seeds": [ - "localhost:9500" - ] - } - } - } - } -} -``` - -Follow the [cross-cluster search](https://www.elastic.co/guide/en/kibana/current/management-cross-cluster-search.html) instructions for setting up index patterns to search across clusters. - -### Running Kibana - -Change to your local Kibana directory. -Start the development server. - -```bash -yarn start -``` - -> On Windows, you'll need to use Git Bash, Cygwin, or a similar shell that exposes the `sh` command. And to successfully build you'll need Cygwin optional packages zip, tar, and shasum. - -Now you can point your web browser to http://localhost:5601 and start using Kibana! When running `yarn start`, Kibana will also log that it is listening on port 5603 due to the base path proxy, but you should still access Kibana on port 5601. - -By default, you can log in with username `elastic` and password `changeme`. See the `--help` options on `yarn es ` if you'd like to configure a different password. - -#### Running Kibana in Open-Source mode - -If you're looking to only work with the open-source software, supply the license type to `yarn es`: - -```bash -yarn es snapshot --license oss -``` - -And start Kibana with only open-source code: - -```bash -yarn start --oss -``` - -#### Unsupported URL Type - -If you're installing dependencies and seeing an error that looks something like - -``` -Unsupported URL Type: link:packages/eslint-config-kibana -``` - -you're likely running `npm`. To install dependencies in Kibana you need to run `yarn kbn bootstrap`. For more info, see [Setting Up Your Development Environment](#setting-up-your-development-environment) above. - -#### Customizing `config/kibana.dev.yml` - -The `config/kibana.yml` file stores user configuration directives. Since this file is checked into source control, however, developer preferences can't be saved without the risk of accidentally committing the modified version. To make customizing configuration easier during development, the Kibana CLI will look for a `config/kibana.dev.yml` file if run with the `--dev` flag. This file behaves just like the non-dev version and accepts any of the [standard settings](https://www.elastic.co/guide/en/kibana/current/settings.html). - -#### Potential Optimization Pitfalls - - - Webpack is trying to include a file in the bundle that I deleted and is now complaining about it is missing - - A module id that used to resolve to a single file now resolves to a directory, but webpack isn't adapting - - (if you discover other scenarios, please send a PR!) - -#### Setting Up SSL - -Kibana includes self-signed certificates that can be used for development purposes in the browser and for communicating with Elasticsearch: `yarn start --ssl` & `yarn es snapshot --ssl`. - -### Linting - -A note about linting: We use [eslint](http://eslint.org) to check that the [styleguide](STYLEGUIDE.md) is being followed. It runs in a pre-commit hook and as a part of the tests, but most contributors integrate it with their code editors for real-time feedback. - -Here are some hints for getting eslint setup in your favorite editor: - -Editor | Plugin ------------|------------------------------------------------------------------------------- -Sublime | [SublimeLinter-eslint](https://github.com/roadhump/SublimeLinter-eslint#installation) -Atom | [linter-eslint](https://github.com/AtomLinter/linter-eslint#installation) -VSCode | [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) -IntelliJ | Settings » Languages & Frameworks » JavaScript » Code Quality Tools » ESLint -`vi` | [scrooloose/syntastic](https://github.com/scrooloose/syntastic) - -Another tool we use for enforcing consistent coding style is EditorConfig, which can be set up by installing a plugin in your editor that dynamically updates its configuration. Take a look at the [EditorConfig](http://editorconfig.org/#download) site to find a plugin for your editor, and browse our [`.editorconfig`](https://github.com/elastic/kibana/blob/master/.editorconfig) file to see what config rules we set up. - -#### Setup Guide for VS Code Users - -Note that for VSCode, to enable "live" linting of TypeScript (and other) file types, you will need to modify your local settings, as shown below. The default for the ESLint extension is to only lint JavaScript file types. - -```json -"eslint.validate": [ - "javascript", - "javascriptreact", - { "language": "typescript", "autoFix": true }, - { "language": "typescriptreact", "autoFix": true } -] -``` - -`eslint` can automatically fix trivial lint errors when you save a file by adding this line in your setting. - -```json - "eslint.autoFixOnSave": true, -``` - -:warning: It is **not** recommended to use the [`Prettier` extension/IDE plugin](https://prettier.io/) while maintaining the Kibana project. Formatting and styling roles are set in the multiple `.eslintrc.js` files across the project and some of them use the [NPM version of Prettier](https://www.npmjs.com/package/prettier). Using the IDE extension might cause conflicts, applying the formatting to too many files that shouldn't be prettier-ized and/or highlighting errors that are actually OK. - -### Internationalization - -All user-facing labels and info texts in Kibana should be internationalized. Please take a look at the [readme](packages/kbn-i18n/README.md) and the [guideline](packages/kbn-i18n/GUIDELINE.md) of the i18n package on how to do so. - -In order to enable translations in the React parts of the application, the top most component of every `ReactDOM.render` call should be the `Context` component from the `i18n` core service: -```jsx -const I18nContext = coreStart.i18n.Context; - -ReactDOM.render( - - {myComponentTree} - , - container -); -``` - -There are a number of tools created to support internationalization in Kibana that would allow one to validate internationalized labels, -extract them to a `JSON` file or integrate translations back to Kibana. To know more, please read corresponding [readme](src/dev/i18n/README.md) file. - -### Localization - -We cannot support accepting contributions to the translations from any source other than the translators we have engaged to do the work. -We are still to develop a proper process to accept any contributed translations. We certainly appreciate that people care enough about the localization effort to want to help improve the quality. We aim to build out a more comprehensive localization process for the future and will notify you once contributions can be supported, but for the time being, we are not able to incorporate suggestions. - -### Styling with SASS - -When writing a new component, create a sibling SASS file of the same name and import directly into the JS/TS component file. Doing so ensures the styles are never separated or lost on import and allows for better modularization (smaller individual plugin asset footprint). - -All SASS (.scss) files will automatically build with the [EUI](https://elastic.github.io/eui/#/guidelines/sass) & Kibana invisibles (SASS variables, mixins, functions) from the [`globals_[theme].scss` file](src/legacy/ui/public/styles/_globals_v7light.scss). - -**Example:** - -```tsx -// component.tsx - -import './component.scss'; - -export const Component = () => { - return ( -
- ); -} -``` - -```scss -// component.scss - -.plgComponent { ... } -``` - -Do not use the underscore `_` SASS file naming pattern when importing directly into a javascript file. - -### Testing and Building - -To ensure that your changes will not break other functionality, please run the test suite and build process before submitting your Pull Request. - -Before running the tests you will need to install the projects dependencies as described above. - -Once that's done, just run: - -```bash -yarn test && yarn build --skip-os-packages -``` - -You can get all build options using the following command: - -```bash -yarn build --help -``` - -macOS users on a machine with a discrete graphics card may see significant speedups (up to 2x) when running tests by changing your terminal emulator's GPU settings. In iTerm2: -- Open Preferences (Command + ,) -- In the General tab, under the "Magic" section, ensure "GPU rendering" is checked -- Open "Advanced GPU Settings..." -- Uncheck the "Prefer integrated to discrete GPU" option -- Restart iTerm - -#### Debugging Server Code -`yarn debug` will start the server with Node's inspect flag. Kibana's development mode will start three processes on ports `9229`, `9230`, and `9231`. Chrome's developer tools need to be configured to connect to all three connections. Add `localhost:` for each Kibana process in Chrome's developer tools connection tab. - -#### Instrumenting with Elastic APM -Kibana ships with the [Elastic APM Node.js Agent](https://github.com/elastic/apm-agent-nodejs) built-in for debugging purposes. - -Its default configuration is meant to be used by core Kibana developers only, but it can easily be re-configured to your needs. -In its default configuration it's disabled and will, once enabled, send APM data to a centrally managed Elasticsearch cluster accessible only to Elastic employees. - -To change the location where data is sent, use the [`serverUrl`](https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#server-url) APM config option. -To activate the APM agent, use the [`active`](https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#active) APM config option. - -All config options can be set either via environment variables, or by creating an appropriate config file under `config/apm.dev.js`. -For more information about configuring the APM agent, please refer to [the documentation](https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuring-the-agent.html). - -Example `config/apm.dev.js` file: - -```js -module.exports = { - active: true, -}; -``` - -APM [Real User Monitoring agent](https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html) is not available in the Kibana distributables, -however the agent can be enabled by setting `ELASTIC_APM_ACTIVE` to `true`. -flags -``` -ELASTIC_APM_ACTIVE=true yarn start -// activates both Node.js and RUM agent -``` - -Once the agent is active, it will trace all incoming HTTP requests to Kibana, monitor for errors, and collect process-level metrics. -The collected data will be sent to the APM Server and is viewable in the APM UI in Kibana. - -#### Unit testing frameworks -Kibana is migrating unit testing from Mocha to Jest. Legacy unit tests still -exist in Mocha but all new unit tests should be written in Jest. Mocha tests -are contained in `__tests__` directories. Whereas Jest tests are stored in -the same directory as source code files with the `.test.js` suffix. - -#### Running specific Kibana tests - -The following table outlines possible test file locations and how to invoke them: - -| Test runner | Test location | Runner command (working directory is kibana root) | -| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | -| Jest | `src/**/*.test.js`
`src/**/*.test.ts` | `yarn test:jest -t regexp [test path]` | -| Jest (integration) | `**/integration_tests/**/*.test.js` | `yarn test:jest_integration -t regexp [test path]` | -| Mocha | `src/**/__tests__/**/*.js`
`!src/**/public/__tests__/*.js`
`packages/kbn-datemath/test/**/*.js`
`packages/kbn-dev-utils/src/**/__tests__/**/*.js`
`tasks/**/__tests__/**/*.js` | `node scripts/mocha --grep=regexp [test path]` | -| Functional | `test/*integration/**/config.js`
`test/*functional/**/config.js`
`test/accessibility/config.js` | `yarn test:ftr:server --config test/[directory]/config.js`
`yarn test:ftr:runner --config test/[directory]/config.js --grep=regexp` | -| Karma | `src/**/public/__tests__/*.js` | `yarn test:karma:debug` | - -For X-Pack tests located in `x-pack/` see [X-Pack Testing](x-pack/README.md#testing) - -Test runner arguments: - - Where applicable, the optional arguments `-t=regexp` or `--grep=regexp` will only run tests or test suites whose descriptions matches the regular expression. - - `[test path]` is the relative path to the test file. - - Examples: - - Run the entire elasticsearch_service test suite: - ``` - yarn test:jest src/core/server/elasticsearch/elasticsearch_service.test.ts - ``` - - Run the jest test case whose description matches `stops both admin and data clients`: - ``` - yarn test:jest -t 'stops both admin and data clients' src/core/server/elasticsearch/elasticsearch_service.test.ts - ``` - - Run the api integration test case whose description matches the given string: - ``` - yarn test:ftr:server --config test/api_integration/config.js - yarn test:ftr:runner --config test/api_integration/config.js --grep='should return 404 if id does not match any sample data sets' - ``` - -#### Debugging Unit Tests - -The standard `yarn test` task runs several sub tasks and can take several minutes to complete, making debugging failures pretty painful. In order to ease the pain specialized tasks provide alternate methods for running the tests. - -You could also add the `--debug` option so that `node` is run using the `--debug-brk` flag. You'll need to connect a remote debugger such as [`node-inspector`](https://github.com/node-inspector/node-inspector) to proceed in this mode. - -```bash -node scripts/mocha --debug -``` - -With `yarn test:karma`, you can run only the browser tests. Coverage reports are available for browser tests by running `yarn test:coverage`. You can find the results under the `coverage/` directory that will be created upon completion. - -```bash -yarn test:karma -``` - -Using `yarn test:karma:debug` initializes an environment for debugging the browser tests. Includes an dedicated instance of the kibana server for building the test bundle, and a karma server. When running this task the build is optimized for the first time and then a karma-owned instance of the browser is opened. Click the "debug" button to open a new tab that executes the unit tests. - -```bash -yarn test:karma:debug -``` - -In the screenshot below, you'll notice the URL is `localhost:9876/debug.html`. You can append a `grep` query parameter to this URL and set it to a string value which will be used to exclude tests which don't match. For example, if you changed the URL to `localhost:9876/debug.html?query=my test` and then refreshed the browser, you'd only see tests run which contain "my test" in the test description. - - -![Browser test debugging](http://i.imgur.com/DwHxgfq.png) - -#### Unit Testing Plugins - -This should work super if you're using the [Kibana plugin generator](https://github.com/elastic/kibana/tree/master/packages/kbn-plugin-generator). If you're not using the generator, well, you're on your own. We suggest you look at how the generator works. - -To run the tests for just your particular plugin run the following command from your plugin: - -```bash -yarn test:mocha -yarn test:karma:debug # remove the debug flag to run them once and close -``` - -#### Automated Accessibility Testing - -To run the tests locally: - -1. In one terminal window run `node scripts/functional_tests_server --config test/accessibility/config.ts` -2. In another terminal window run `node scripts/functional_test_runner.js --config test/accessibility/config.ts` - -To run the x-pack tests, swap the config file out for `x-pack/test/accessibility/config.ts`. - -After the server is up, you can go to this instance of Kibana at `localhost:5620`. - -The testing is done using [axe](https://github.com/dequelabs/axe-core). The same thing that runs in CI, -can be run locally using their browser plugins: - -- [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US) -- [Firefox](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/) - -#### Cross-browser Compatibility - -##### Testing Compatibility Locally - -###### Testing IE on OS X - -* [Download VMWare Fusion](http://www.vmware.com/products/fusion/fusion-evaluation.html). -* [Download IE virtual machines](https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/#downloads) for VMWare. -* Open VMWare and go to Window > Virtual Machine Library. Unzip the virtual machine and drag the .vmx file into your Virtual Machine Library. -* Right-click on the virtual machine you just added to your library and select "Snapshots...", and then click the "Take" button in the modal that opens. You can roll back to this snapshot when the VM expires in 90 days. -* In System Preferences > Sharing, change your computer name to be something simple, e.g. "computer". -* Run Kibana with `yarn start --host=computer.local` (substituting your computer name). -* Now you can run your VM, open the browser, and navigate to `http://computer.local:5601` to test Kibana. -* Alternatively you can use browserstack - -##### Running Browser Automation Tests - -[Read about the `FunctionalTestRunner`](https://www.elastic.co/guide/en/kibana/current/development-functional-tests.html) to learn more about how you can run and develop functional tests for Kibana core and plugins. - -You can also look into the [Scripts README.md](./scripts/README.md) to learn more about using the node scripts we provide for building Kibana, running integration tests, and starting up Kibana and Elasticsearch while you develop. - -### Building OS packages - -Packages are built using fpm, dpkg, and rpm. Package building has only been tested on Linux and is not supported on any other platform. - -```bash -apt-get install ruby-dev rpm -gem install fpm -v 1.5.0 -yarn build --skip-archives -``` - -To specify a package to build you can add `rpm` or `deb` as an argument. - -```bash -yarn build --rpm -``` - -Distributable packages can be found in `target/` after the build completes. - -### Writing documentation - -Kibana documentation is written in [asciidoc](http://asciidoc.org/) format in -the `docs/` directory. - -To build the docs, clone the [elastic/docs](https://github.com/elastic/docs) -repo as a sibling of your Kibana repo. Follow the instructions in that project's -README for getting the docs tooling set up. - -**To build the Kibana docs and open them in your browser:** - -```bash -./docs/build_docs --doc kibana/docs/index.asciidoc --chunk 1 --open -``` -or - -```bash -node scripts/docs.js --open -``` - -### Release Notes process - -Part of this process only applies to maintainers, since it requires access to GitHub labels. - -Kibana publishes [Release Notes](https://www.elastic.co/guide/en/kibana/current/release-notes.html) for major and minor releases. The Release Notes summarize what the PRs accomplish in language that is meaningful to users. To generate the Release Notes, the team runs a script against this repo to collect the merged PRs against the release. - -#### Create the Release Notes text -The text that appears in the Release Notes is pulled directly from your PR title, or a single paragraph of text that you specify in the PR description. - -To use a single paragraph of text, enter `Release note:` or a `## Release note` header in the PR description, followed by your text. For example, refer to this [PR](https://github.com/elastic/kibana/pull/65796) that uses the `## Release note` header. - -When you create the Release Notes text, use the following best practices: -* Use present tense. -* Use sentence case. -* When you create a feature PR, start with `Adds`. -* When you create an enhancement PR, start with `Improves`. -* When you create a bug fix PR, start with `Fixes`. -* When you create a deprecation PR, start with `Deprecates`. - -#### Add your labels -1. Label the PR with the targeted version (ex: `v7.3.0`). -2. Label the PR with the appropriate GitHub labels: - * For a new feature or functionality, use `release_note:enhancement`. - * For an external-facing fix, use `release_note:fix`. We do not include docs, build, and test fixes in the Release Notes, or unreleased issues that are only on `master`. - * For a deprecated feature, use `release_note:deprecation`. - * For a breaking change, use `release_note:breaking`. - * To **NOT** include your changes in the Release Notes, use `release_note:skip`. - -We also produce a blog post that details more important breaking API changes in every major and minor release. When your PR includes a breaking API change, add the `release_note:dev_docs` label, and add a brief summary of the break at the bottom of the PR using the format below: - -``` -# Dev Docs - -## Name the feature with the break (ex: Visualize Loader) - -Summary of the change. Anything Under `#Dev Docs` is used in the blog. -``` - -## Signing the contributor license agreement - -Please make sure you have signed the [Contributor License Agreement](http://www.elastic.co/contributor-agreement/). We are not asking you to assign copyright to us, but to give us the right to distribute your code without restriction. We ask this of all contributors in order to assure our users of the origin and continuing existence of the code. You only need to sign the CLA once. - -## Submitting a Pull Request - -Push your local changes to your forked copy of the repository and submit a Pull Request. In the Pull Request, describe what your changes do and mention the number of the issue where discussion has taken place, e.g., “Closes #123″. - -Always submit your pull against `master` unless the bug is only present in an older version. If the bug affects both `master` and another branch say so in your pull. - -Then sit back and wait. There will probably be discussion about the Pull Request and, if any changes are needed, we'll work with you to get your Pull Request merged into Kibana. - -## Code Reviewing - -After a pull is submitted, it needs to get to review. If you have commit permission on the Kibana repo you will probably perform these steps while submitting your Pull Request. If not, a member of the Elastic organization will do them for you, though you can help by suggesting a reviewer for your changes if you've interacted with someone while working on the issue. - -### Getting to the Code Review Stage - -1. Assign the `review` label. This signals to the team that someone needs to give this attention. -1. Do **not** assign a version label. Someone from Elastic staff will assign a version label, if necessary, when your Pull Request is ready to be merged. -1. Find someone to review your pull. Don't just pick any yahoo, pick the right person. The right person might be the original reporter of the issue, but it might also be the person most familiar with the code you've changed. If neither of those things apply, or your change is small in scope, try to find someone on the Kibana team without a ton of existing reviews on their plate. As a rule, most pulls will require 2 reviewers, but the first reviewer will pick the 2nd. - -### Reviewing Pull Requests - -So, you've been assigned a pull to review. Check out our [pull request review guidelines](https://www.elastic.co/guide/en/kibana/master/pr-review.html) for our general philosophy for pull request reviewers. - -Thank you so much for reading our guidelines! :tada: +Our developer guide is written in asciidoc and located under [./docs/developer](./docs/developer) if you want to make edits or access it in raw form. diff --git a/docs/developer/add-data-guide.asciidoc b/docs/developer/add-data-guide.asciidoc deleted file mode 100644 index e00e46868bb2d..0000000000000 --- a/docs/developer/add-data-guide.asciidoc +++ /dev/null @@ -1,38 +0,0 @@ -[[add-data-guide]] -== Add Data Guide - -`Add Data` in the Kibana Home application contains tutorials for setting up data flows in the Elastic stack. - -Each tutorial contains three sets of instructions: - -* `On Premise.` Set up a data flow when both Kibana and Elasticsearch are running on premise. -* `On Premise Elastic Cloud.` Set up a data flow when Kibana is running on premise and Elasticsearch is running on Elastic Cloud. -* `Elastic Cloud.` Set up a data flow when both Kibana and Elasticsearch are running on Elastic Cloud. - -[float] -=== Creating a new tutorial -1. Create a new directory in the link:https://github.com/elastic/kibana/tree/master/src/plugins/home/server/tutorials[tutorials directory]. -2. In the new directory, create a file called `index.ts` that exports a function. -The function must return a function object that conforms to the `TutorialSchema` interface link:https://github.com/elastic/kibana/blob/master/src/plugins/home/server/services/tutorials/lib/tutorial_schema.ts[tutorial schema]. -3. Register the tutorial in link:https://github.com/elastic/kibana/blob/master/src/plugins/home/server/tutorials/register.ts[register.ts] by adding it to the `builtInTutorials`. -// TODO update path once assets are migrated -4. Add image assets to the link:https://github.com/elastic/kibana/tree/master/src/legacy/core_plugins/kibana/public/home/tutorial_resources[tutorial_resources directory]. -5. Run Kibana locally to preview the tutorial. -6. Create a PR and go through the review process to get the changes approved. - -If you are creating a new plugin and the tutorial is only related to that plugin, you can also place the `TutorialSchema` object into your plugin folder. Add `home` to the `requiredPlugins` list in your `kibana.json` file. -Then register the tutorial object by calling `home.tutorials.registerTutorial(tutorialObject)` in the `setup` lifecycle of your server plugin. - -[float] -==== Variables -String values can contain variables that are substituted when rendered. Variables are specified by `{}`. -For example: `{config.docs.version}` is rendered as `6.2` when running the tutorial in Kibana 6.2. - -link:https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/replace_template_strings.js#L23[Provided variables] - -[float] -==== Markdown -String values can contain limited Markdown syntax. - -link:https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/kibana/public/home/components/tutorial/content.js#L8[Enabled Markdown grammars] - diff --git a/docs/developer/advanced/development-basepath.asciidoc b/docs/developer/advanced/development-basepath.asciidoc new file mode 100644 index 0000000000000..f0b760a21ea0c --- /dev/null +++ b/docs/developer/advanced/development-basepath.asciidoc @@ -0,0 +1,18 @@ +[[development-basepath]] +=== Considerations for basepath + +In dev mode, {kib} by default runs behind a proxy which adds a random path component to its URL. + +You can set this explicitly using `server.basePath` in <>. + +Use the server.rewriteBasePath setting to tell {kib} if it should remove the basePath from requests it receives, and to prevent a deprecation warning at startup. This setting cannot end in a slash (/). + +If you want to turn off the basepath when in development mode, start {kib} with the `--no-basepath` flag + +[source,bash] +---- +yarn start --no-basepath +---- + + + diff --git a/docs/developer/core/development-es-snapshots.asciidoc b/docs/developer/advanced/development-es-snapshots.asciidoc similarity index 90% rename from docs/developer/core/development-es-snapshots.asciidoc rename to docs/developer/advanced/development-es-snapshots.asciidoc index 4cd4f31e582db..92fae7a241edf 100644 --- a/docs/developer/core/development-es-snapshots.asciidoc +++ b/docs/developer/advanced/development-es-snapshots.asciidoc @@ -1,7 +1,7 @@ [[development-es-snapshots]] === Daily Elasticsearch Snapshots -For local development and CI, Kibana, by default, uses Elasticsearch snapshots that are built daily when running tasks that require Elasticsearch (e.g. functional tests). +For local development and CI, {kib}, by default, uses Elasticsearch snapshots that are built daily when running tasks that require Elasticsearch (e.g. functional tests). A snapshot is just a group of tarballs, one for each supported distribution/architecture/os of Elasticsearch, and a JSON-based manifest file containing metadata about the distributions. @@ -9,13 +9,13 @@ https://ci.kibana.dev/es-snapshots[A dashboard] is available that shows the curr ==== Process Overview -1. Elasticsearch snapshots are built for each current tracked branch of Kibana. +1. Elasticsearch snapshots are built for each current tracked branch of {kib}. 2. Each snapshot is uploaded to a public Google Cloud Storage bucket, `kibana-ci-es-snapshots-daily`. ** At this point, the snapshot is not automatically used in CI or local development. It needs to be tested/verified first. -3. Each snapshot is tested with the latest commit of the corresponding Kibana branch, using the full CI suite. +3. Each snapshot is tested with the latest commit of the corresponding {kib} branch, using the full CI suite. 4. After CI ** If the snapshot passes, it is promoted and automatically used in CI and local development. -** If the snapshot fails, the issue must be investigated and resolved. A new incompatibility may exist between Elasticsearch and Kibana. +** If the snapshot fails, the issue must be investigated and resolved. A new incompatibility may exist between Elasticsearch and {kib}. ==== Using the latest snapshot @@ -39,7 +39,7 @@ KBN_ES_SNAPSHOT_USE_UNVERIFIED=true node scripts/functional_tests_server Currently, there is not a way to run your pull request with the latest unverified snapshot without a code change. You can, however, do it with a small code change. -1. Edit `Jenkinsfile` in the root of the Kibana repo +1. Edit `Jenkinsfile` in the root of the {kib} repo 2. Add `env.KBN_ES_SNAPSHOT_USE_UNVERIFIED = 'true'` at the top of the file. 3. Commit the change @@ -75,13 +75,13 @@ The file structure for this bucket looks like this: ==== How snapshots are built, tested, and promoted -Each day, a https://kibana-ci.elastic.co/job/elasticsearch+snapshots+trigger/[Jenkins job] runs that triggers Elasticsearch builds for each currently tracked branch/version. This job is automatically updated with the correct branches whenever we release new versions of Kibana. +Each day, a https://kibana-ci.elastic.co/job/elasticsearch+snapshots+trigger/[Jenkins job] runs that triggers Elasticsearch builds for each currently tracked branch/version. This job is automatically updated with the correct branches whenever we release new versions of {kib}. ===== Build https://kibana-ci.elastic.co/job/elasticsearch+snapshots+build/[This Jenkins job] builds the Elasticsearch snapshots and uploads them to GCS. -The Jenkins job pipeline definition is https://github.com/elastic/kibana/blob/master/.ci/es-snapshots/Jenkinsfile_build_es[in the kibana repo]. +The Jenkins job pipeline definition is https://github.com/elastic/kibana/blob/master/.ci/es-snapshots/Jenkinsfile_build_es[in the {kib} repo]. 1. Checkout Elasticsearch repo for the given branch/version. 2. Run `./gradlew -p distribution/archives assemble --parallel` to create all of the Elasticsearch distributions. @@ -91,15 +91,15 @@ The Jenkins job pipeline definition is https://github.com/elastic/kibana/blob/ma ** e.g. `/archives/` 6. Replace `/manifest-latest.json` in GCS with this newest manifest. ** This allows the `KBN_ES_SNAPSHOT_USE_UNVERIFIED` flag to work. -7. Trigger the verification job, to run the full Kibana CI test suite with this snapshot. +7. Trigger the verification job, to run the full {kib} CI test suite with this snapshot. ===== Verification and Promotion -https://kibana-ci.elastic.co/job/elasticsearch+snapshots+verify/[This Jenkins job] tests the latest Elasticsearch snapshot with the full Kibana CI pipeline, and promotes if it there are no test failures. +https://kibana-ci.elastic.co/job/elasticsearch+snapshots+verify/[This Jenkins job] tests the latest Elasticsearch snapshot with the full {kib} CI pipeline, and promotes if it there are no test failures. -The Jenkins job pipeline definition is https://github.com/elastic/kibana/blob/master/.ci/es-snapshots/Jenkinsfile_verify_es[in the kibana repo]. +The Jenkins job pipeline definition is https://github.com/elastic/kibana/blob/master/.ci/es-snapshots/Jenkinsfile_verify_es[in the {kib} repo]. -1. Checkout Kibana and set up CI environment as normal. +1. Checkout {kib} and set up CI environment as normal. 2. Set the `ES_SNAPSHOT_MANIFEST` env var to point to the latest snapshot manifest. 3. Run CI (functional tests, integration tests, etc). 4. After CI diff --git a/docs/developer/advanced/index.asciidoc b/docs/developer/advanced/index.asciidoc new file mode 100644 index 0000000000000..139940ee42fe2 --- /dev/null +++ b/docs/developer/advanced/index.asciidoc @@ -0,0 +1,12 @@ +[[advanced]] +== Advanced + +* <> +* <> +* <> + +include::development-es-snapshots.asciidoc[] + +include::running-elasticsearch.asciidoc[] + +include::development-basepath.asciidoc[] \ No newline at end of file diff --git a/docs/developer/advanced/running-elasticsearch.asciidoc b/docs/developer/advanced/running-elasticsearch.asciidoc new file mode 100644 index 0000000000000..b03c231678eee --- /dev/null +++ b/docs/developer/advanced/running-elasticsearch.asciidoc @@ -0,0 +1,118 @@ +[[running-elasticsearch]] +=== Running elasticsearch during development + +There are many ways to run Elasticsearch while you are developing. + +[float] + +==== By snapshot + +This will run a snapshot of elasticsearch that is usually built nightly. Read more about <>. + +[source,bash] +---- +yarn es snapshot +---- + +See all available options, like how to specify a specific license, with the `--help` flag. + +[source,bash] +---- +yarn es snapshot --help +---- + +`trial` will give you access to all capabilities. + +**Keeping data between snapshots** + +If you want to keep the data inside your Elasticsearch between usages of this command, you should use the following command, to keep your data folder outside the downloaded snapshot folder: + +[source,bash] +---- +yarn es snapshot -E path.data=../data +---- + +==== By source + +If you have the Elasticsearch repo checked out locally and wish to run against that, use `source`. By default, it will reference an elasticsearch checkout which is a sibling to the {kib} directory named elasticsearch. If you wish to use a checkout in another location you can provide that by supplying --source-path + +[source,bash] +---- +yarn es source +---- + +==== From an archive + +Use this if you already have a distributable. For released versions, one can be obtained on the Elasticsearch downloads page. + +[source,bash] +---- +yarn es archive +---- + +Each of these will run Elasticsearch with a basic license. Additional options are available, pass --help for more information. + +==== From a remote host + +You can save some system resources, and the effort of generating sample data, if you have a remote Elasticsearch cluster to connect to. (Elasticians: you do! Check with your team about where to find credentials) + +You'll need to create a kibana.dev.yml (<>) and add the following to it: + +[source,bash] +---- +elasticsearch.hosts: + - {{ url }} +elasticsearch.username: {{ username }} +elasticsearch.password: {{ password }} +elasticsearch.ssl.verificationMode: none +---- + +If many other users will be interacting with your remote cluster, you'll want to add the following to avoid causing conflicts: + +[source,bash] +---- +kibana.index: '.{YourGitHubHandle}-kibana' +xpack.task_manager.index: '.{YourGitHubHandle}-task-manager-kibana' +---- + +===== Running remote clusters + +Setup remote clusters for cross cluster search (CCS) and cross cluster replication (CCR). + +Start your primary cluster by running: + +[source,bash] +---- +yarn es snapshot -E path.data=../data_prod1 +---- + +Start your remote cluster by running: + +[source,bash] +---- +yarn es snapshot -E transport.port=9500 -E http.port=9201 -E path.data=../data_prod2 +---- + +Once both clusters are running, start {kib}. {kib} will connect to the primary cluster. + +Setup the remote cluster in {kib} from either Management -> Elasticsearch -> Remote Clusters UI or by running the following script in Console. + +[source,bash] +---- +PUT _cluster/settings +{ + "persistent": { + "cluster": { + "remote": { + "cluster_one": { + "seeds": [ + "localhost:9500" + ] + } + } + } + } +} +---- + +Follow the cross-cluster search instructions for setting up index patterns to search across clusters (<>). \ No newline at end of file diff --git a/docs/developer/architecture/add-data-tutorials.asciidoc b/docs/developer/architecture/add-data-tutorials.asciidoc new file mode 100644 index 0000000000000..e16b1bc039a10 --- /dev/null +++ b/docs/developer/architecture/add-data-tutorials.asciidoc @@ -0,0 +1,38 @@ +[[add-data-tutorials]] +=== Add data tutorials + +`Add Data` in the {kib} Home application contains tutorials for setting up data flows in the Elastic stack. + +Each tutorial contains three sets of instructions: + +* `On Premise.` Set up a data flow when both {kib} and Elasticsearch are running on premise. +* `On Premise Elastic Cloud.` Set up a data flow when {kib} is running on premise and Elasticsearch is running on Elastic Cloud. +* `Elastic Cloud.` Set up a data flow when both {kib} and Elasticsearch are running on Elastic Cloud. + +[float] +==== Creating a new tutorial +1. Create a new directory in the link:https://github.com/elastic/kibana/tree/master/src/plugins/home/server/tutorials[tutorials directory]. +2. In the new directory, create a file called `index.ts` that exports a function. +The function must return a function object that conforms to the `TutorialSchema` interface link:{kib-repo}tree/{branch}/src/plugins/home/server/services/tutorials/lib/tutorial_schema.ts[tutorial schema]. +3. Register the tutorial in link:{kib-repo}tree/{branch}/src/plugins/home/server/tutorials/register.ts[register.ts] by adding it to the `builtInTutorials`. +// TODO update path once assets are migrated +4. Add image assets to the link:{kib-repo}tree/{branch}/src/legacy/core_plugins/kibana/public/home/tutorial_resources[tutorial_resources directory]. +5. Run {kib} locally to preview the tutorial. +6. Create a PR and go through the review process to get the changes approved. + +If you are creating a new plugin and the tutorial is only related to that plugin, you can also place the `TutorialSchema` object into your plugin folder. Add `home` to the `requiredPlugins` list in your `kibana.json` file. +Then register the tutorial object by calling `home.tutorials.registerTutorial(tutorialObject)` in the `setup` lifecycle of your server plugin. + +[float] +===== Variables +String values can contain variables that are substituted when rendered. Variables are specified by `{}`. +For example: `{config.docs.version}` is rendered as `6.2` when running the tutorial in {kib} 6.2. + +link:{kib-repo}tree/{branch}/src/legacy/core_plugins/kibana/public/home/np_ready/components/tutorial/replace_template_strings.js#L23[Provided variables] + +[float] +===== Markdown +String values can contain limited Markdown syntax. + +link:{kib-repo}tree/{branch}/src/legacy/core_plugins/kibana/public/home/components/tutorial/content.js#L8[Enabled Markdown grammars] + diff --git a/docs/developer/visualize/development-visualize-index.asciidoc b/docs/developer/architecture/development-visualize-index.asciidoc similarity index 85% rename from docs/developer/visualize/development-visualize-index.asciidoc rename to docs/developer/architecture/development-visualize-index.asciidoc index ac824b4702a3c..551c41833fb72 100644 --- a/docs/developer/visualize/development-visualize-index.asciidoc +++ b/docs/developer/architecture/development-visualize-index.asciidoc @@ -1,13 +1,13 @@ [[development-visualize-index]] -== Developing Visualizations +=== Developing Visualizations [IMPORTANT] ============================================== -These pages document internal APIs and are not guaranteed to be supported across future versions of Kibana. +These pages document internal APIs and are not guaranteed to be supported across future versions of {kib}. ============================================== The internal APIs for creating custom visualizations are in a state of heavy churn as -they are being migrated to the new Kibana platform, and large refactorings have been +they are being migrated to the new {kib} platform, and large refactorings have been happening across minor releases in the `7.x` series. In particular, in `7.5` and later we have made significant changes to the legacy APIs as we work to gradually replace them. @@ -20,7 +20,7 @@ If you would like to keep up with progress on the visualizations plugin in the m here are a few resources: * The <> documentation, where we try to capture any changes to the APIs as they occur across minors. -* link:https://github.com/elastic/kibana/issues/44121[Meta issue] which is tracking the move of the plugin to the new Kibana platform +* link:https://github.com/elastic/kibana/issues/44121[Meta issue] which is tracking the move of the plugin to the new {kib} platform * Our link:https://www.elastic.co/blog/join-our-elastic-stack-workspace-on-slack[Elastic Stack workspace on Slack]. * The {kib-repo}blob/{branch}/src/plugins/visualizations[source code], which will continue to be the most accurate source of information. diff --git a/docs/developer/architecture/index.asciidoc b/docs/developer/architecture/index.asciidoc new file mode 100644 index 0000000000000..d726a8bd3642d --- /dev/null +++ b/docs/developer/architecture/index.asciidoc @@ -0,0 +1,25 @@ +[[kibana-architecture]] +== Architecture + +[IMPORTANT] +============================================== +{kib} developer services and apis are in a state of constant development. We cannot provide backwards compatibility at this time due to the high rate of change. +============================================== + +Our developer services are changing all the time. One of the best ways to discover and learn about them is to read the available +READMEs from all the plugins inside our {kib-repo}tree/{branch}/src/plugins[open source plugins folder] and our +{kib-repo}/tree/{branch}/x-pack/plugins[commercial plugins folder]. + +A few services also automatically generate api documentation which can be browsed inside the {kib-repo}tree/{branch}/docs/development[docs/development section of our repo] + +A few notable services are called out below. + +* <> +* <> +* <> + +include::add-data-tutorials.asciidoc[] + +include::development-visualize-index.asciidoc[] + +include::security/index.asciidoc[] diff --git a/docs/developer/plugin/development-plugin-feature-registration.asciidoc b/docs/developer/architecture/security/feature-registration.asciidoc similarity index 96% rename from docs/developer/plugin/development-plugin-feature-registration.asciidoc rename to docs/developer/architecture/security/feature-registration.asciidoc index 203cc201ee626..164f6d1cf9c74 100644 --- a/docs/developer/plugin/development-plugin-feature-registration.asciidoc +++ b/docs/developer/architecture/security/feature-registration.asciidoc @@ -1,13 +1,13 @@ [[development-plugin-feature-registration]] -=== Plugin feature registration +==== Plugin feature registration If your plugin will be used with {kib}'s default distribution, then you have the ability to register the features that your plugin provides. Features are typically apps in {kib}; once registered, you can toggle them via Spaces, and secure them via Roles when security is enabled. -==== UI Capabilities +===== UI Capabilities Registering features also gives your plugin access to “UI Capabilities”. These capabilities are boolean flags that you can use to conditionally render your interface, based on the current user's permissions. For example, you can hide or disable a Save button if the current user is not authorized. -==== Registering a feature +===== Registering a feature Feature registration is controlled via the built-in `xpack_main` plugin. To register a feature, call `xpack_main`'s `registerFeature` function from your plugin's `init` function, and provide the appropriate details: @@ -65,12 +65,12 @@ Registering a feature consists of the following fields. For more information, co |The ID of the navigation link associated with your feature. |=== -===== Privilege definition +====== Privilege definition The `privileges` section of feature registration allows plugins to implement read/write and read-only modes for their applications. For a full explanation of fields and options, consult the {kib-repo}blob/{branch}/x-pack/plugins/features/server/feature_registry.ts[feature registry interface]. -==== Using UI Capabilities +===== Using UI Capabilities UI Capabilities are available to your public (client) plugin code. These capabilities are read-only, and are used to inform the UI. This object is namespaced by feature id. For example, if your feature id is “foo”, then your UI Capabilities are stored at `uiCapabilities.foo`. To access capabilities, import them from `ui/capabilities`: @@ -86,7 +86,7 @@ if (canUserSave) { ----------- [[example-1-canvas]] -==== Example 1: Canvas Application +===== Example 1: Canvas Application ["source","javascript"] ----------- init(server) { @@ -118,13 +118,13 @@ init(server) { } ----------- -This shows how the Canvas application might register itself as a Kibana feature. +This shows how the Canvas application might register itself as a {kib} feature. Note that it specifies different `savedObject` access levels for each privilege: - Users with read/write access (`all` privilege) need to be able to read/write `canvas-workpad` saved objects, and they need read-only access to `index-pattern` saved objects. - Users with read-only access (`read` privilege) do not need to have read/write access to any saved objects, but instead get read-only access to `index-pattern` and `canvas-workpad` saved objects. -Additionally, Canvas registers the `canvas` UI app and `canvas` catalogue entry. This tells Kibana that these entities are available for users with either the `read` or `all` privilege. +Additionally, Canvas registers the `canvas` UI app and `canvas` catalogue entry. This tells {kib} that these entities are available for users with either the `read` or `all` privilege. The `all` privilege defines a single “save” UI Capability. To access this in the UI, Canvas could: @@ -141,7 +141,7 @@ if (canUserSave) { Because the `read` privilege does not define the `save` capability, users with read-only access will have their `uiCapabilities.canvas.save` flag set to `false`. [[example-2-dev-tools]] -==== Example 2: Dev Tools +===== Example 2: Dev Tools ["source","javascript"] ----------- @@ -199,7 +199,7 @@ server.route({ ----------- [[example-3-discover]] -==== Example 3: Discover +===== Example 3: Discover Discover takes advantage of subfeature privileges to allow fine-grained access control. In this example, a single "Create Short URLs" subfeature privilege is defined, which allows users to grant access to this feature without having to grant the `all` privilege to Discover. In other words, you can grant `read` access to Discover, and also grant the ability to create short URLs. diff --git a/docs/developer/architecture/security/index.asciidoc b/docs/developer/architecture/security/index.asciidoc new file mode 100644 index 0000000000000..55b2450caf7a7 --- /dev/null +++ b/docs/developer/architecture/security/index.asciidoc @@ -0,0 +1,12 @@ +[[development-security]] +=== Security + +{kib} has generally been able to implement security transparently to core and plugin developers, and this largely remains the case. {kib} on two methods that the elasticsearch `Cluster` provides: `callWithRequest` and `callWithInternalUser`. + +`callWithRequest` executes requests against Elasticsearch using the authentication credentials of the {kib} end-user. So, if you log into {kib} with the user of `foo` when `callWithRequest` is used, {kib} execute the request against Elasticsearch as the user `foo`. Historically, `callWithRequest` has been used extensively to perform actions that are initiated at the request of {kib} end-users. + +`callWithInternalUser` executes requests against Elasticsearch using the internal {kib} server user, and has historically been used for performing actions that aren't initiated by {kib} end users; for example, creating the initial `.kibana` index or performing health checks against Elasticsearch. + +However, with the changes that role-based access control (RBAC) introduces, this is no longer cut and dry. {kib} now requires all access to the `.kibana` index goes through the `SavedObjectsClient`. This used to be a best practice, as the `SavedObjectsClient` was responsible for translating the documents stored in Elasticsearch to and from Saved Objects, but RBAC is now taking advantage of this abstraction to implement access control and determine when to use `callWithRequest` versus `callWithInternalUser`. + +include::rbac.asciidoc[] diff --git a/docs/developer/security/rbac.asciidoc b/docs/developer/architecture/security/rbac.asciidoc similarity index 96% rename from docs/developer/security/rbac.asciidoc rename to docs/developer/architecture/security/rbac.asciidoc index 02b8233a9a3df..ae1979e856e23 100644 --- a/docs/developer/security/rbac.asciidoc +++ b/docs/developer/architecture/security/rbac.asciidoc @@ -1,5 +1,5 @@ [[development-security-rbac]] -=== Role-based access control +==== Role-based access control Role-based access control (RBAC) in {kib} relies upon the {ref}/security-privileges.html#application-privileges[application privileges] @@ -11,7 +11,7 @@ consumers when using `request.getSavedObjectsClient()` or `savedObjects.getScopedSavedObjectsClient()`. [[development-rbac-privileges]] -==== {kib} Privileges +===== {kib} Privileges When {kib} first starts up, it executes the following `POST` request against {es}. This synchronizes the definition of the privileges with various `actions` which are later used to authorize a user: @@ -19,7 +19,7 @@ When {kib} first starts up, it executes the following `POST` request against {es ---------------------------------- POST /_security/privilege Content-Type: application/json -Authorization: Basic kibana changeme +Authorization: Basic {kib} changeme { "kibana-.kibana":{ @@ -56,7 +56,7 @@ The application is created by concatenating the prefix of `kibana-` with the val ============================================== [[development-rbac-assigning-privileges]] -==== Assigning {kib} Privileges +===== Assigning {kib} Privileges {kib} privileges are assigned to specific roles using the `applications` element. For example, the following role assigns the <> privilege at `*` `resources` (which will in the future be used to secure spaces) to the default {kib} `application`: @@ -81,7 +81,7 @@ Roles that grant <> should be managed using the <> +* <> +* <> + +include::stability.asciidoc[] + +include::security.asciidoc[] diff --git a/docs/developer/best-practices/security.asciidoc b/docs/developer/best-practices/security.asciidoc new file mode 100644 index 0000000000000..26fcc73ce2b90 --- /dev/null +++ b/docs/developer/best-practices/security.asciidoc @@ -0,0 +1,55 @@ +[[security-best-practices]] +=== Security best practices + +* XSS +** Check for usages of `dangerouslySetInnerHtml`, `Element.innerHTML`, +`Element.outerHTML` +** Ensure all user input is properly escaped. +** Ensure any input in `$.html`, `$.append`, `$.appendTo`, +latexmath:[$.prepend`, `$].prependTo`is escaped. Instead use`$.text`, or +don’t use jQuery at all. +* CSRF +** Ensure all APIs are running inside the {kib} HTTP service. +* RCE +** Ensure no usages of `eval` +** Ensure no usages of dynamic requires +** Check for template injection +** Check for usages of templating libraries, including `_.template`, and +ensure that user provided input isn’t influencing the template and is +only used as data for rendering the template. +** Check for possible prototype pollution. +* Prototype Pollution +** Check for instances of `anObject[a][b] = c` where a, b, and c are +user defined. This includes code paths where the following logical code +steps could be performed in separate files by completely different +operations, or recursively using dynamic operations. +** Validate any user input, including API +url-parameters/query-parameters/payloads, preferable against a schema +which only allows specific keys/values. At a very minimum, black-list +`__proto__` and `prototype.constructor` for use within keys +** When calling APIs which spawn new processes or potentially perform +code generation from strings, defensively protect against Prototype +Pollution by checking `Object.hasOwnProperty` if the arguments to the +APIs originate from an Object. An example is the Code app’s +https://github.com/elastic/kibana/blob/b49192626a8528af5d888545fb14cd1ce66a72e7/x-pack/legacy/plugins/code/server/lsp/workspace_command.ts#L40-L44[spawnProcess]. +*** Common Node.js offenders: `child_process.spawn`, +`child_process.exec`, `eval`, `Function('some string')`, +`vm.runIn*Context(x)` +*** Common Client-side offenders: `eval`, `Function('some string')`, +`setTimeout('some string', num)`, `setInterval('some string', num)` +* Check for accidental reveal of sensitive information +** The biggest culprit is errors which contain stack traces or other +sensitive information which end up in the HTTP Response +* Checked for Mishandled API requests +** Ensure no sensitive cookies are forwarded to external resources. +** Ensure that all user controllable variables that are used in +constructing a URL are escaped properly. This is relevant when using +`transport.request` with the Elasticsearch client as no automatic +escaping is performed. +* Reverse tabnabbing - +https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/HTML5_Security_Cheat_Sheet.md#tabnabbing +** When there are user controllable links or hard-coded links to +third-party domains that specify target="_blank" or target="_window", the a tag should have the rel="noreferrer noopener" attribute specified. +Allowing users to input markdown is a common culprit, a custom link renderer should be used +* SSRF - https://www.owasp.org/index.php/Server_Side_Request_Forgery +All network requests made from the {kib} server should use an explicit configuration or white-list specified in the kibana.yml \ No newline at end of file diff --git a/docs/developer/best-practices/stability.asciidoc b/docs/developer/best-practices/stability.asciidoc new file mode 100644 index 0000000000000..68237a034be52 --- /dev/null +++ b/docs/developer/best-practices/stability.asciidoc @@ -0,0 +1,66 @@ +[[stability]] +=== Stability + +Ensure your feature will work under all possible {kib} scenarios. + +[float] +==== Environmental configuration scenarios + +* Cloud +** Does the feature work on *cloud environment*? +** Does it create a setting that needs to be exposed, or configured +differently than the default, on Cloud? (whitelisting of certain +settings/users? Ref: +https://www.elastic.co/guide/en/cloud/current/ec-add-user-settings.html +, +https://www.elastic.co/guide/en/cloud/current/ec-manage-kibana-settings.html) +** Is there a significant performance impact that may affect Cloud +{kib} instances? +** Does it need to be aware of running in a container? (for example +monitoring) +* Multiple {kib} instances +** Pointing to the same index +** Pointing to different indexes +*** Should make sure that the {kib} index is not hardcoded anywhere. +*** Should not be storing a bunch of stuff in {kib} memory. +*** Should emulate a high availability deployment. +*** Anticipating different timing related issues due to shared resource +access. +*** We need to make sure security is set up in a specific way for +non-standard {kib} indices. (create their own custom roles) +* {kib} running behind a reverse proxy or load balancer, without sticky +sessions. (we have had many discuss/SDH tickets around this) +* If a proxy/loadbalancer is running between ES and {kib} + +[float] +==== Kibana.yml settings + +* Using a custom {kib} index alias +* When optional dependencies are disabled +** Ensure all your required dependencies are listed in kibana.json +dependency list! + +[float] +==== Test coverage + +* Does the feature have sufficient unit test coverage? (does it handle +storeinSessions?) +* Does the feature have sufficient Functional UI test coverage? +* Does the feature have sufficient Rest API coverage test coverage? +* Does the feature have sufficient Integration test coverage? + +[float] +==== Browser coverage + +Refer to the list of browsers and OS {kib} supports +https://www.elastic.co/support/matrix + +Does the feature work efficiently on the list of supported browsers? + +[float] +==== Upgrade Scenarios - Migration scenarios- + +Does the feature affect old +indices, saved objects ? - Has the feature been tested with {kib} +aliases - Read/Write privileges of the indices before and after the +upgrade? diff --git a/docs/developer/contributing/development-accessibility-tests.asciidoc b/docs/developer/contributing/development-accessibility-tests.asciidoc new file mode 100644 index 0000000000000..a3ffefb94cd2a --- /dev/null +++ b/docs/developer/contributing/development-accessibility-tests.asciidoc @@ -0,0 +1,23 @@ +[[development-accessibility-tests]] +==== Automated Accessibility Testing + +To run the tests locally: + +[arabic] +. In one terminal window run +`node scripts/functional_tests_server --config test/accessibility/config.ts` +. In another terminal window run +`node scripts/functional_test_runner.js --config test/accessibility/config.ts` + +To run the x-pack tests, swap the config file out for +`x-pack/test/accessibility/config.ts`. + +After the server is up, you can go to this instance of {kib} at +`localhost:5620`. + +The testing is done using https://github.com/dequelabs/axe-core[axe]. +The same thing that runs in CI, can be run locally using their browser +plugins: + +* https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US[Chrome] +* https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/[Firefox] \ No newline at end of file diff --git a/docs/developer/contributing/development-documentation.asciidoc b/docs/developer/contributing/development-documentation.asciidoc new file mode 100644 index 0000000000000..d9fae42eef87e --- /dev/null +++ b/docs/developer/contributing/development-documentation.asciidoc @@ -0,0 +1,34 @@ +[[development-documentation]] +=== Documentation during development + +Docs should be written during development and accompany PRs when relevant. There are multiple types of documentation, and different places to add each. + +[float] +==== Developer services documentation + +Documentation about specific services a plugin offers should be encapsulated in: + +* README.asciidoc at the base of the plugin folder. +* Typescript comments for all public services. + +[float] +==== End user documentation + +Documentation about user facing features should be written in http://asciidoc.org/[asciidoc] at +{kib-repo}/tree/master/docs[https://github.com/elastic/kibana/tree/master/docs] + +To build the docs, you must clone the https://github.com/elastic/docs[elastic/docs] +repo as a sibling of your {kib} repo. Follow the instructions in that project's +README for getting the docs tooling set up. + +**To build the docs:** + +```bash +node scripts/docs.js --open +``` + +[float] +==== General developer documentation and guidelines + +General developer guildlines and documentation, like this right here, should be written in http://asciidoc.org/[asciidoc] +at {kib-repo}/tree/master/docs/developer[https://github.com/elastic/kibana/tree/master/docs/developer] diff --git a/docs/developer/core/development-functional-tests.asciidoc b/docs/developer/contributing/development-functional-tests.asciidoc similarity index 90% rename from docs/developer/core/development-functional-tests.asciidoc rename to docs/developer/contributing/development-functional-tests.asciidoc index 2b091d9abb9fc..442fc1ac755d3 100644 --- a/docs/developer/core/development-functional-tests.asciidoc +++ b/docs/developer/contributing/development-functional-tests.asciidoc @@ -1,38 +1,39 @@ [[development-functional-tests]] === Functional Testing -We use functional tests to make sure the Kibana UI works as expected. It replaces hours of manual testing by automating user interaction. To have better control over our functional test environment, and to make it more accessible to plugin authors, Kibana uses a tool called the `FunctionalTestRunner`. +We use functional tests to make sure the {kib} UI works as expected. It replaces hours of manual testing by automating user interaction. To have better control over our functional test environment, and to make it more accessible to plugin authors, {kib} uses a tool called the `FunctionalTestRunner`. [float] ==== Running functional tests -The `FunctionalTestRunner` is very bare bones and gets most of its functionality from its config file, located at {blob}test/functional/config.js[test/functional/config.js]. If you’re writing a plugin you will have your own config file. See <> for more info. +The `FunctionalTestRunner` is very bare bones and gets most of its functionality from its config file, located at {blob}test/functional/config.js[test/functional/config.js]. If you’re writing a plugin outside the {kib} repo, you will have your own config file. + See <> for more info. There are three ways to run the tests depending on your goals: 1. Easiest option: -** Description: Starts up Kibana & Elasticsearch servers, followed by running tests. This is much slower when running the tests multiple times because slow startup time for the servers. Recommended for single-runs. +** Description: Starts up {kib} & Elasticsearch servers, followed by running tests. This is much slower when running the tests multiple times because slow startup time for the servers. Recommended for single-runs. ** `node scripts/functional_tests` -*** does everything in a single command, including running Elasticsearch and Kibana locally +*** does everything in a single command, including running Elasticsearch and {kib} locally *** tears down everything after the tests run *** exit code reports success/failure of the tests 2. Best for development: -** Description: Two commands, run in separate terminals, separate the components that are long-running and slow from those that are ephemeral and fast. Tests can be re-run much faster, and this still runs Elasticsearch & Kibana locally. +** Description: Two commands, run in separate terminals, separate the components that are long-running and slow from those that are ephemeral and fast. Tests can be re-run much faster, and this still runs Elasticsearch & {kib} locally. ** `node scripts/functional_tests_server` -*** starts Elasticsearch and Kibana servers +*** starts Elasticsearch and {kib} servers *** slow to start *** can be reused for multiple executions of the tests, thereby saving some time when re-running tests -*** automatically restarts the Kibana server when relevant changes are detected +*** automatically restarts the {kib} server when relevant changes are detected ** `node scripts/functional_test_runner` -*** runs the tests against Kibana & Elasticsearch servers that were started by `node scripts/functional_tests_server` +*** runs the tests against {kib} & Elasticsearch servers that were started by `node scripts/functional_tests_server` *** exit code reports success or failure of the tests 3. Custom option: -** Description: Runs tests against instances of Elasticsearch & Kibana started some other way (like Elastic Cloud, or an instance you are managing in some other way). +** Description: Runs tests against instances of Elasticsearch & {kib} started some other way (like Elastic Cloud, or an instance you are managing in some other way). ** just executes the functional tests -** url, credentials, etc. for Elasticsearch and Kibana are specified via environment variables -** Here's an example that runs against an Elastic Cloud instance. Note that you must run the same branch of tests as the version of Kibana you're testing. +** url, credentials, etc. for Elasticsearch and {kib} are specified via environment variables +** Here's an example that runs against an Elastic Cloud instance. Note that you must run the same branch of tests as the version of {kib} you're testing. + ["source","shell"] ---------- @@ -95,10 +96,10 @@ node scripts/functional_test_runner --exclude-tag skipCloud When run without any arguments the `FunctionalTestRunner` automatically loads the configuration in the standard location, but you can override that behavior with the `--config` flag. List configs with multiple --config arguments. -* `--config test/functional/config.js` starts Elasticsearch and Kibana servers with the WebDriver tests configured to run in Chrome. -* `--config test/functional/config.firefox.js` starts Elasticsearch and Kibana servers with the WebDriver tests configured to run in Firefox. -* `--config test/api_integration/config.js` starts Elasticsearch and Kibana servers with the api integration tests configuration. -* `--config test/accessibility/config.ts` starts Elasticsearch and Kibana servers with the WebDriver tests configured to run an accessibility audit using https://www.deque.com/axe/[axe]. +* `--config test/functional/config.js` starts Elasticsearch and {kib} servers with the WebDriver tests configured to run in Chrome. +* `--config test/functional/config.firefox.js` starts Elasticsearch and {kib} servers with the WebDriver tests configured to run in Firefox. +* `--config test/api_integration/config.js` starts Elasticsearch and {kib} servers with the api integration tests configuration. +* `--config test/accessibility/config.ts` starts Elasticsearch and {kib} servers with the WebDriver tests configured to run an accessibility audit using https://www.deque.com/axe/[axe]. There are also command line flags for `--bail` and `--grep`, which behave just like their mocha counterparts. For instance, use `--grep=foo` to run only tests that match a regular expression. @@ -117,7 +118,7 @@ The tests are written in https://mochajs.org[mocha] using https://github.com/ela We use https://www.w3.org/TR/webdriver1/[WebDriver Protocol] to run tests in both Chrome and Firefox with the help of https://sites.google.com/a/chromium.org/chromedriver/[chromedriver] and https://firefox-source-docs.mozilla.org/testing/geckodriver/[geckodriver]. When the `FunctionalTestRunner` launches, remote service creates a new webdriver session, which starts the driver and a stripped-down browser instance. We use `browser` service and `webElementWrapper` class to wrap up https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/[Webdriver API]. -The `FunctionalTestRunner` automatically transpiles functional tests using babel, so that tests can use the same ECMAScript features that Kibana source code uses. See {blob}style_guides/js_style_guide.md[style_guides/js_style_guide.md]. +The `FunctionalTestRunner` automatically transpiles functional tests using babel, so that tests can use the same ECMAScript features that {kib} source code uses. See {blob}style_guides/js_style_guide.md[style_guides/js_style_guide.md]. [float] ===== Definitions @@ -304,9 +305,9 @@ The `FunctionalTestRunner` comes with three built-in services: * Phases include: `beforeLoadTests`, `beforeTests`, `beforeEachTest`, `cleanup` [float] -===== Kibana Services +===== {kib} Services -The Kibana functional tests define the vast majority of the actual functionality used by tests. +The {kib} functional tests define the vast majority of the actual functionality used by tests. **browser**::: * Source: {blob}test/functional/services/browser.ts[test/functional/services/browser.ts] @@ -356,7 +357,7 @@ await testSubjects.click(‘containerButton’); **kibanaServer:**::: * Source: {blob}test/common/services/kibana_server/kibana_server.js[test/common/services/kibana_server/kibana_server.js] -* Helpers for interacting with Kibana's server +* Helpers for interacting with {kib}'s server * Commonly used methods: ** `kibanaServer.uiSettings.update()` ** `kibanaServer.version.get()` @@ -501,3 +502,13 @@ const log = getService(‘log’); // log.debug only writes when using the `--debug` or `--verbose` flag. log.debug(‘done clicking menu’); ----------- + +[float] +==== MacOS testing performance tip + +macOS users on a machine with a discrete graphics card may see significant speedups (up to 2x) when running tests by changing your terminal emulator's GPU settings. In iTerm2: +* Open Preferences (Command + ,) +* In the General tab, under the "Magic" section, ensure "GPU rendering" is checked +* Open "Advanced GPU Settings..." +* Uncheck the "Prefer integrated to discrete GPU" option +* Restart iTerm \ No newline at end of file diff --git a/docs/developer/contributing/development-github.asciidoc b/docs/developer/contributing/development-github.asciidoc new file mode 100644 index 0000000000000..027b4e73aa9de --- /dev/null +++ b/docs/developer/contributing/development-github.asciidoc @@ -0,0 +1,112 @@ +[[development-github]] +=== How we use git and github + +[float] +==== Forking + +We follow the https://help.github.com/articles/fork-a-repo/[GitHub +forking model] for collaborating on {kib} code. This model assumes that +you have a remote called `upstream` which points to the official {kib} +repo, which we'll refer to in later code snippets. + +[float] +==== Branching + +* All work on the next major release goes into master. +* Past major release branches are named `{majorVersion}.x`. They contain +work that will go into the next minor release. For example, if the next +minor release is `5.2.0`, work for it should go into the `5.x` branch. +* Past minor release branches are named `{majorVersion}.{minorVersion}`. +They contain work that will go into the next patch release. For example, +if the next patch release is `5.3.1`, work for it should go into the +`5.3` branch. +* All work is done on feature branches and merged into one of these +branches. +* Where appropriate, we'll backport changes into older release branches. + +[float] +==== Commits and Merging + +* Feel free to make as many commits as you want, while working on a +branch. +* When submitting a PR for review, please perform an interactive rebase +to present a logical history that's easy for the reviewers to follow. +* Please use your commit messages to include helpful information on your +changes, e.g. changes to APIs, UX changes, bugs fixed, and an +explanation of _why_ you made the changes that you did. +* Resolve merge conflicts by rebasing the target branch over your +feature branch, and force-pushing (see below for instructions). +* When merging, we'll squash your commits into a single commit. + +[float] +===== Rebasing and fixing merge conflicts + +Rebasing can be tricky, and fixing merge conflicts can be even trickier +because it involves force pushing. This is all compounded by the fact +that attempting to push a rebased branch remotely will be rejected by +git, and you'll be prompted to do a `pull`, which is not at all what you +should do (this will really mess up your branch's history). + +Here's how you should rebase master onto your branch, and how to fix +merge conflicts when they arise. + +First, make sure master is up-to-date. + +["source","shell"] +----------- +git checkout master +git fetch upstream +git rebase upstream/master +----------- + +Then, check out your branch and rebase master on top of it, which will +apply all of the new commits on master to your branch, and then apply +all of your branch's new commits after that. + +["source","shell"] +----------- +git checkout name-of-your-branch +git rebase master +----------- + +You want to make sure there are no merge conflicts. If there are merge +conflicts, git will pause the rebase and allow you to fix the conflicts +before continuing. + +You can use `git status` to see which files contain conflicts. They'll +be the ones that aren't staged for commit. Open those files, and look +for where git has marked the conflicts. Resolve the conflicts so that +the changes you want to make to the code have been incorporated in a way +that doesn't destroy work that's been done in master. Refer to master's +commit history on GitHub if you need to gain a better understanding of how code is conflicting and how best to resolve it. + +Once you've resolved all of the merge conflicts, use `git add -A` to stage them to be committed, and then use + `git rebase --continue` to tell git to continue the rebase. + +When the rebase has completed, you will need to force push your branch because the history is now completely different than what's on the remote. This is potentially dangerous because it will completely overwrite what you have on the remote, so you need to be sure that you haven't lost any work when resolving merge conflicts. (If there weren't any merge conflicts, then you can force push without having to worry about this.) + +["source","shell"] +----------- +git push origin name-of-your-branch --force +----------- + +This will overwrite the remote branch with what you have locally. You're done! + +**Note that you should not run git pull**, for example in response to a push rejection like this: + +["source","shell"] +----------- +! [rejected] name-of-your-branch -> name-of-your-branch (non-fast-forward) +error: failed to push some refs to 'https://github.com/YourGitHubHandle/kibana.git' +hint: Updates were rejected because the tip of your current branch is behind +hint: its remote counterpart. Integrate the remote changes (e.g. +hint: 'git pull ...') before pushing again. +hint: See the 'Note about fast-forwards' in 'git push --help' for details. +----------- + +Assuming you've successfully rebased and you're happy with the code, you should force push instead. + +[float] +==== Creating a pull request + +See <> for the next steps on getting your code changes merged into {kib}. \ No newline at end of file diff --git a/docs/developer/contributing/development-pull-request.asciidoc b/docs/developer/contributing/development-pull-request.asciidoc new file mode 100644 index 0000000000000..5d3c30fec7383 --- /dev/null +++ b/docs/developer/contributing/development-pull-request.asciidoc @@ -0,0 +1,32 @@ +[[development-pull-request]] +=== Submitting a pull request + +[float] +==== What Goes Into a Pull Request + +* Please include an explanation of your changes in your PR description. +* Links to relevant issues, external resources, or related PRs are very important and useful. +* Please update any tests that pertain to your code, and add new tests where appropriate. +* Update or add docs when appropriate. Read more about <>. + +[float] +==== Submitting a Pull Request + + 1. Push your local changes to your forked copy of the repository and submit a pull request. + 2. Describe what your changes do and mention the number of the issue where discussion has taken place, e.g., “Closes #123″. + 3. Assign the `review` and `💝community` label (assuming you are not a member of the Elastic organization). This signals to the team that someone needs to give this attention. + 4. Do *not* assign a version label. Someone from Elastic staff will assign a version label, if necessary, when your Pull Request is ready to be merged. + 5. If you would like someone specific to review your pull request, assign them. Otherwise an Elastic staff member will assign the appropriate person. + +Always submit your pull against master unless the bug is only present in an older version. If the bug affects both master and another branch say so in your pull. + +Then sit back and wait. There will probably be discussion about the Pull Request and, if any changes are needed, we'll work with you to get your Pull Request merged into {kib}. + +[float] +==== What to expect during the pull request review process + +Most PRs go through several iterations of feedback and updates. Depending on the scope and complexity of the PR, the process can take weeks. Please +be patient and understand we hold our code base to a high standard. + +Check out our <> for our general philosophy for pull request reviews. + diff --git a/docs/developer/contributing/development-tests.asciidoc b/docs/developer/contributing/development-tests.asciidoc new file mode 100644 index 0000000000000..b470ea61669b2 --- /dev/null +++ b/docs/developer/contributing/development-tests.asciidoc @@ -0,0 +1,96 @@ +[[development-tests]] +=== Testing + +To ensure that your changes will not break other functionality, please run the test suite and build (<>) before submitting your Pull Request. + +[float] +==== Running specific {kib} tests + +The following table outlines possible test file locations and how to +invoke them: + +[width="100%",cols="7%,59%,34%",options="header",] +|=== +|Test runner |Test location |Runner command (working directory is {kib} +root) +|Jest |`src/**/*.test.js` `src/**/*.test.ts` +|`yarn test:jest -t regexp [test path]` + +|Jest (integration) |`**/integration_tests/**/*.test.js` +|`yarn test:jest_integration -t regexp [test path]` + +|Mocha +|`src/**/__tests__/**/*.js` `!src/**/public/__tests__/*.js``packages/kbn-datemath/test/**/*.js` `packages/kbn-dev-utils/src/**/__tests__/**/*.js` `tasks/**/__tests__/**/*.js` +|`node scripts/mocha --grep=regexp [test path]` + +|Functional +|`test/*integration/**/config.js` `test/*functional/**/config.js` `test/accessibility/config.js` +|`yarn test:ftr:server --config test/[directory]/config.js``yarn test:ftr:runner --config test/[directory]/config.js --grep=regexp` + +|Karma |`src/**/public/__tests__/*.js` |`yarn test:karma:debug` +|=== + +For X-Pack tests located in `x-pack/` see +link:{kib-repo}tree/{branch}/x-pack/README.md#testing[X-Pack Testing] + +Test runner arguments: - Where applicable, the optional arguments +`-t=regexp` or `--grep=regexp` will only run tests or test suites +whose descriptions matches the regular expression. - `[test path]` is +the relative path to the test file. + +Examples: - Run the entire elasticsearch_service test suite: +`yarn test:jest src/core/server/elasticsearch/elasticsearch_service.test.ts` +- Run the jest test case whose description matches +`stops both admin and data clients`: +`yarn test:jest -t 'stops both admin and data clients' src/core/server/elasticsearch/elasticsearch_service.test.ts` +- Run the api integration test case whose description matches the given +string: ``` yarn test:ftr:server –config test/api_integration/config.js +yarn test:ftr:runner –config test/api_integration/config + +[float] +==== Cross-browser compatibility + +**Testing IE on OS X** + +* http://www.vmware.com/products/fusion/fusion-evaluation.html[Download +VMWare Fusion]. +* https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/#downloads[Download +IE virtual machines] for VMWare. +* Open VMWare and go to Window > Virtual Machine Library. Unzip the +virtual machine and drag the .vmx file into your Virtual Machine +Library. +* Right-click on the virtual machine you just added to your library and +select "`Snapshots…`", and then click the "`Take`" button in the modal +that opens. You can roll back to this snapshot when the VM expires in 90 +days. +* In System Preferences > Sharing, change your computer name to be +something simple, e.g. "`computer`". +* Run {kib} with `yarn start --host=computer.local` (substituting +your computer name). +* Now you can run your VM, open the browser, and navigate to +`http://computer.local:5601` to test {kib}. +* Alternatively you can use browserstack + +[float] +==== Running browser automation tests + +Check out <> to learn more about how you can run +and develop functional tests for {kib} core and plugins. + +You can also look into the {kib-repo}tree/{branch}/scripts/README.md[Scripts README.md] +to learn more about using the node scripts we provide for building +{kib}, running integration tests, and starting up {kib} and +Elasticsearch while you develop. + +[float] +==== More testing information: + +* <> +* <> +* <> + +include::development-functional-tests.asciidoc[] + +include::development-unit-tests.asciidoc[] + +include::development-accessibility-tests.asciidoc[] \ No newline at end of file diff --git a/docs/developer/core/development-unit-tests.asciidoc b/docs/developer/contributing/development-unit-tests.asciidoc similarity index 52% rename from docs/developer/core/development-unit-tests.asciidoc rename to docs/developer/contributing/development-unit-tests.asciidoc index 04cce0dfec901..0009533c9a7c4 100644 --- a/docs/developer/core/development-unit-tests.asciidoc +++ b/docs/developer/contributing/development-unit-tests.asciidoc @@ -1,15 +1,11 @@ [[development-unit-tests]] -=== Unit Testing +==== Unit testing frameworks -We use unit tests to make sure that individual software units of {kib} perform as they were designed to. +{kib} is migrating unit testing from `Mocha` to `Jest`. Legacy unit tests +still exist in Mocha but all new unit tests should be written in Jest. [float] -=== Current Frameworks - -{kib} is migrating unit testing from `Mocha` to `Jest`. Legacy unit tests still exist in `Mocha` but all new unit tests should be written in `Jest`. - -[float] -==== Mocha (legacy) +===== Mocha (legacy) Mocha tests are contained in `__tests__` directories. @@ -32,7 +28,7 @@ yarn test:jest ----------- [float] -===== Writing Jest Unit Tests +====== Writing Jest Unit Tests In order to write those tests there are two main things you need to be aware of. The first one is the different between `jest.mock` and `jest.doMock` @@ -42,7 +38,7 @@ specially for the tests implemented on Typescript in order to benefit from the auto-inference types feature. [float] -===== Jest.mock vs Jest.doMock +====== Jest.mock vs Jest.doMock Both methods are essentially the same on their roots however the `jest.mock` calls will get hoisted to the top of the file and can only reference variables @@ -52,7 +48,7 @@ variables are instantiated at the time we need them which lead us to the next section where we'll talk about our jest mock files pattern. [float] -===== Jest Mock Files Pattern +====== Jest Mock Files Pattern Specially on typescript it is pretty common to have in unit tests `jest.doMock` calls which reference for example imported types. Any error @@ -79,5 +75,71 @@ like: `import * as Mocks from './mymodule.test.mocks'`, `import { mockX } from './mymodule.test.mocks'` or just `import './mymodule.test.mocks'` if there isn't anything exported to be used. - +[float] +[[debugging-unit-tests]] +===== Debugging Unit Tests + +The standard `yarn test` task runs several sub tasks and can take +several minutes to complete, making debugging failures pretty painful. +In order to ease the pain specialized tasks provide alternate methods +for running the tests. + +You could also add the `--debug` option so that `node` is run using +the `--debug-brk` flag. You’ll need to connect a remote debugger such +as https://github.com/node-inspector/node-inspector[`node-inspector`] +to proceed in this mode. + +[source,bash] +---- +node scripts/mocha --debug +---- + +With `yarn test:karma`, you can run only the browser tests. Coverage +reports are available for browser tests by running +`yarn test:coverage`. You can find the results under the `coverage/` +directory that will be created upon completion. + +[source,bash] +---- +yarn test:karma +---- + +Using `yarn test:karma:debug` initializes an environment for debugging +the browser tests. Includes an dedicated instance of the {kib} server +for building the test bundle, and a karma server. When running this task +the build is optimized for the first time and then a karma-owned +instance of the browser is opened. Click the "`debug`" button to open a +new tab that executes the unit tests. + +[source,bash] +---- +yarn test:karma:debug +---- + +In the screenshot below, you’ll notice the URL is +`localhost:9876/debug.html`. You can append a `grep` query parameter +to this URL and set it to a string value which will be used to exclude +tests which don’t match. For example, if you changed the URL to +`localhost:9876/debug.html?query=my test` and then refreshed the +browser, you’d only see tests run which contain "`my test`" in the test +description. + +image:http://i.imgur.com/DwHxgfq.png[Browser test debugging] + +[float] +===== Unit Testing Plugins + +This should work super if you’re using the +https://github.com/elastic/kibana/tree/master/packages/kbn-plugin-generator[Kibana +plugin generator]. If you’re not using the generator, well, you’re on +your own. We suggest you look at how the generator works. + +To run the tests for just your particular plugin run the following +command from your plugin: + +[source,bash] +---- +yarn test:mocha +yarn test:karma:debug # remove the debug flag to run them once and close +---- \ No newline at end of file diff --git a/docs/developer/contributing/index.asciidoc b/docs/developer/contributing/index.asciidoc new file mode 100644 index 0000000000000..4f987f31cf1f6 --- /dev/null +++ b/docs/developer/contributing/index.asciidoc @@ -0,0 +1,89 @@ +[[contributing]] +== Contributing + +Whether you want to fix a bug, implement a feature, or add some other improvements or apis, the following sections will +guide you on the process. + +Read <> to get your environment up and running, then read <>. + +* <> +* <> +* <> +* <> +* <> +* <> +* <> +* <> +* <> +* <> + +[discrete] +[[signing-contributor-agreement]] +=== Signing the contributor license agreement + +Please make sure you have signed the [Contributor License Agreement](http://www.elastic.co/contributor-agreement/). We are not asking you to assign copyright to us, but to give us the right to distribute your code without restriction. We ask this of all contributors in order to assure our users of the origin and continuing existence of the code. You only need to sign the CLA once. + +[float] +[[kibana-localization]] +=== Localization + +Read <> for details on our localization practices. + +Note that we cannot support accepting contributions to the translations from any source other than the translators we have engaged to do the work. +We are still to develop a proper process to accept any contributed translations. We certainly appreciate that people care enough about the localization effort to want to help improve the quality. We aim to build out a more comprehensive localization process for the future and will notify you once contributions can be supported, but for the time being, we are not able to incorporate suggestions. + +[float] +[[kibana-release-notes-process]] +=== Release Notes Process + +Part of this process only applies to maintainers, since it requires +access to GitHub labels. + +{kib} publishes https://www.elastic.co/guide/en/kibana/current/release-notes.html[Release Notes] for major and minor releases. +The Release Notes summarize what the PRs accomplish in language that is meaningful to users. + To generate the Release Notes, the team runs a script against this repo to collect the merged PRs against the release. + +[float] +==== Create the Release Notes text + +The text that appears in the Release Notes is pulled directly from your PR title, or a single paragraph of text that you specify in the PR description. + +To use a single paragraph of text, enter `Release note:` or a `## Release note` header in the PR description, followed by your text. For example, refer to this https://github.com/elastic/kibana/pull/65796[PR] that uses the `## Release note` header. + +When you create the Release Notes text, use the following best practices: + +* Use present tense. +* Use sentence case. +* When you create a feature PR, start with `Adds`. +* When you create an enhancement PR, start with `Improves`. +* When you create a bug fix PR, start with `Fixes`. +* When you create a deprecation PR, start with `Deprecates`. + +[float] +==== Add your labels + +[arabic] +. Label the PR with the targeted version (ex: `v7.3.0`). +. Label the PR with the appropriate GitHub labels: + * For a new feature or functionality, use `release_note:enhancement`. + * For an external-facing fix, use `release_note:fix`. We do not include docs, build, and test fixes in the Release Notes, or unreleased issues that are only on `master`. + * For a deprecated feature, use `release_note:deprecation`. + * For a breaking change, use `release_note:breaking`. + * To **NOT** include your changes in the Release Notes, use `release_note:skip`. + + +include::development-github.asciidoc[] + +include::development-tests.asciidoc[] + +include::interpreting-ci-failures.asciidoc[] + +include::development-documentation.asciidoc[] + +include::development-pull-request.asciidoc[] + +include::kibana-issue-reporting.asciidoc[] + +include::pr-review.asciidoc[] + +include::linting.asciidoc[] diff --git a/docs/developer/testing/interpreting-ci-failures.asciidoc b/docs/developer/contributing/interpreting-ci-failures.asciidoc similarity index 87% rename from docs/developer/testing/interpreting-ci-failures.asciidoc rename to docs/developer/contributing/interpreting-ci-failures.asciidoc index c47a59217d89b..ba3999a310198 100644 --- a/docs/developer/testing/interpreting-ci-failures.asciidoc +++ b/docs/developer/contributing/interpreting-ci-failures.asciidoc @@ -1,19 +1,19 @@ [[interpreting-ci-failures]] -== Interpreting CI Failures +=== Interpreting CI Failures -Kibana CI uses a Jenkins feature called "Pipelines" to automate testing of the code in pull requests and on tracked branches. Pipelines are defined within the repository via the `Jenkinsfile` at the root of the project. +{kib} CI uses a Jenkins feature called "Pipelines" to automate testing of the code in pull requests and on tracked branches. Pipelines are defined within the repository via the `Jenkinsfile` at the root of the project. More information about Jenkins Pipelines can be found link:https://jenkins.io/doc/book/pipeline/[in the Jenkins book]. [float] -=== Github Checks +==== Github Checks When a test fails it will be reported to Github via Github Checks. We currently bucket tests into several categories which run in parallel to make CI faster. Groups like `ciGroup{X}` get a single check in Github, and other tests like linting, or type checks, get their own checks. Clicking the link next to the check in the conversation tab of a pull request will take you to the log output from that section of the tests. If that log output is truncated, or doesn't clearly identify what happened, you can usually get more complete information by visiting Jenkins directly. [float] -=== Viewing Job Executions in Jenkins +==== Viewing Job Executions in Jenkins To view the results of a job execution in Jenkins, either click the link in the comment left by `@elasticmachine` or search for the `kibana-ci` check in the list at the bottom of the PR. This link will take you to the top-level page for the specific job execution that failed. @@ -25,7 +25,7 @@ image::images/job_view.png[] 4. *Pipeline Steps:*: A breakdown of the pipline that was executed, along with individual log output for each step in the pipeline. [float] -=== Viewing ciGroup/test Logs +==== Viewing ciGroup/test Logs To view the logs for a failed specific ciGroup, jest, mocha, type checkers, linters, etc., click on the *Pipeline Steps* link in from the Job page. diff --git a/docs/developer/contributing/kibana-issue-reporting.asciidoc b/docs/developer/contributing/kibana-issue-reporting.asciidoc new file mode 100644 index 0000000000000..36c50b612d675 --- /dev/null +++ b/docs/developer/contributing/kibana-issue-reporting.asciidoc @@ -0,0 +1,46 @@ +[[kibana-issue-reporting]] +=== Effective issue reporting in {kib} + +[float] +==== Voicing the importance of an issue + +We seriously appreciate thoughtful comments. If an issue is important to +you, add a comment with a solid write up of your use case and explain +why it’s so important. Please avoid posting comments comprised solely of +a thumbs up emoji 👍. + +Granted that you share your thoughts, we might even be able to come up +with creative solutions to your specific problem. If everything you’d +like to say has already been brought up but you’d still like to add a +token of support, feel free to add a +https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments[👍 +thumbs up reaction] on the issue itself and on the comment which best +summarizes your thoughts. + +[float] +==== "`My issue isn’t getting enough attention`" + +First of all, *sorry about that!* We want you to have a great time with +{kib}. + +There’s hundreds of open issues and prioritizing what to work on is an +important aspect of our daily jobs. We prioritize issues according to +impact and difficulty, so some issues can be neglected while we work on +more pressing issues. + +Feel free to bump your issues if you think they’ve been neglected for a +prolonged period. + +[float] +==== "`I want to help!`" + +*Now we’re talking*. If you have a bug fix or new feature that you would +like to contribute to {kib}, please *find or open an issue about it +before you start working on it.* Talk about what you would like to do. +It may be that somebody is already working on it, or that there are +particular issues that you should know about before implementing the +change. + +We enjoy working with contributors to get their code accepted. There are +many approaches to fixing a problem and it is important to find the best +approach before writing too much code. \ No newline at end of file diff --git a/docs/developer/contributing/linting.asciidoc b/docs/developer/contributing/linting.asciidoc new file mode 100644 index 0000000000000..234bd90478907 --- /dev/null +++ b/docs/developer/contributing/linting.asciidoc @@ -0,0 +1,70 @@ +[[kibana-linting]] +=== Linting + +A note about linting: We use http://eslint.org[eslint] to check that the +link:STYLEGUIDE.md[styleguide] is being followed. It runs in a +pre-commit hook and as a part of the tests, but most contributors +integrate it with their code editors for real-time feedback. + +Here are some hints for getting eslint setup in your favorite editor: + +[width="100%",cols="13%,87%",options="header",] +|=== +|Editor |Plugin +|Sublime +|https://github.com/roadhump/SublimeLinter-eslint#installation[SublimeLinter-eslint] + +|Atom +|https://github.com/AtomLinter/linter-eslint#installation[linter-eslint] + +|VSCode +|https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint[ESLint] + +|IntelliJ |Settings » Languages & Frameworks » JavaScript » Code Quality +Tools » ESLint + +|`vi` |https://github.com/scrooloose/syntastic[scrooloose/syntastic] +|=== + +Another tool we use for enforcing consistent coding style is +EditorConfig, which can be set up by installing a plugin in your editor +that dynamically updates its configuration. Take a look at the +http://editorconfig.org/#download[EditorConfig] site to find a plugin +for your editor, and browse our +https://github.com/elastic/kibana/blob/master/.editorconfig[`.editorconfig`] +file to see what config rules we set up. + +[float] +==== Setup Guide for VS Code Users + +Note that for VSCode, to enable "`live`" linting of TypeScript (and +other) file types, you will need to modify your local settings, as shown +below. The default for the ESLint extension is to only lint JavaScript +file types. + +[source,json] +---- +"eslint.validate": [ + "javascript", + "javascriptreact", + { "language": "typescript", "autoFix": true }, + { "language": "typescriptreact", "autoFix": true } +] +---- + +`eslint` can automatically fix trivial lint errors when you save a +file by adding this line in your setting. + +[source,json] +---- + "eslint.autoFixOnSave": true, +---- + +:warning: It is *not* recommended to use the +https://prettier.io/[`Prettier` extension/IDE plugin] while +maintaining the {kib} project. Formatting and styling roles are set in +the multiple `.eslintrc.js` files across the project and some of them +use the https://www.npmjs.com/package/prettier[NPM version of Prettier]. +Using the IDE extension might cause conflicts, applying the formatting +to too many files that shouldn’t be prettier-ized and/or highlighting +errors that are actually OK. \ No newline at end of file diff --git a/docs/developer/pr-review.asciidoc b/docs/developer/contributing/pr-review.asciidoc similarity index 90% rename from docs/developer/pr-review.asciidoc rename to docs/developer/contributing/pr-review.asciidoc index 304718e437dc5..ebab3b24aaaee 100644 --- a/docs/developer/pr-review.asciidoc +++ b/docs/developer/contributing/pr-review.asciidoc @@ -1,7 +1,7 @@ [[pr-review]] -== Pull request review guidelines +=== Pull request review guidelines -Every change made to Kibana must be held to a high standard, and while the responsibility for quality in a pull request ultimately lies with the author, Kibana team members have the responsibility as reviewers to verify during their review process. +Every change made to {kib} must be held to a high standard, and while the responsibility for quality in a pull request ultimately lies with the author, {kib} team members have the responsibility as reviewers to verify during their review process. Frankly, it's impossible to build a concrete list of requirements that encompass all of the possible situations we'll encounter when reviewing pull requests, so instead this document tries to lay out a common set of the few obvious requirements while also outlining a general philosophy that we should have when approaching any PR review. @@ -11,15 +11,15 @@ While the review process is always done by Elastic staff members, these guidelin [float] -=== Target audience +==== Target audience -The target audience for this document are pull request reviewers. For Kibana maintainers, the PR review is the only part of the contributing process in which we have complete control. The author of any given pull request may not be up to speed on the latest expectations we have for pull requests, and they may have never read our guidelines at all. It's our responsibility as reviewers to guide folks through this process, but it's hard to do that consistently without a common set of documented principles. +The target audience for this document are pull request reviewers. For {kib} maintainers, the PR review is the only part of the contributing process in which we have complete control. The author of any given pull request may not be up to speed on the latest expectations we have for pull requests, and they may have never read our guidelines at all. It's our responsibility as reviewers to guide folks through this process, but it's hard to do that consistently without a common set of documented principles. Pull request authors can benefit from reading this document as well because it'll help establish a common set of expectations between authors and reviewers early. [float] -=== Reject fast +==== Reject fast Every pull request is different, and before reviewing any given PR, reviewers should consider the optimal way to approach the PR review so that if the change is ultimately rejected, it is done so as early in the process as possible. @@ -27,7 +27,7 @@ For example, a reviewer may want to do a product level review as early as possib [float] -=== The big three +==== The big three There are a lot of discrete requirements and guidelines we want to follow in all of our pull requests, but three things in particular stand out as important above all the rest. @@ -58,24 +58,24 @@ This isn't simply a question of enough test files. The code in the tests themsel All of our code should have unit tests that verify its behaviors, including not only the "happy path", but also edge cases, error handling, etc. When you change an existing API of a module, then there should always be at least one failing unit test, which in turn means we need to verify that all code consuming that API properly handles the change if necessary. For modules at a high enough level, this will mean we have breaking change in the product, which we'll need to handle accordingly. -In addition to extensive unit test coverage, PRs should include relevant functional and integration tests. In some cases, we may simply be testing a programmatic interface (e.g. a service) that is integrating with the file system, the network, Elasticsearch, etc. In other cases, we'll be testing REST APIs over HTTP or comparing screenshots/snapshots with prior known acceptable state. In the worst case, we are doing browser-based functional testing on a running instance of Kibana using selenium. +In addition to extensive unit test coverage, PRs should include relevant functional and integration tests. In some cases, we may simply be testing a programmatic interface (e.g. a service) that is integrating with the file system, the network, Elasticsearch, etc. In other cases, we'll be testing REST APIs over HTTP or comparing screenshots/snapshots with prior known acceptable state. In the worst case, we are doing browser-based functional testing on a running instance of {kib} using selenium. Enhancements are pretty much always going to have extensive unit tests as a base as well as functional and integration testing. Bug fixes should always include regression tests to ensure that same bug does not manifest again in the future. -- [float] -=== Product level review +==== Product level review Reviewers are not simply evaluating the code itself, they are also evaluating the quality of the user-facing change in the product. This generally means they need to check out the branch locally and "play around" with it. In addition to the "do we want this change in the product" details, the reviewer should be looking for bugs and evaluating how approachable and useful the feature is as implemented. Special attention should be given to error scenarios and edge cases to ensure they are all handled well within the product. [float] -=== Consistency, style, readability +==== Consistency, style, readability Having a relatively consistent codebase is an important part of us building a sustainable project. With dozens of active contributors at any given time, we rely on automation to help ensure consistency - we enforce a comprehensive set of linting rules through CI. We're also rolling out prettier to make this even more automatic. -For things that can't be easily automated, we maintain a link:https://github.com/elastic/kibana/blob/master/STYLEGUIDE.md[style guide] that authors should adhere to and reviewers should keep in mind when they review a pull request. +For things that can't be easily automated, we maintain a link:{kib-repo}tree/{branch}/STYLEGUIDE.md[style guide] that authors should adhere to and reviewers should keep in mind when they review a pull request. Beyond that, we're into subjective territory. Statements like "this isn't very readable" are hardly helpful since they can't be qualified, but that doesn't mean a reviewer should outright ignore code that is hard to understand due to how it is written. There isn't one definitively "best" way to write any particular code, so pursuing such shouldn't be our goal. Instead, reviewers and authors alike must accept that there are likely many different appropriate ways to accomplish the same thing with code, and so long as the contribution is utilizing one of those ways, then we're in good shape. @@ -87,7 +87,7 @@ There may also be times when a person is inspired by a particular contribution t [float] -=== Nitpicking +==== Nitpicking Nitpicking is when a reviewer identifies trivial and unimportant details in a pull request and asks the author to change them. This is a completely subjective category that is impossible to define universally, and it's equally impractical to define a blanket policy on nitpicking that everyone will be happy with. @@ -97,13 +97,13 @@ Often, reviewers have an opinion about whether the feedback they are about to gi [float] -=== Handling disagreements +==== Handling disagreements Conflicting opinions between reviewers and authors happen, and sometimes it is hard to reconcile those opinions. Ideally folks can work together in the spirit of these guidelines toward a consensus, but if that doesn't work out it may be best to bring a third person into the discussion. Our pull requests generally have two reviewers, so an appropriate third person may already be obvious. Otherwise, reach out to the functional area that is most appropriate or to technical leadership if an area isn't obvious. [float] -=== Inappropriate review feedback +==== Inappropriate review feedback Whether or not a bit of feedback is appropriate for a pull request is often dependent on the motivation for giving the feedback in the first place. @@ -113,7 +113,7 @@ Inflammatory feedback such as "this is crap" isn't feedback at all. It's both me [float] -=== A checklist +==== A checklist Establishing a comprehensive checklist for all of the things that should happen in all possible pull requests is impractical, but that doesn't mean we lack a concrete set of minimum requirements that we can enumerate. The following items should be double checked for any pull request: diff --git a/docs/developer/core-development.asciidoc b/docs/developer/core-development.asciidoc deleted file mode 100644 index 8f356abd095f2..0000000000000 --- a/docs/developer/core-development.asciidoc +++ /dev/null @@ -1,24 +0,0 @@ -[[core-development]] -== Core Development - -* <> -* <> -* <> -* <> -* <> -* <> -* <> - -include::core/development-basepath.asciidoc[] - -include::core/development-dependencies.asciidoc[] - -include::core/development-modules.asciidoc[] - -include::core/development-elasticsearch.asciidoc[] - -include::core/development-unit-tests.asciidoc[] - -include::core/development-functional-tests.asciidoc[] - -include::core/development-es-snapshots.asciidoc[] diff --git a/docs/developer/core/development-basepath.asciidoc b/docs/developer/core/development-basepath.asciidoc deleted file mode 100644 index d49dfe2938fad..0000000000000 --- a/docs/developer/core/development-basepath.asciidoc +++ /dev/null @@ -1,85 +0,0 @@ -[[development-basepath]] -=== Considerations for basePath - -All communication from the Kibana UI to the server needs to respect the -`server.basePath`. Here are the "blessed" strategies for dealing with this -based on the context: - -[float] -==== Getting a static asset url - -Use webpack to import the asset into the build. This will give you a URL in -JavaScript and gives webpack a chance to perform optimizations and -cache-busting. - -["source","shell"] ------------ -// in plugin/public/main.js -import uiChrome from 'ui/chrome'; -import logoUrl from 'plugins/facechimp/assets/banner.png'; - -uiChrome.setBrand({ - logo: `url(${logoUrl}) center no-repeat` -}); ------------ - -[float] -==== API requests from the front-end - -Use `chrome.addBasePath()` to append the basePath to the front of the url. - -["source","shell"] ------------ -import chrome from 'ui/chrome'; -$http.get(chrome.addBasePath('/api/plugin/things')); ------------ - -[float] -==== Server side - -Append `request.getBasePath()` to any absolute URL path. - -["source","shell"] ------------ -const basePath = server.config().get('server.basePath'); -server.route({ - path: '/redirect', - handler(request, h) { - return h.redirect(`${request.getBasePath()}/otherLocation`); - } -}); ------------ - -[float] -==== BasePathProxy in dev mode - -The Kibana dev server automatically runs behind a proxy with a random -`server.basePath`. This way developers will be constantly verifying that their -code works with basePath, while they write it. - -To accomplish this the `serve` task does a few things: - -1. change the port for the server to the `dev.basePathProxyTarget` setting (default `5603`) -2. start a `BasePathProxy` at `server.port` - - picks a random 3-letter value for `randomBasePath` - - redirects from `/` to `/{randomBasePath}` - - redirects from `/{any}/app/{appName}` to `/{randomBasePath}/app/{appName}` so that refreshes should work - - proxies all requests starting with `/{randomBasePath}/` to the Kibana server - -If you're writing scripts that interact with the Kibana API, the base path proxy will likely -make this difficult. To bypass the base path proxy for a single request, prefix urls with -`__UNSAFE_bypassBasePath` and the request will be routed to the development Kibana server. - -["source","shell"] ------------ -curl "http://elastic:changeme@localhost:5601/__UNSAFE_bypassBasePath/api/status" ------------ - -This proxy can sometimes have unintended side effects in development, so when -needed you can opt out by passing the `--no-base-path` flag to the `serve` task -or `yarn start`. - -["source","shell"] ------------ -yarn start --no-base-path ------------ diff --git a/docs/developer/core/development-dependencies.asciidoc b/docs/developer/core/development-dependencies.asciidoc deleted file mode 100644 index 285d338a23a0d..0000000000000 --- a/docs/developer/core/development-dependencies.asciidoc +++ /dev/null @@ -1,103 +0,0 @@ -[[development-dependencies]] -=== Managing Dependencies - -While developing plugins for use in the Kibana front-end environment you will -probably want to include a library or two (at least). While that should be -simple to do 90% of the time, there are always outliers, and some of those -outliers are very popular projects. - -Before you can use an external library with Kibana you have to install it. You -do that using... - -[float] -==== yarn (preferred method) - -Once you've http://npmsearch.com[found] a dependency you want to add, you can -install it like so: - -["source","shell"] ------------ -yarn add some-neat-library ------------ - -At the top of a javascript file, just import the library using it's name: - -["source","shell"] ------------ -import someNeatLibrary from 'some-neat-library'; ------------ - -Just like working in node.js, front-end code can require node modules installed -by yarn without any additional configuration. - -[float] -==== webpackShims - -When a library you want to use does use es6 or common.js modules but is not -available with yarn, you can copy the source of the library into a webpackShim. - -["source","shell"] ------------ -# create a directory for our new library to live -mkdir -p webpackShims/some-neat-library -# download the library you want to use into that directory -curl https://cdnjs.com/some-neat-library/library.js > webpackShims/some-neat-library/index.js ------------ - -Then include the library in your JavaScript code as you normally would: - -["source","shell"] ------------ -import someNeatLibrary from 'some-neat-library'; ------------ - -[float] -==== Shimming third party code - -Some JavaScript libraries do not declare their dependencies in a way that tools -like webpack can understand. It is also often the case that libraries do not -`export` their provided values, but simply write them to a global variable name -(or something to that effect). - -When pulling code like this into Kibana we need to write "shims" that will -adapt the third party code to work with our application, other libraries, and -module system. To do this we can utilize the `webpackShims` directory. - -The easiest way to explain how to write a shim is to show you some. Here is our -webpack shim for jQuery: - -["source","shell"] ------------ -// webpackShims/jquery.js - -module.exports = window.jQuery = window.$ = require('../node_modules/jquery/dist/jquery'); -require('ui/jquery/findTestSubject')(window.$); ------------ - -This shim is loaded up anytime an `import 'jquery';` statement is found by -webpack, because of the way that `webpackShims` behaves like `node_modules`. -When that happens, the shim does two things: - -. Assign the exported value of the actual jQuery module to the window at `$` and `jQuery`, allowing libraries like angular to detect that jQuery is available, and use it as the module's export value. -. Finally, a jQuery plugin that we wrote is included so that every time a file imports jQuery it will get both jQuery and the `$.findTestSubject` helper function. - -Here is what our webpack shim for angular looks like: - -["source","shell"] ------------ -// webpackShims/angular.js - -require('jquery'); -require('../node_modules/angular/angular'); -require('../node_modules/angular-elastic/elastic'); -require('ui/modules').get('kibana', ['monospaced.elastic']); -module.exports = window.angular; ------------ - -What this shim does is fairly simple if you go line by line: - -. makes sure that jQuery is loaded before angular (which actually runs the shim) -. load the angular.js file from the node_modules directory -. load the angular-elastic plugin, a plugin we want to always be included whenever we import angular -. use the `ui/modules` module to add the module exported by angular-elastic as a dependency to the `kibana` angular module -. finally, export the window.angular variable. This means that writing `import angular from 'angular';` will properly set the angular variable to the angular library, rather than undefined which is the default behavior. diff --git a/docs/developer/core/development-elasticsearch.asciidoc b/docs/developer/core/development-elasticsearch.asciidoc deleted file mode 100644 index 89f85cfc19fbf..0000000000000 --- a/docs/developer/core/development-elasticsearch.asciidoc +++ /dev/null @@ -1,40 +0,0 @@ -[[development-elasticsearch]] -=== Communicating with Elasticsearch - -Kibana exposes two clients on the server and browser for communicating with elasticsearch. -There is an 'admin' client which is used for managing Kibana's state, and a 'data' client for all -other requests. The clients use the {jsclient-current}/index.html[elasticsearch.js library]. - -[float] -[[client-server]] -=== Server clients - -Server clients are exposed through the elasticsearch plugin. -[source,javascript] ----- - const adminCluster = server.plugins.elasticsearch.getCluster('admin'); - const dataCluster = server.plugins.elasticsearch.getCluster('data'); - - //ping as the configured elasticsearch.user in kibana.yml - adminCluster.callWithInternalUser('ping'); - - //ping as the user specified in the current requests header - adminCluster.callWithRequest(req, 'ping'); ----- - -[float] -[[client-browser]] -=== Browser clients - -Browser clients are exposed through AngularJS services. - -[source,javascript] ----- -uiModules.get('kibana') -.run(function (es) { - es.ping() - .catch(err => { - console.log('error pinging servers'); - }); -}); ----- diff --git a/docs/developer/core/development-modules.asciidoc b/docs/developer/core/development-modules.asciidoc deleted file mode 100644 index cc5cd69ed8cb9..0000000000000 --- a/docs/developer/core/development-modules.asciidoc +++ /dev/null @@ -1,63 +0,0 @@ -[[development-modules]] -=== Modules and Autoloading - -[float] -==== Autoloading - -Because of the disconnect between JS modules and angular directives, filters, -and services it is difficult to know what you need to import. It is even more -difficult to know if you broke something by removing an import that looked -unused. - -To prevent this from being an issue the ui module provides "autoloading" -modules. The sole purpose of these modules is to extend the environment with -certain components. Here is a breakdown of those modules: - -- *`import 'ui/autoload/modules'`* - Imports angular and several ui services and "components" which Kibana - depends on without importing. The full list of imports is hard coded in the - module. Hopefully this list will shrink over time as we properly map out - the required modules and import them were they are actually necessary. - -- *`import 'ui/autoload/all'`* - Imports all of the modules - -[float] -==== Resolving Require Paths - -Kibana uses Webpack to bundle Kibana's dependencies. - -Here is how import/require statements are resolved to a file: - -. Check the beginning of the module path - * if the path starts with a '.' - ** append it the directory of the current file - ** proceed to *3* - * if the path starts with a '/' - ** search for this exact path - ** proceed to *3* - * proceed to *2* -. Search for a named module - * `moduleName` = dirname(require path)` - * match if `moduleName` is or starts with one of these aliases - ** replace the alias with the match and continue to ***3*** - * match when any of these conditions are met: - ** `./webpackShims/${moduleName}` is a directory - ** `./node_modules/${moduleName}` is a directory - * if no match was found - ** move to the parent directory - ** start again at *2.iii* until reaching the root directory or a match is found - * if a match was found - ** replace the `moduleName` prefix from the require statement with the full path of the match and proceed to *3* -. Search for a file - * the first of the following paths that resolves to a **file** is our match - ** path + '.js' - ** path + '.json' - ** path - ** path/${basename(path)} + '.js' - ** path/${basename(path)} + '.json' - ** path/${basename(path)} - ** path/index + '.js' - ** path/index + '.json' - ** path/index - * if none of the paths matches then an error is thrown diff --git a/docs/developer/getting-started/building-kibana.asciidoc b/docs/developer/getting-started/building-kibana.asciidoc new file mode 100644 index 0000000000000..e1f1ca336a5da --- /dev/null +++ b/docs/developer/getting-started/building-kibana.asciidoc @@ -0,0 +1,39 @@ +[[building-kibana]] +=== Building a {kib} distributable + +The following commands will build a {kib} production distributable. + +[source,bash] +---- +yarn build --skip-os-packages +---- + +You can get all build options using the following command: + +[source,bash] +---- +yarn build --help +---- + +[float] +==== Building OS packages + +Packages are built using fpm, dpkg, and rpm. Package building has only been tested on Linux and is not supported on any other platform. + + +[source,bash] +---- +apt-get install ruby-dev rpm +gem install fpm -v 1.5.0 +yarn build --skip-archives +---- + +To specify a package to build you can add `rpm` or `deb` as an argument. + + +[source,bash] +---- +yarn build --rpm +---- + +Distributable packages can be found in `target/` after the build completes. \ No newline at end of file diff --git a/docs/developer/getting-started/debugging.asciidoc b/docs/developer/getting-started/debugging.asciidoc new file mode 100644 index 0000000000000..b369dcda748af --- /dev/null +++ b/docs/developer/getting-started/debugging.asciidoc @@ -0,0 +1,59 @@ +[[kibana-debugging]] +=== Debugging {kib} + +For information about how to debug unit tests, refer to <>. + +[float] +==== Server Code + +`yarn debug` will start the server with Node's inspect flag. {kib}'s development mode will start three processes on ports `9229`, `9230`, and `9231`. Chrome's developer tools need to be configured to connect to all three connections. Add `localhost:` for each {kib} process in Chrome's developer tools connection tab. + +[float] +==== Instrumenting with Elastic APM + +{kib} ships with the +https://github.com/elastic/apm-agent-nodejs[Elastic APM Node.js Agent] +built-in for debugging purposes. + +Its default configuration is meant to be used by core {kib} developers +only, but it can easily be re-configured to your needs. In its default +configuration it’s disabled and will, once enabled, send APM data to a +centrally managed Elasticsearch cluster accessible only to Elastic +employees. + +To change the location where data is sent, use the +https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#server-url[`serverUrl`] +APM config option. To activate the APM agent, use the +https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#active[`active`] +APM config option. + +All config options can be set either via environment variables, or by +creating an appropriate config file under `config/apm.dev.js`. For +more information about configuring the APM agent, please refer to +https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuring-the-agent.html[the +documentation]. + +Example `config/apm.dev.js` file: + +[source,js] +---- +module.exports = { + active: true, +}; +---- + +APM +https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html[Real +User Monitoring agent] is not available in the {kib} distributables, +however the agent can be enabled by setting `ELASTIC_APM_ACTIVE` to +`true`. flags + +.... +ELASTIC_APM_ACTIVE=true yarn start +// activates both Node.js and RUM agent +.... + +Once the agent is active, it will trace all incoming HTTP requests to +{kib}, monitor for errors, and collect process-level metrics. The +collected data will be sent to the APM Server and is viewable in the APM +UI in {kib}. \ No newline at end of file diff --git a/docs/developer/plugin/development-plugin-resources.asciidoc b/docs/developer/getting-started/development-plugin-resources.asciidoc similarity index 51% rename from docs/developer/plugin/development-plugin-resources.asciidoc rename to docs/developer/getting-started/development-plugin-resources.asciidoc index 3a32c49e40e0f..dfe8efc4fef57 100644 --- a/docs/developer/plugin/development-plugin-resources.asciidoc +++ b/docs/developer/getting-started/development-plugin-resources.asciidoc @@ -5,54 +5,35 @@ Here are some resources that are helpful for getting started with plugin develop [float] ==== Some light reading -Our {kib-repo}blob/master/CONTRIBUTING.md[contributing guide] can help you get a development environment going. +If you haven't already, start with <>. If you are planning to add your plugin to the {kib} repo, read the <> guide, if you are building a plugin externally, read <>. In both cases, read up on our recommended <>. [float] -==== Plugin Generator +==== Creating an empty plugin -We recommend that you kick-start your plugin by generating it with the {kib-repo}tree/{branch}/packages/kbn-plugin-generator[Kibana Plugin Generator]. Run the following in the Kibana repo, and you will be asked a couple questions, see some progress bars, and have a freshly generated plugin ready for you to play with in Kibana's `plugins` folder. +You can use the <> to get a basic structure for a new plugin. Plugins that are not part of the +{kib} repo should be developed inside the `plugins` folder. If you are building a new plugin to check in to the {kib} repo, +you will choose between a few locations: -["source","shell"] ------------ -node scripts/generate_plugin my_plugin_name # replace "my_plugin_name" with your desired plugin name ------------ - - -[float] -==== Directory structure for plugins - -The Kibana directory must be named `kibana`, and your plugin directory should be located in the root of `kibana` in a `plugins` directory, for example: - -["source","shell"] ----- -. -└── kibana - └── plugins - ├── foo-plugin - └── bar-plugin ----- - -[float] -==== References in the code - - {kib-repo}blob/{branch}/src/legacy/server/plugins/lib/plugin.js[Plugin class]: What options does the `kibana.Plugin` class accept? - - <>: What type of exports are available? + - {kib-repo}tree/{branch}/x-pack/plugins[x-pack/plugins] for commercially licensed plugins + - {kib-repo}tree/{branch}/src/plugins[src/plugins] for open source licensed plugins + - {kib-repo}tree/{branch}/examples[examples] for developer example plugins (these will not be included in the distributables) [float] ==== Elastic UI Framework If you're developing a plugin that has a user interface, take a look at our https://elastic.github.io/eui[Elastic UI Framework]. -It documents the CSS and React components we use to build Kibana's user interface. +It documents the CSS and React components we use to build {kib}'s user interface. You're welcome to use these components, but be aware that they are rapidly evolving, and we might introduce breaking changes that will disrupt your plugin's UI. [float] ==== TypeScript Support -Plugin code can be written in http://www.typescriptlang.org/[TypeScript] if desired. +We recommend your plugin code is written in http://www.typescriptlang.org/[TypeScript]. To enable TypeScript support, create a `tsconfig.json` file at the root of your plugin that looks something like this: ["source","js"] ----------- { - // extend Kibana's tsconfig, or use your own settings + // extend {kib}'s tsconfig, or use your own settings "extends": "../../kibana/tsconfig.json", // tell the TypeScript compiler where to find your source files @@ -64,10 +45,17 @@ To enable TypeScript support, create a `tsconfig.json` file at the root of your ----------- TypeScript code is automatically converted into JavaScript during development, -but not in the distributable version of Kibana. If you use the -{kib-repo}blob/{branch}/packages/kbn-plugin-helpers[@kbn/plugin-helpers] to build your plugin, then your `.ts` and `.tsx` files will be permanently transpiled before your plugin is archived. If you have your own build process, make sure to run the TypeScript compiler on your source files and ship the compilation output so that your plugin will work with the distributable version of Kibana. +but not in the distributable version of {kib}. If you use the +{kib-repo}blob/{branch}/packages/kbn-plugin-helpers[@kbn/plugin-helpers] to build your plugin, then your `.ts` and `.tsx` files will be permanently transpiled before your plugin is archived. If you have your own build process, make sure to run the TypeScript compiler on your source files and ship the compilation output so that your plugin will work with the distributable version of {kib}. +[float] ==== {kib} platform migration guide {kib-repo}blob/{branch}/src/core/MIGRATION.md#migrating-legacy-plugins-to-the-new-platform[This guide] provides an action plan for moving a legacy plugin to the new platform. + +[float] +==== Externally developed plugins + +If you are building a plugin outside of the {kib} repo, read <>. + diff --git a/docs/developer/getting-started/index.asciidoc b/docs/developer/getting-started/index.asciidoc new file mode 100644 index 0000000000000..ff1623e22f1eb --- /dev/null +++ b/docs/developer/getting-started/index.asciidoc @@ -0,0 +1,144 @@ +[[development-getting-started]] +== Getting started + +Get started building your own plugins, or contributing directly to the {kib} repo. + +[float] +[[get-kibana-code]] +=== Get the code + +https://help.github.com/en/github/getting-started-with-github/fork-a-repo[Fork], then https://help.github.com/en/github/getting-started-with-github/fork-a-repo#step-2-create-a-local-clone-of-your-fork[clone] the {kib-repo}[{kib} repo] and change directory into it: + +[source,bash] +---- +git clone https://github.com/[YOUR_USERNAME]/kibana.git kibana +cd kibana +---- + +[float] +=== Install dependencies + +Install the version of Node.js listed in the `.node-version` file. This +can be automated with tools such as +https://github.com/creationix/nvm[nvm], +https://github.com/coreybutler/nvm-windows[nvm-windows] or +https://github.com/wbyoung/avn[avn]. As we also include a `.nvmrc` file +you can switch to the correct version when using nvm by running: + +[source,bash] +---- +nvm use +---- + +Install the latest version of https://yarnpkg.com[yarn]. + +Bootstrap {kib} and install all the dependencies: + +[source,bash] +---- +yarn kbn bootstrap +---- + +____ +Node.js native modules could be in use and node-gyp is the tool used to +build them. There are tools you need to install per platform and python +versions you need to be using. Please see +https://github.com/nodejs/node-gyp#installation[https://github.com/nodejs/node-gyp#installation] +and follow the guide according your platform. +____ + +(You can also run `yarn kbn` to see the other available commands. For +more info about this tool, see +{kib-repo}tree/{branch}/packages/kbn-pm[{kib-repo}tree/{branch}packages/kbn-pm].) + +When switching branches which use different versions of npm packages you +may need to run: + +[source,bash] +---- +yarn kbn clean +---- + +If you have failures during `yarn kbn bootstrap` you may have some +corrupted packages in your yarn cache which you can clean with: + +[source,bash] +---- +yarn cache clean +---- + +[float] +=== Configure environmental settings + +[[increase-nodejs-heap-size]] +[float] +==== Increase node.js heap size + +{kib} is a big project and for some commands it can happen that the +process hits the default heap limit and crashes with an out-of-memory +error. If you run into this problem, you can increase maximum heap size +by setting the `--max_old_space_size` option on the command line. To set +the limit for all commands, simply add the following line to your shell +config: `export NODE_OPTIONS="--max_old_space_size=2048"`. + +[float] +=== Run Elasticsearch + +Run the latest Elasticsearch snapshot. Specify an optional license with the `--license` flag. + +[source,bash] +---- +yarn es snapshot --license trial +---- + +`trial` will give you access to all capabilities. + +Read about more options for <>, like connecting to a remote host, running from source, +preserving data inbetween runs, running remote cluster, etc. + +[float] +=== Run {kib} + +In another terminal window, start up {kib}. Include developer examples by adding an optional `--run-examples` flag. + +[source,bash] +---- +yarn start --run-examples +---- + +View all available options by running `yarn start --help` + +Read about more advanced options for <>. + +[float] +=== Code away! + +You are now ready to start developing. Changes to your files should be picked up automatically. Server side changes will +cause the {kib} server to reboot. + +[float] +=== More information + +* <> + +* <> + +* <> + +* <> + +* <> + +* <> + +include::running-kibana-advanced.asciidoc[] + +include::sample-data.asciidoc[] + +include::debugging.asciidoc[] + +include::sass.asciidoc[] + +include::building-kibana.asciidoc[] + +include::development-plugin-resources.asciidoc[] \ No newline at end of file diff --git a/docs/developer/getting-started/running-kibana-advanced.asciidoc b/docs/developer/getting-started/running-kibana-advanced.asciidoc new file mode 100644 index 0000000000000..e36f38de1b366 --- /dev/null +++ b/docs/developer/getting-started/running-kibana-advanced.asciidoc @@ -0,0 +1,87 @@ +[[running-kibana-advanced]] +=== Running {kib} + +Change to your local {kib} directory. Start the development server. + +[source,bash] +---- +yarn start +---- + +____ +On Windows, you’ll need to use Git Bash, Cygwin, or a similar shell that +exposes the `sh` command. And to successfully build you’ll need Cygwin +optional packages zip, tar, and shasum. +____ + +Now you can point your web browser to http://localhost:5601 and start +using {kib}! When running `yarn start`, {kib} will also log that it +is listening on port 5603 due to the base path proxy, but you should +still access {kib} on port 5601. + +By default, you can log in with username `elastic` and password +`changeme`. See the `--help` options on `yarn es ` if +you’d like to configure a different password. + +[float] +==== Running {kib} in Open-Source mode + +If you’re looking to only work with the open-source software, supply the +license type to `yarn es`: + +[source,bash] +---- +yarn es snapshot --license oss +---- + +And start {kib} with only open-source code: + +[source,bash] +---- +yarn start --oss +---- + +[float] +==== Unsupported URL Type + +If you’re installing dependencies and seeing an error that looks +something like + +.... +Unsupported URL Type: link:packages/eslint-config-kibana +.... + +you’re likely running `npm`. To install dependencies in {kib} you +need to run `yarn kbn bootstrap`. For more info, see +link:#setting-up-your-development-environment[Setting Up Your +Development Environment] above. + +[float] +[[customize-kibana-yml]] +==== Customizing `config/kibana.dev.yml` + +The `config/kibana.yml` file stores user configuration directives. +Since this file is checked into source control, however, developer +preferences can’t be saved without the risk of accidentally committing +the modified version. To make customizing configuration easier during +development, the {kib} CLI will look for a `config/kibana.dev.yml` +file if run with the `--dev` flag. This file behaves just like the +non-dev version and accepts any of the +https://www.elastic.co/guide/en/kibana/current/settings.html[standard +settings]. + +[float] +==== Potential Optimization Pitfalls + +* Webpack is trying to include a file in the bundle that I deleted and +is now complaining about it is missing +* A module id that used to resolve to a single file now resolves to a +directory, but webpack isn’t adapting +* (if you discover other scenarios, please send a PR!) + +[float] +==== Setting Up SSL + +{kib} includes self-signed certificates that can be used for +development purposes in the browser and for communicating with +Elasticsearch: `yarn start --ssl` & `yarn es snapshot --ssl`. \ No newline at end of file diff --git a/docs/developer/getting-started/sample-data.asciidoc b/docs/developer/getting-started/sample-data.asciidoc new file mode 100644 index 0000000000000..376211ceb2634 --- /dev/null +++ b/docs/developer/getting-started/sample-data.asciidoc @@ -0,0 +1,31 @@ +[[sample-data]] +=== Installing sample data + +There are a couple ways to easily get data ingested into Elasticsearch. + +[float] +==== Sample data packages available for one click installation + +The easiest is to install one or more of our vailable sample data packages. If you have no data, you should be +prompted to install when running {kib} for the first time. You can also access and install the sample data packages +by going to the home page and clicking "add sample data". + +[float] +==== makelogs script + +The provided `makelogs` script will generate sample data. + +[source,bash] +---- +node scripts/makelogs --auth : +---- + +The default username and password combination are `elastic:changeme` + +Make sure to execute `node scripts/makelogs` *after* elasticsearch is up and running! + +[float] +==== CSV upload + +If running with a platinum or trial license, you can also use the CSV uploader provided inside the Machine learning app. +Navigate to the Data visualizer to upload your data from a file. \ No newline at end of file diff --git a/docs/developer/getting-started/sass.asciidoc b/docs/developer/getting-started/sass.asciidoc new file mode 100644 index 0000000000000..194e001f642e1 --- /dev/null +++ b/docs/developer/getting-started/sass.asciidoc @@ -0,0 +1,36 @@ +[[kibana-sass]] +=== Styling with SASS + +When writing a new component, create a sibling SASS file of the same +name and import directly into the JS/TS component file. Doing so ensures +the styles are never separated or lost on import and allows for better +modularization (smaller individual plugin asset footprint). + +All SASS (.scss) files will automatically build with the +https://elastic.github.io/eui/#/guidelines/sass[EUI] & {kib} invisibles (SASS variables, mixins, functions) from +the {kib-repo}tree/{branch}/src/legacy/ui/public/styles/_globals_v7light.scss[globals_THEME.scss] file. + +*Example:* + +[source,tsx] +---- +// component.tsx + +import './component.scss'; + +export const Component = () => { + return ( +
+ ); +} +---- + +[source,scss] +---- +// component.scss + +.plgComponent { ... } +---- + +Do not use the underscore `_` SASS file naming pattern when importing +directly into a javascript file. \ No newline at end of file diff --git a/docs/developer/index.asciidoc b/docs/developer/index.asciidoc index 50e41a4e18207..db57815a1285a 100644 --- a/docs/developer/index.asciidoc +++ b/docs/developer/index.asciidoc @@ -3,25 +3,27 @@ [partintro] -- -Contributing to Kibana can be daunting at first, but it doesn't have to be. If -you're planning a pull request to the Kibana repository, you may want to start -with <>. +Contributing to {kib} can be daunting at first, but it doesn't have to be. The following sections should get you up and +running in no time. If you have any problems, file an issue in the https://github.com/elastic/kibana/issues[Kibana repo]. -If you'd prefer to use Kibana's internal plugin API, then check out -<>. --- +* <> +* <> +* <> +* <> +* <> +* <> -include::core-development.asciidoc[] +-- -include::plugin-development.asciidoc[] +include::getting-started/index.asciidoc[] -include::visualize/development-visualize-index.asciidoc[] +include::best-practices/index.asciidoc[] -include::add-data-guide.asciidoc[] +include::architecture/index.asciidoc[] -include::security/index.asciidoc[] +include::contributing/index.asciidoc[] -include::pr-review.asciidoc[] +include::plugin/index.asciidoc[] -include::testing/interpreting-ci-failures.asciidoc[] +include::advanced/index.asciidoc[] diff --git a/docs/developer/plugin-development.asciidoc b/docs/developer/plugin-development.asciidoc deleted file mode 100644 index 691fdb0412fd2..0000000000000 --- a/docs/developer/plugin-development.asciidoc +++ /dev/null @@ -1,24 +0,0 @@ -[[plugin-development]] -== Plugin Development - -[IMPORTANT] -============================================== -The Kibana plugin interfaces are in a state of constant development. We cannot provide backwards compatibility for plugins due to the high rate of change. Kibana enforces that the installed plugins match the version of Kibana itself. Plugin developers will have to release a new version of their plugin for each new Kibana release as a result. -============================================== - -* <> -* <> -* <> -* <> -* <> - -include::plugin/development-plugin-resources.asciidoc[] - -include::plugin/development-uiexports.asciidoc[] - -include::plugin/development-plugin-feature-registration.asciidoc[] - -include::plugin/development-plugin-functional-tests.asciidoc[] - -include::plugin/development-plugin-localization.asciidoc[] - diff --git a/docs/developer/plugin/development-uiexports.asciidoc b/docs/developer/plugin/development-uiexports.asciidoc deleted file mode 100644 index 18d326cbfb9c0..0000000000000 --- a/docs/developer/plugin/development-uiexports.asciidoc +++ /dev/null @@ -1,16 +0,0 @@ -[[development-uiexports]] -=== UI Exports - -An aggregate list of available UiExport types: - -[cols="> docs are the best place to +start. However, there are a few differences when developing plugins outside the {kib} repo. These differences are covered here. + +[float] +[[automatic-plugin-generator]] +==== Automatic plugin generator + +We recommend that you kick-start your plugin by generating it with the {kib-repo}tree/{branch}/packages/kbn-plugin-generator[Kibana Plugin Generator]. Run the following in the {kib} repo, and you will be asked a couple questions, see some progress bars, and have a freshly generated plugin ready for you to play with in {kib}'s `plugins` folder. + +["source","shell"] +----------- +node scripts/generate_plugin my_plugin_name # replace "my_plugin_name" with your desired plugin name +----------- + +[float] +=== Plugin location + +The {kib} directory must be named `kibana`, and your plugin directory should be located in the root of `kibana` in a `plugins` directory, for example: + +["source","shell"] +---- +. +└── kibana + └── plugins + ├── foo-plugin + └── bar-plugin +---- + +* <> +* <> + +include::external-plugin-functional-tests.asciidoc[] + +include::external-plugin-localization.asciidoc[] diff --git a/docs/developer/security/index.asciidoc b/docs/developer/security/index.asciidoc deleted file mode 100644 index e7ef0b85930e4..0000000000000 --- a/docs/developer/security/index.asciidoc +++ /dev/null @@ -1,12 +0,0 @@ -[[development-security]] -== Security - -Kibana has generally been able to implement security transparently to core and plugin developers, and this largely remains the case. {kib} on two methods that the <>'s `Cluster` provides: `callWithRequest` and `callWithInternalUser`. - -`callWithRequest` executes requests against Elasticsearch using the authentication credentials of the Kibana end-user. So, if you log into Kibana with the user of `foo` when `callWithRequest` is used, {kib} execute the request against Elasticsearch as the user `foo`. Historically, `callWithRequest` has been used extensively to perform actions that are initiated at the request of Kibana end-users. - -`callWithInternalUser` executes requests against Elasticsearch using the internal Kibana server user, and has historically been used for performing actions that aren't initiated by Kibana end users; for example, creating the initial `.kibana` index or performing health checks against Elasticsearch. - -However, with the changes that role-based access control (RBAC) introduces, this is no longer cut and dry. {kib} now requires all access to the `.kibana` index goes through the `SavedObjectsClient`. This used to be a best practice, as the `SavedObjectsClient` was responsible for translating the documents stored in Elasticsearch to and from Saved Objects, but RBAC is now taking advantage of this abstraction to implement access control and determine when to use `callWithRequest` versus `callWithInternalUser`. - -include::rbac.asciidoc[] From a906c732b02cb54e9f19c00c01c2a526ce2d450f Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 13 Jul 2020 11:00:58 -0400 Subject: [PATCH 18/28] [Ingest Manager] During fleet setup create an enrollment for every config (#71308) --- .../ingest_manager/server/services/setup.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/services/setup.ts b/x-pack/plugins/ingest_manager/server/services/setup.ts index e27a5456a5a7d..627abc158143d 100644 --- a/x-pack/plugins/ingest_manager/server/services/setup.ts +++ b/x-pack/plugins/ingest_manager/server/services/setup.ts @@ -180,11 +180,18 @@ export async function setupFleet( fleet_enroll_password: password, }); - // Generate default enrollment key - await generateEnrollmentAPIKey(soClient, { - name: 'Default', - configId: await agentConfigService.getDefaultAgentConfigId(soClient), + const { items: agentConfigs } = await agentConfigService.list(soClient, { + perPage: 10000, }); + + await Promise.all( + agentConfigs.map((agentConfig) => { + return generateEnrollmentAPIKey(soClient, { + name: `Default`, + configId: agentConfig.id, + }); + }) + ); } function generateRandomPassword() { From f0d744e8659a0f9d8369226084151bff235afe2c Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Mon, 13 Jul 2020 17:03:41 +0200 Subject: [PATCH 19/28] inclusive language (#71438) --- .../repository_form/type_settings/readonly_settings.tsx | 2 +- x-pack/plugins/translations/translations/ja-JP.json | 1 - x-pack/plugins/translations/translations/zh-CN.json | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/plugins/snapshot_restore/public/application/components/repository_form/type_settings/readonly_settings.tsx b/x-pack/plugins/snapshot_restore/public/application/components/repository_form/type_settings/readonly_settings.tsx index 309dad366bef8..17cce6efafb6f 100644 --- a/x-pack/plugins/snapshot_restore/public/application/components/repository_form/type_settings/readonly_settings.tsx +++ b/x-pack/plugins/snapshot_restore/public/application/components/repository_form/type_settings/readonly_settings.tsx @@ -46,7 +46,7 @@ export const ReadonlySettings: React.FunctionComponent = ({ case 'ftp': return ( repositories.url.allowed_urls, diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 92285d8bf72f8..4118053396e90 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -15258,7 +15258,6 @@ "xpack.snapshotRestore.repositoryForm.typeReadonly.urlLabel": "パス (必須)", "xpack.snapshotRestore.repositoryForm.typeReadonly.urlSchemeLabel": "スキーム", "xpack.snapshotRestore.repositoryForm.typeReadonly.urlTitle": "URL", - "xpack.snapshotRestore.repositoryForm.typeReadonly.urlWhitelistDescription": "この URL は {settingKey} 設定で登録する必要があります。", "xpack.snapshotRestore.repositoryForm.typeS3.basePathDescription": "レポジトリデータへのバケットパスです。", "xpack.snapshotRestore.repositoryForm.typeS3.basePathLabel": "ベースパス", "xpack.snapshotRestore.repositoryForm.typeS3.basePathTitle": "ベースパス", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 457f65e89083d..01939bea417d4 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -15264,7 +15264,6 @@ "xpack.snapshotRestore.repositoryForm.typeReadonly.urlLabel": "路径(必填)", "xpack.snapshotRestore.repositoryForm.typeReadonly.urlSchemeLabel": "方案", "xpack.snapshotRestore.repositoryForm.typeReadonly.urlTitle": "URL", - "xpack.snapshotRestore.repositoryForm.typeReadonly.urlWhitelistDescription": "必须在 {settingKey} 设置中注册此 URL。", "xpack.snapshotRestore.repositoryForm.typeS3.basePathDescription": "存储库数据的存储桶路径。", "xpack.snapshotRestore.repositoryForm.typeS3.basePathLabel": "基路径", "xpack.snapshotRestore.repositoryForm.typeS3.basePathTitle": "基路径", From f0c9915280f5c92e1e32cdc39a70b84ef4cea367 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Mon, 13 Jul 2020 08:09:04 -0700 Subject: [PATCH 20/28] [APM] Anomaly detection integration with transaction duration chart (#71230) * Reintroduces the previous anomaly detection ML integration back into the transaction duration chart in the service details screen. Support the latest APM anoamly detection by environment jobs. * PR feedback * Code improvements from PR feedback * handle errors thrown when fetching ml job for current environment Co-authored-by: Elastic Machine --- .../app/TransactionDetails/index.tsx | 1 - .../app/TransactionOverview/index.tsx | 2 - .../shared/charts/TransactionCharts/index.tsx | 18 ++- .../apm/public/selectors/chartSelectors.ts | 2 + .../charts/get_anomaly_data/fetcher.ts | 93 ++++++++++++ .../get_anomaly_data/get_ml_bucket_size.ts | 61 ++++++++ .../charts/get_anomaly_data/index.ts | 72 ++++++++-- .../charts/get_anomaly_data/transform.ts | 136 ++++++++++++++++++ .../server/lib/transactions/charts/index.ts | 4 + .../server/lib/transactions/queries.test.ts | 8 ++ .../apm/server/routes/transaction_groups.ts | 16 ++- 11 files changed, 390 insertions(+), 23 deletions(-) create mode 100644 x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/fetcher.ts create mode 100644 x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts create mode 100644 x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts diff --git a/x-pack/plugins/apm/public/components/app/TransactionDetails/index.tsx b/x-pack/plugins/apm/public/components/app/TransactionDetails/index.tsx index 620ae6708eda0..c56b7b9aaa720 100644 --- a/x-pack/plugins/apm/public/components/app/TransactionDetails/index.tsx +++ b/x-pack/plugins/apm/public/components/app/TransactionDetails/index.tsx @@ -89,7 +89,6 @@ export function TransactionDetails() { { }; public renderMLHeader(hasValidMlLicense: boolean | undefined) { - const { hasMLJob } = this.props; - if (!hasValidMlLicense || !hasMLJob) { + const { mlJobId } = this.props.charts; + + if (!hasValidMlLicense || !mlJobId) { return null; } - const { serviceName, kuery } = this.props.urlParams; + const { serviceName, kuery, transactionType } = this.props.urlParams; if (!serviceName) { return null; } - const linkedJobId = ''; // TODO [APM ML] link to ML job id for the selected environment - const hasKuery = !isEmpty(kuery); const icon = hasKuery ? ( { } )}{' '} - View Job + + View Job + ); diff --git a/x-pack/plugins/apm/public/selectors/chartSelectors.ts b/x-pack/plugins/apm/public/selectors/chartSelectors.ts index 714d62a703f51..26c2365ed77e1 100644 --- a/x-pack/plugins/apm/public/selectors/chartSelectors.ts +++ b/x-pack/plugins/apm/public/selectors/chartSelectors.ts @@ -33,6 +33,7 @@ export interface ITpmBucket { export interface ITransactionChartData { tpmSeries: ITpmBucket[]; responseTimeSeries: TimeSeries[]; + mlJobId: string | undefined; } const INITIAL_DATA = { @@ -62,6 +63,7 @@ export function getTransactionCharts( return { tpmSeries, responseTimeSeries, + mlJobId: anomalyTimeseries?.jobId, }; } diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/fetcher.ts b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/fetcher.ts new file mode 100644 index 0000000000000..3cf9a54e3fe9b --- /dev/null +++ b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/fetcher.ts @@ -0,0 +1,93 @@ +/* + * 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 { Logger } from 'kibana/server'; +import { PromiseReturnType } from '../../../../../../observability/typings/common'; +import { Setup, SetupTimeRange } from '../../../helpers/setup_request'; + +export type ESResponse = Exclude< + PromiseReturnType, + undefined +>; + +export async function anomalySeriesFetcher({ + serviceName, + transactionType, + intervalString, + mlBucketSize, + setup, + jobId, + logger, +}: { + serviceName: string; + transactionType: string; + intervalString: string; + mlBucketSize: number; + setup: Setup & SetupTimeRange; + jobId: string; + logger: Logger; +}) { + const { ml, start, end } = setup; + if (!ml) { + return; + } + + // move the start back with one bucket size, to ensure to get anomaly data in the beginning + // this is required because ML has a minimum bucket size (default is 900s) so if our buckets are smaller, we might have several null buckets in the beginning + const newStart = start - mlBucketSize * 1000; + + const params = { + body: { + size: 0, + query: { + bool: { + filter: [ + { term: { job_id: jobId } }, + { exists: { field: 'bucket_span' } }, + { term: { result_type: 'model_plot' } }, + { term: { partition_field_value: serviceName } }, + { term: { by_field_value: transactionType } }, + { + range: { + timestamp: { gte: newStart, lte: end, format: 'epoch_millis' }, + }, + }, + ], + }, + }, + aggs: { + ml_avg_response_times: { + date_histogram: { + field: 'timestamp', + fixed_interval: intervalString, + min_doc_count: 0, + extended_bounds: { min: newStart, max: end }, + }, + aggs: { + anomaly_score: { max: { field: 'anomaly_score' } }, + lower: { min: { field: 'model_lower' } }, + upper: { max: { field: 'model_upper' } }, + }, + }, + }, + }, + }; + + try { + const response = await ml.mlSystem.mlAnomalySearch(params); + return response; + } catch (err) { + const isHttpError = 'statusCode' in err; + if (isHttpError) { + logger.info( + `Status code "${err.statusCode}" while retrieving ML anomalies for APM` + ); + return; + } + logger.error('An error occurred while retrieving ML anomalies for APM'); + logger.error(err); + } +} diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts new file mode 100644 index 0000000000000..2f5e703251c03 --- /dev/null +++ b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts @@ -0,0 +1,61 @@ +/* + * 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 { Logger } from 'kibana/server'; +import { Setup, SetupTimeRange } from '../../../helpers/setup_request'; + +interface IOptions { + setup: Setup & SetupTimeRange; + jobId: string; + logger: Logger; +} + +interface ESResponse { + bucket_span: number; +} + +export async function getMlBucketSize({ + setup, + jobId, + logger, +}: IOptions): Promise { + const { ml, start, end } = setup; + if (!ml) { + return; + } + + const params = { + body: { + _source: 'bucket_span', + size: 1, + terminateAfter: 1, + query: { + bool: { + filter: [ + { term: { job_id: jobId } }, + { exists: { field: 'bucket_span' } }, + { + range: { + timestamp: { gte: start, lte: end, format: 'epoch_millis' }, + }, + }, + ], + }, + }, + }, + }; + + try { + const resp = await ml.mlSystem.mlAnomalySearch(params); + return resp.hits.hits[0]?._source.bucket_span; + } catch (err) { + const isHttpError = 'statusCode' in err; + if (isHttpError) { + return; + } + logger.error(err); + } +} diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/index.ts b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/index.ts index b2d11f2ffe19a..072099bc9553c 100644 --- a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/index.ts @@ -3,18 +3,19 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - +import { Logger } from 'kibana/server'; +import { isNumber } from 'lodash'; +import { getBucketSize } from '../../../helpers/get_bucket_size'; import { Setup, SetupTimeRange, SetupUIFilters, } from '../../../helpers/setup_request'; -import { Coordinate, RectCoordinate } from '../../../../../typings/timeseries'; - -interface AnomalyTimeseries { - anomalyBoundaries: Coordinate[]; - anomalyScore: RectCoordinate[]; -} +import { anomalySeriesFetcher } from './fetcher'; +import { getMlBucketSize } from './get_ml_bucket_size'; +import { anomalySeriesTransform } from './transform'; +import { getMLJobIds } from '../../../service_map/get_service_anomalies'; +import { UIFilters } from '../../../../../typings/ui_filters'; export async function getAnomalySeries({ serviceName, @@ -22,13 +23,17 @@ export async function getAnomalySeries({ transactionName, timeSeriesDates, setup, + logger, + uiFilters, }: { serviceName: string; transactionType: string | undefined; transactionName: string | undefined; timeSeriesDates: number[]; setup: Setup & SetupTimeRange & SetupUIFilters; -}): Promise { + logger: Logger; + uiFilters: UIFilters; +}) { // don't fetch anomalies for transaction details page if (transactionName) { return; @@ -39,8 +44,12 @@ export async function getAnomalySeries({ return; } - // don't fetch anomalies if uiFilters are applied - if (setup.uiFiltersES.length > 0) { + // don't fetch anomalies if unknown uiFilters are applied + const knownFilters = ['environment', 'serviceName']; + const uiFilterNames = Object.keys(uiFilters); + if ( + uiFilterNames.some((uiFilterName) => !knownFilters.includes(uiFilterName)) + ) { return; } @@ -55,6 +64,45 @@ export async function getAnomalySeries({ return; } - // TODO [APM ML] return a series of anomaly scores, upper & lower bounds for the given timeSeriesDates - return; + let mlJobIds: string[] = []; + try { + mlJobIds = await getMLJobIds(setup.ml, uiFilters.environment); + } catch (error) { + logger.error(error); + return; + } + + // don't fetch anomalies if there are isn't exaclty 1 ML job match for the given environment + if (mlJobIds.length !== 1) { + return; + } + const jobId = mlJobIds[0]; + + const mlBucketSize = await getMlBucketSize({ setup, jobId, logger }); + if (!isNumber(mlBucketSize)) { + return; + } + + const { start, end } = setup; + const { intervalString, bucketSize } = getBucketSize(start, end, 'auto'); + + const esResponse = await anomalySeriesFetcher({ + serviceName, + transactionType, + intervalString, + mlBucketSize, + setup, + jobId, + logger, + }); + + if (esResponse && mlBucketSize > 0) { + return anomalySeriesTransform( + esResponse, + mlBucketSize, + bucketSize, + timeSeriesDates, + jobId + ); + } } diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts new file mode 100644 index 0000000000000..393a73f7c1ccd --- /dev/null +++ b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts @@ -0,0 +1,136 @@ +/* + * 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 { first, last } from 'lodash'; +import { Coordinate, RectCoordinate } from '../../../../../typings/timeseries'; +import { ESResponse } from './fetcher'; + +type IBucket = ReturnType; +function getBucket( + bucket: Required< + ESResponse + >['aggregations']['ml_avg_response_times']['buckets'][0] +) { + return { + x: bucket.key, + anomalyScore: bucket.anomaly_score.value, + lower: bucket.lower.value, + upper: bucket.upper.value, + }; +} + +export type AnomalyTimeSeriesResponse = ReturnType< + typeof anomalySeriesTransform +>; +export function anomalySeriesTransform( + response: ESResponse, + mlBucketSize: number, + bucketSize: number, + timeSeriesDates: number[], + jobId: string +) { + const buckets = + response.aggregations?.ml_avg_response_times.buckets.map(getBucket) || []; + + const bucketSizeInMillis = Math.max(bucketSize, mlBucketSize) * 1000; + + return { + jobId, + anomalyScore: getAnomalyScoreDataPoints( + buckets, + timeSeriesDates, + bucketSizeInMillis + ), + anomalyBoundaries: getAnomalyBoundaryDataPoints(buckets, timeSeriesDates), + }; +} + +export function getAnomalyScoreDataPoints( + buckets: IBucket[], + timeSeriesDates: number[], + bucketSizeInMillis: number +): RectCoordinate[] { + const ANOMALY_THRESHOLD = 75; + const firstDate = first(timeSeriesDates); + const lastDate = last(timeSeriesDates); + + if (firstDate === undefined || lastDate === undefined) { + return []; + } + + return buckets + .filter( + (bucket) => + bucket.anomalyScore !== null && bucket.anomalyScore > ANOMALY_THRESHOLD + ) + .filter(isInDateRange(firstDate, lastDate)) + .map((bucket) => { + return { + x0: bucket.x, + x: Math.min(bucket.x + bucketSizeInMillis, lastDate), // don't go beyond last date + }; + }); +} + +export function getAnomalyBoundaryDataPoints( + buckets: IBucket[], + timeSeriesDates: number[] +): Coordinate[] { + return replaceFirstAndLastBucket(buckets, timeSeriesDates) + .filter((bucket) => bucket.lower !== null) + .map((bucket) => { + return { + x: bucket.x, + y0: bucket.lower, + y: bucket.upper, + }; + }); +} + +export function replaceFirstAndLastBucket( + buckets: IBucket[], + timeSeriesDates: number[] +) { + const firstDate = first(timeSeriesDates); + const lastDate = last(timeSeriesDates); + + if (firstDate === undefined || lastDate === undefined) { + return buckets; + } + + const preBucketWithValue = buckets + .filter((p) => p.x <= firstDate) + .reverse() + .find((p) => p.lower !== null); + + const bucketsInRange = buckets.filter(isInDateRange(firstDate, lastDate)); + + // replace first bucket if it is null + const firstBucket = first(bucketsInRange); + if (preBucketWithValue && firstBucket && firstBucket.lower === null) { + firstBucket.lower = preBucketWithValue.lower; + firstBucket.upper = preBucketWithValue.upper; + } + + const lastBucketWithValue = [...buckets] + .reverse() + .find((p) => p.lower !== null); + + // replace last bucket if it is null + const lastBucket = last(bucketsInRange); + if (lastBucketWithValue && lastBucket && lastBucket.lower === null) { + lastBucket.lower = lastBucketWithValue.lower; + lastBucket.upper = lastBucketWithValue.upper; + } + + return bucketsInRange; +} + +// anomaly time series contain one or more buckets extra in the beginning +// these extra buckets should be removed +function isInDateRange(firstDate: number, lastDate: number) { + return (p: IBucket) => p.x >= firstDate && p.x <= lastDate; +} diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/index.ts b/x-pack/plugins/apm/server/lib/transactions/charts/index.ts index 2ec049002d605..e862982145f77 100644 --- a/x-pack/plugins/apm/server/lib/transactions/charts/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/charts/index.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { Logger } from 'kibana/server'; import { PromiseReturnType } from '../../../../../observability/typings/common'; import { Setup, @@ -13,6 +14,7 @@ import { import { getAnomalySeries } from './get_anomaly_data'; import { getApmTimeseriesData } from './get_timeseries_data'; import { ApmTimeSeriesResponse } from './get_timeseries_data/transform'; +import { UIFilters } from '../../../../typings/ui_filters'; function getDates(apmTimeseries: ApmTimeSeriesResponse) { return apmTimeseries.responseTimes.avg.map((p) => p.x); @@ -26,6 +28,8 @@ export async function getTransactionCharts(options: { transactionType: string | undefined; transactionName: string | undefined; setup: Setup & SetupTimeRange & SetupUIFilters; + logger: Logger; + uiFilters: UIFilters; }) { const apmTimeseries = await getApmTimeseriesData(options); const anomalyTimeseries = await getAnomalySeries({ diff --git a/x-pack/plugins/apm/server/lib/transactions/queries.test.ts b/x-pack/plugins/apm/server/lib/transactions/queries.test.ts index 713635cff2fbf..586fa1798b7bc 100644 --- a/x-pack/plugins/apm/server/lib/transactions/queries.test.ts +++ b/x-pack/plugins/apm/server/lib/transactions/queries.test.ts @@ -12,6 +12,8 @@ import { SearchParamsMock, inspectSearchParams, } from '../../../public/utils/testHelpers'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { loggerMock } from '../../../../../../src/core/server/logging/logger.mock'; describe('transaction queries', () => { let mock: SearchParamsMock; @@ -52,6 +54,8 @@ describe('transaction queries', () => { transactionName: undefined, transactionType: undefined, setup, + logger: loggerMock.create(), + uiFilters: {}, }) ); expect(mock.params).toMatchSnapshot(); @@ -64,6 +68,8 @@ describe('transaction queries', () => { transactionName: 'bar', transactionType: undefined, setup, + logger: loggerMock.create(), + uiFilters: {}, }) ); expect(mock.params).toMatchSnapshot(); @@ -76,6 +82,8 @@ describe('transaction queries', () => { transactionName: 'bar', transactionType: 'baz', setup, + logger: loggerMock.create(), + uiFilters: {}, }) ); diff --git a/x-pack/plugins/apm/server/routes/transaction_groups.ts b/x-pack/plugins/apm/server/routes/transaction_groups.ts index 9ad281159fca5..3d939b04795c6 100644 --- a/x-pack/plugins/apm/server/routes/transaction_groups.ts +++ b/x-pack/plugins/apm/server/routes/transaction_groups.ts @@ -14,6 +14,7 @@ import { createRoute } from './create_route'; import { uiFiltersRt, rangeRt } from './default_api_types'; import { getTransactionAvgDurationByBrowser } from '../lib/transactions/avg_duration_by_browser'; import { getTransactionAvgDurationByCountry } from '../lib/transactions/avg_duration_by_country'; +import { UIFilters } from '../../typings/ui_filters'; export const transactionGroupsRoute = createRoute(() => ({ path: '/api/apm/services/{serviceName}/transaction_groups', @@ -62,14 +63,27 @@ export const transactionGroupsChartsRoute = createRoute(() => ({ }, handler: async ({ context, request }) => { const setup = await setupRequest(context, request); + const logger = context.logger; const { serviceName } = context.params.path; - const { transactionType, transactionName } = context.params.query; + const { + transactionType, + transactionName, + uiFilters: uiFiltersJson, + } = context.params.query; + let uiFilters: UIFilters = {}; + try { + uiFilters = JSON.parse(uiFiltersJson); + } catch (error) { + logger.error(error); + } return getTransactionCharts({ serviceName, transactionType, transactionName, setup, + logger, + uiFilters, }); }, })); From ae231feef7c393d730e374bab11c46c592c848df Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Mon, 13 Jul 2020 08:09:55 -0700 Subject: [PATCH 21/28] [APM] Anomaly detection setup link with alert if job doesn't exist (#71229) * Closes #70440 by adding a setup link to anomaly detection setting in the home header * PR feedback and type error fix * Code cleanup and PR feedback * Modified getEnvironmentUiFilterES return type from `ESFilter | undefined` to `ESFilter[]` for ease of use. Co-authored-by: Elastic Machine --- .../apm/common/environment_filter_values.ts | 11 +++ .../apm/public/components/app/Home/index.tsx | 4 + .../anomaly_detection/add_environments.tsx | 11 +-- .../Settings/anomaly_detection/jobs_list.tsx | 11 +-- .../Links/apm/AnomalyDetectionSetupLink.tsx | 63 +++++++++++++ .../create_anomaly_detection_jobs.ts | 17 +--- .../get_environment_ui_filter_es.test.ts | 17 ++-- .../get_environment_ui_filter_es.ts | 15 +-- .../convert_ui_filters/get_ui_filters_es.ts | 13 +-- .../get_service_map_service_node_info.ts | 93 +++---------------- .../get_derived_service_annotations.ts | 7 +- .../annotations/get_stored_annotations.ts | 4 +- 12 files changed, 117 insertions(+), 149 deletions(-) create mode 100644 x-pack/plugins/apm/public/components/shared/Links/apm/AnomalyDetectionSetupLink.tsx diff --git a/x-pack/plugins/apm/common/environment_filter_values.ts b/x-pack/plugins/apm/common/environment_filter_values.ts index 239378d0ea94a..38b6f480ca3d3 100644 --- a/x-pack/plugins/apm/common/environment_filter_values.ts +++ b/x-pack/plugins/apm/common/environment_filter_values.ts @@ -4,5 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ +import { i18n } from '@kbn/i18n'; + export const ENVIRONMENT_ALL = 'ENVIRONMENT_ALL'; export const ENVIRONMENT_NOT_DEFINED = 'ENVIRONMENT_NOT_DEFINED'; + +export function getEnvironmentLabel(environment: string) { + if (environment === ENVIRONMENT_NOT_DEFINED) { + return i18n.translate('xpack.apm.filter.environment.notDefinedLabel', { + defaultMessage: 'Not defined', + }); + } + return environment; +} diff --git a/x-pack/plugins/apm/public/components/app/Home/index.tsx b/x-pack/plugins/apm/public/components/app/Home/index.tsx index f612ac0d383ef..bcc834fef6a6a 100644 --- a/x-pack/plugins/apm/public/components/app/Home/index.tsx +++ b/x-pack/plugins/apm/public/components/app/Home/index.tsx @@ -20,6 +20,7 @@ import { EuiTabLink } from '../../shared/EuiTabLink'; import { ServiceMapLink } from '../../shared/Links/apm/ServiceMapLink'; import { ServiceOverviewLink } from '../../shared/Links/apm/ServiceOverviewLink'; import { SettingsLink } from '../../shared/Links/apm/SettingsLink'; +import { AnomalyDetectionSetupLink } from '../../shared/Links/apm/AnomalyDetectionSetupLink'; import { TraceOverviewLink } from '../../shared/Links/apm/TraceOverviewLink'; import { SetupInstructionsLink } from '../../shared/Links/SetupInstructionsLink'; import { ServiceMap } from '../ServiceMap'; @@ -118,6 +119,9 @@ export function Home({ tab }: Props) { + + + diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx index 2da3c12563104..98b4ae2f4b63f 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n'; import { useFetcher, FETCH_STATUS } from '../../../../hooks/useFetcher'; import { useApmPluginContext } from '../../../../hooks/useApmPluginContext'; import { createJobs } from './create_jobs'; -import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values'; +import { getEnvironmentLabel } from '../../../../../common/environment_filter_values'; interface Props { currentEnvironments: string[]; @@ -45,7 +45,7 @@ export const AddEnvironments = ({ ); const environmentOptions = data.map((env) => ({ - label: env === ENVIRONMENT_NOT_DEFINED ? NOT_DEFINED_OPTION_LABEL : env, + label: getEnvironmentLabel(env), value: env, disabled: currentEnvironments.includes(env), })); @@ -155,10 +155,3 @@ export const AddEnvironments = ({ ); }; - -const NOT_DEFINED_OPTION_LABEL = i18n.translate( - 'xpack.apm.filter.environment.notDefinedLabel', - { - defaultMessage: 'Not defined', - } -); diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx index 83d19aa27ac11..34687e5a8094e 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx @@ -22,7 +22,7 @@ import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt'; import { AnomalyDetectionJobByEnv } from '../../../../../typings/anomaly_detection'; import { MLJobLink } from '../../../shared/Links/MachineLearningLinks/MLJobLink'; import { MLLink } from '../../../shared/Links/MachineLearningLinks/MLLink'; -import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values'; +import { getEnvironmentLabel } from '../../../../../common/environment_filter_values'; import { LegacyJobsCallout } from './legacy_jobs_callout'; const columns: Array> = [ @@ -32,14 +32,7 @@ const columns: Array> = [ 'xpack.apm.settings.anomalyDetection.jobList.environmentColumnLabel', { defaultMessage: 'Environment' } ), - render: (environment: string) => { - if (environment === ENVIRONMENT_NOT_DEFINED) { - return i18n.translate('xpack.apm.filter.environment.notDefinedLabel', { - defaultMessage: 'Not defined', - }); - } - return environment; - }, + render: getEnvironmentLabel, }, { field: 'job_id', diff --git a/x-pack/plugins/apm/public/components/shared/Links/apm/AnomalyDetectionSetupLink.tsx b/x-pack/plugins/apm/public/components/shared/Links/apm/AnomalyDetectionSetupLink.tsx new file mode 100644 index 0000000000000..88d15239b8fba --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/Links/apm/AnomalyDetectionSetupLink.tsx @@ -0,0 +1,63 @@ +/* + * 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 React from 'react'; +import { EuiButtonEmpty, EuiToolTip, EuiIcon } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { APMLink } from './APMLink'; +import { getEnvironmentLabel } from '../../../../../common/environment_filter_values'; +import { useUrlParams } from '../../../../hooks/useUrlParams'; +import { useFetcher, FETCH_STATUS } from '../../../../hooks/useFetcher'; + +export function AnomalyDetectionSetupLink() { + const { uiFilters } = useUrlParams(); + const environment = uiFilters.environment; + + const { data = { jobs: [], hasLegacyJobs: false }, status } = useFetcher( + (callApmApi) => + callApmApi({ pathname: `/api/apm/settings/anomaly-detection` }), + [], + { preservePreviousData: false } + ); + const isFetchSuccess = status === FETCH_STATUS.SUCCESS; + + // Show alert if there are no jobs OR if no job matches the current environment + const showAlert = + isFetchSuccess && !data.jobs.some((job) => environment === job.environment); + + return ( + + + {ANOMALY_DETECTION_LINK_LABEL} + + {showAlert && ( + + + + )} + + ); +} + +function getTooltipText(environment?: string) { + if (!environment) { + return i18n.translate('xpack.apm.anomalyDetectionSetup.notEnabledText', { + defaultMessage: `Anomaly detection is not yet enabled. Click to continue setup.`, + }); + } + + return i18n.translate( + 'xpack.apm.anomalyDetectionSetup.notEnabledForEnvironmentText', + { + defaultMessage: `Anomaly detection is not yet enabled for the "{currentEnvironment}" environment. Click to continue setup.`, + values: { currentEnvironment: getEnvironmentLabel(environment) }, + } + ); +} + +const ANOMALY_DETECTION_LINK_LABEL = i18n.translate( + 'xpack.apm.anomalyDetectionSetup.linkLabel', + { defaultMessage: `Anomaly detection` } +); diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts index e723393a24013..c387c5152b1c5 100644 --- a/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts +++ b/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts @@ -10,12 +10,11 @@ import { snakeCase } from 'lodash'; import { PromiseReturnType } from '../../../../observability/typings/common'; import { Setup } from '../helpers/setup_request'; import { - SERVICE_ENVIRONMENT, TRANSACTION_DURATION, PROCESSOR_EVENT, } from '../../../common/elasticsearch_fieldnames'; -import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values'; import { APM_ML_JOB_GROUP, ML_MODULE_ID_APM_TRANSACTION } from './constants'; +import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es'; export type CreateAnomalyDetectionJobsAPIResponse = PromiseReturnType< typeof createAnomalyDetectionJobs @@ -89,9 +88,7 @@ async function createAnomalyDetectionJob({ filter: [ { term: { [PROCESSOR_EVENT]: 'transaction' } }, { exists: { field: TRANSACTION_DURATION } }, - environment === ENVIRONMENT_NOT_DEFINED - ? ENVIRONMENT_NOT_DEFINED_FILTER - : { term: { [SERVICE_ENVIRONMENT]: environment } }, + ...getEnvironmentUiFilterES(environment), ], }, }, @@ -109,13 +106,3 @@ async function createAnomalyDetectionJob({ ], }); } - -const ENVIRONMENT_NOT_DEFINED_FILTER = { - bool: { - must_not: { - exists: { - field: SERVICE_ENVIRONMENT, - }, - }, - }, -}; diff --git a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts index 0f0a11a868d6d..800f809727eb6 100644 --- a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts +++ b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts @@ -7,24 +7,23 @@ import { getEnvironmentUiFilterES } from '../get_environment_ui_filter_es'; import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values'; import { SERVICE_ENVIRONMENT } from '../../../../../common/elasticsearch_fieldnames'; -import { ESFilter } from '../../../../../typings/elasticsearch'; describe('getEnvironmentUiFilterES', () => { - it('should return undefined, when environment is undefined', () => { + it('should return empty array, when environment is undefined', () => { const uiFilterES = getEnvironmentUiFilterES(); - expect(uiFilterES).toBeUndefined(); + expect(uiFilterES).toHaveLength(0); }); it('should create a filter for a service environment', () => { - const uiFilterES = getEnvironmentUiFilterES('test') as ESFilter; - expect(uiFilterES).toHaveProperty(['term', SERVICE_ENVIRONMENT], 'test'); + const uiFilterES = getEnvironmentUiFilterES('test'); + expect(uiFilterES).toHaveLength(1); + expect(uiFilterES[0]).toHaveProperty(['term', SERVICE_ENVIRONMENT], 'test'); }); it('should create a filter for missing service environments', () => { - const uiFilterES = getEnvironmentUiFilterES( - ENVIRONMENT_NOT_DEFINED - ) as ESFilter; - expect(uiFilterES).toHaveProperty( + const uiFilterES = getEnvironmentUiFilterES(ENVIRONMENT_NOT_DEFINED); + expect(uiFilterES).toHaveLength(1); + expect(uiFilterES[0]).toHaveProperty( ['bool', 'must_not', 'exists', 'field'], SERVICE_ENVIRONMENT ); diff --git a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts index 63d222a7fcb6e..87bc8dc968373 100644 --- a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts +++ b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts @@ -8,19 +8,12 @@ import { ESFilter } from '../../../../typings/elasticsearch'; import { ENVIRONMENT_NOT_DEFINED } from '../../../../common/environment_filter_values'; import { SERVICE_ENVIRONMENT } from '../../../../common/elasticsearch_fieldnames'; -export function getEnvironmentUiFilterES( - environment?: string -): ESFilter | undefined { +export function getEnvironmentUiFilterES(environment?: string): ESFilter[] { if (!environment) { - return undefined; + return []; } - if (environment === ENVIRONMENT_NOT_DEFINED) { - return { - bool: { must_not: { exists: { field: SERVICE_ENVIRONMENT } } }, - }; + return [{ bool: { must_not: { exists: { field: SERVICE_ENVIRONMENT } } } }]; } - return { - term: { [SERVICE_ENVIRONMENT]: environment }, - }; + return [{ term: { [SERVICE_ENVIRONMENT]: environment } }]; } diff --git a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts index b34d5535d58cc..c1405b44f2a8a 100644 --- a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts +++ b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts @@ -27,22 +27,19 @@ export function getUiFiltersES(uiFilters: UIFilters) { }; }) as ESFilter[]; - // remove undefined items from list const esFilters = [ - getKueryUiFilterES(uiFilters.kuery), - getEnvironmentUiFilterES(uiFilters.environment), - ] - .filter((filter) => !!filter) - .concat(mappedFilters) as ESFilter[]; + ...getKueryUiFilterES(uiFilters.kuery), + ...getEnvironmentUiFilterES(uiFilters.environment), + ].concat(mappedFilters) as ESFilter[]; return esFilters; } function getKueryUiFilterES(kuery?: string) { if (!kuery) { - return; + return []; } const ast = esKuery.fromKueryExpression(kuery); - return esKuery.toElasticsearchQuery(ast) as ESFilter; + return [esKuery.toElasticsearchQuery(ast) as ESFilter]; } diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts index be92bfe5a0099..dd5d19b620c51 100644 --- a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts +++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts @@ -9,7 +9,6 @@ import { ESFilter } from '../../../typings/elasticsearch'; import { rangeFilter } from '../../../common/utils/range_filter'; import { PROCESSOR_EVENT, - SERVICE_ENVIRONMENT, SERVICE_NAME, TRANSACTION_DURATION, TRANSACTION_TYPE, @@ -22,7 +21,7 @@ import { TRANSACTION_REQUEST, TRANSACTION_PAGE_LOAD, } from '../../../common/transaction_types'; -import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values'; +import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es'; interface Options { setup: Setup & SetupTimeRange; @@ -43,30 +42,14 @@ export async function getServiceMapServiceNodeInfo({ }: Options & { serviceName: string; environment?: string }) { const { start, end } = setup; - const environmentNotDefinedFilter = { - bool: { must_not: [{ exists: { field: SERVICE_ENVIRONMENT } }] }, - }; - const filter: ESFilter[] = [ { range: rangeFilter(start, end) }, { term: { [SERVICE_NAME]: serviceName } }, + ...getEnvironmentUiFilterES(environment), ]; - if (environment) { - filter.push( - environment === ENVIRONMENT_NOT_DEFINED - ? environmentNotDefinedFilter - : { term: { [SERVICE_ENVIRONMENT]: environment } } - ); - } - const minutes = Math.abs((end - start) / (1000 * 60)); - - const taskParams = { - setup, - minutes, - filter, - }; + const taskParams = { setup, minutes, filter }; const [ errorMetrics, @@ -97,11 +80,7 @@ async function getErrorMetrics({ setup, minutes, filter }: TaskParameters) { size: 0, query: { bool: { - filter: filter.concat({ - term: { - [PROCESSOR_EVENT]: 'error', - }, - }), + filter: filter.concat({ term: { [PROCESSOR_EVENT]: 'error' } }), }, }, track_total_hits: true, @@ -134,11 +113,7 @@ async function getTransactionStats({ bool: { filter: [ ...filter, - { - term: { - [PROCESSOR_EVENT]: 'transaction', - }, - }, + { term: { [PROCESSOR_EVENT]: 'transaction' } }, { terms: { [TRANSACTION_TYPE]: [ @@ -151,13 +126,7 @@ async function getTransactionStats({ }, }, track_total_hits: true, - aggs: { - duration: { - avg: { - field: TRANSACTION_DURATION, - }, - }, - }, + aggs: { duration: { avg: { field: TRANSACTION_DURATION } } }, }, }; const response = await client.search(params); @@ -181,32 +150,16 @@ async function getCpuMetrics({ query: { bool: { filter: filter.concat([ - { - term: { - [PROCESSOR_EVENT]: 'metric', - }, - }, - { - exists: { - field: METRIC_SYSTEM_CPU_PERCENT, - }, - }, + { term: { [PROCESSOR_EVENT]: 'metric' } }, + { exists: { field: METRIC_SYSTEM_CPU_PERCENT } }, ]), }, }, - aggs: { - avgCpuUsage: { - avg: { - field: METRIC_SYSTEM_CPU_PERCENT, - }, - }, - }, + aggs: { avgCpuUsage: { avg: { field: METRIC_SYSTEM_CPU_PERCENT } } }, }, }); - return { - avgCpuUsage: response.aggregations?.avgCpuUsage.value ?? null, - }; + return { avgCpuUsage: response.aggregations?.avgCpuUsage.value ?? null }; } async function getMemoryMetrics({ @@ -220,31 +173,13 @@ async function getMemoryMetrics({ query: { bool: { filter: filter.concat([ - { - term: { - [PROCESSOR_EVENT]: 'metric', - }, - }, - { - exists: { - field: METRIC_SYSTEM_FREE_MEMORY, - }, - }, - { - exists: { - field: METRIC_SYSTEM_TOTAL_MEMORY, - }, - }, + { term: { [PROCESSOR_EVENT]: 'metric' } }, + { exists: { field: METRIC_SYSTEM_FREE_MEMORY } }, + { exists: { field: METRIC_SYSTEM_TOTAL_MEMORY } }, ]), }, }, - aggs: { - avgMemoryUsage: { - avg: { - script: percentMemoryUsedScript, - }, - }, - }, + aggs: { avgMemoryUsage: { avg: { script: percentMemoryUsedScript } } }, }, }); diff --git a/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts b/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts index 6da5d195cf194..6a8aaf8dca8a6 100644 --- a/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts +++ b/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts @@ -29,14 +29,9 @@ export async function getDerivedServiceAnnotations({ const filter: ESFilter[] = [ { term: { [PROCESSOR_EVENT]: 'transaction' } }, { term: { [SERVICE_NAME]: serviceName } }, + ...getEnvironmentUiFilterES(environment), ]; - const environmentFilter = getEnvironmentUiFilterES(environment); - - if (environmentFilter) { - filter.push(environmentFilter); - } - const versions = ( await client.search({ diff --git a/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts b/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts index 75aeb27ea2122..6e3ae0181ddee 100644 --- a/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts +++ b/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts @@ -29,8 +29,6 @@ export async function getStoredAnnotations({ logger: Logger; }): Promise { try { - const environmentFilter = getEnvironmentUiFilterES(environment); - const response: ESSearchResponse = (await apiCaller( 'search', { @@ -51,7 +49,7 @@ export async function getStoredAnnotations({ { term: { 'annotation.type': 'deployment' } }, { term: { tags: 'apm' } }, { term: { [SERVICE_NAME]: serviceName } }, - ...(environmentFilter ? [environmentFilter] : []), + ...getEnvironmentUiFilterES(environment), ], }, }, From 4925a4983a74572b2fba84f46111f9d04225950e Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 13 Jul 2020 09:11:11 -0600 Subject: [PATCH 22/28] Ensure Other bucket works on scripted fields. (#71329) --- .../_terms_other_bucket_helper.test.ts | 77 +++++++++++++++++++ .../buckets/_terms_other_bucket_helper.ts | 10 ++- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts index 8e862b5692ca3..e9b4629ba88cf 100644 --- a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts @@ -316,6 +316,83 @@ describe('Terms Agg Other bucket helper', () => { } }); + test('excludes exists filter for scripted fields', () => { + const aggConfigs = getAggConfigs(nestedTerm.aggs); + aggConfigs.aggs[1].params.field.scripted = true; + const agg = buildOtherBucketAgg( + aggConfigs, + aggConfigs.aggs[1] as IBucketAggConfig, + nestedTermResponse + ); + const expectedResponse = { + 'other-filter': { + aggs: undefined, + filters: { + filters: { + '-IN': { + bool: { + must: [], + filter: [{ match_phrase: { 'geo.src': 'IN' } }], + should: [], + must_not: [ + { + script: { + script: { + lang: undefined, + params: { value: 'ios' }, + source: '(undefined) == value', + }, + }, + }, + { + script: { + script: { + lang: undefined, + params: { value: 'win xp' }, + source: '(undefined) == value', + }, + }, + }, + ], + }, + }, + '-US': { + bool: { + must: [], + filter: [{ match_phrase: { 'geo.src': 'US' } }], + should: [], + must_not: [ + { + script: { + script: { + lang: undefined, + params: { value: 'ios' }, + source: '(undefined) == value', + }, + }, + }, + { + script: { + script: { + lang: undefined, + params: { value: 'win xp' }, + source: '(undefined) == value', + }, + }, + }, + ], + }, + }, + }, + }, + }, + }; + expect(agg).toBeDefined(); + if (agg) { + expect(agg()).toEqual(expectedResponse); + } + }); + test('returns false when nested terms agg has no buckets', () => { const aggConfigs = getAggConfigs(nestedTerm.aggs); const agg = buildOtherBucketAgg( diff --git a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts index fba3d35f002af..1a7deafb548ae 100644 --- a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts +++ b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts @@ -202,10 +202,12 @@ export const buildOtherBucketAgg = ( return; } - if ( - !aggWithOtherBucket.params.missingBucket || - agg.buckets.some((bucket: { key: string }) => bucket.key === '__missing__') - ) { + const hasScriptedField = !!aggWithOtherBucket.params.field.scripted; + const hasMissingBucket = !!aggWithOtherBucket.params.missingBucket; + const hasMissingBucketKey = agg.buckets.some( + (bucket: { key: string }) => bucket.key === '__missing__' + ); + if (!hasScriptedField && (!hasMissingBucket || hasMissingBucketKey)) { filters.push( buildExistsFilter( aggWithOtherBucket.params.field, From 82f6c6a1df9168b104227e999d927ea500bb11cc Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Mon, 13 Jul 2020 08:12:53 -0700 Subject: [PATCH 23/28] [Ingest Manager] Simplify add/edit package config (integration) form (#71187) * Match add integration page with designs * Clean up package config layout code * Match edit integration config page with designs * Fix typing and i18n issues * Add back data test subj * Add loading UI for second step; code clean up * Fix limited packages incorrect response * Add ability to create agent config when selecting config to add integration to * Add error count to input-level panel; memoize children components * Add error count next to all advanced options toggles * Move general form error to bottom bar * #69750 Auto-expand inputs with required & empty (invalid) vars * #68019 Enforce unique package config names, per agent config * Fix typing * Fix i18n * Fix reloading when new agent config _wasn't_ created * Memoize edit integration and fix fields not collapsing on edit * Really fix types --- .../components/layout.tsx | 252 +++++++------- .../package_config_input_config.tsx | 281 ++++++++-------- .../components/package_config_input_panel.tsx | 317 +++++++++--------- .../package_config_input_stream.tsx | 293 ++++++++-------- .../package_config_input_var_field.tsx | 12 +- .../create_package_config_page/index.tsx | 213 +++++++----- .../has_invalid_but_required_var.test.ts | 94 ++++++ .../services/has_invalid_but_required_var.ts | 26 ++ .../services/index.ts | 3 + .../services/is_advanced_var.ts | 2 +- .../services/validate_package_config.ts | 17 +- .../step_configure_package.tsx | 120 +++---- .../step_define_package_config.tsx | 228 +++++++------ .../step_select_config.tsx | 231 ++++++++----- .../step_select_package.tsx | 25 +- .../edit_package_config_page/index.tsx | 191 ++++++----- .../list_page/components/create_config.tsx | 8 +- .../ingest_manager/types/index.ts | 1 + .../server/services/package_config.ts | 29 ++ .../translations/translations/ja-JP.json | 10 - .../translations/translations/zh-CN.json | 10 - .../apis/index.js | 1 + .../apis/package_config/create.ts | 43 +++ .../apis/package_config/update.ts | 127 +++++++ 24 files changed, 1506 insertions(+), 1028 deletions(-) create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.test.ts create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.ts create mode 100644 x-pack/test/ingest_manager_api_integration/apis/package_config/update.ts diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/layout.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/layout.tsx index e0f40f1b15375..7ccb59f0e741e 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/layout.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/layout.tsx @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React from 'react'; +import React, { memo, useMemo } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiFlexGroup, @@ -27,130 +27,148 @@ export const CreatePackageConfigPageLayout: React.FunctionComponent<{ agentConfig?: AgentConfig; packageInfo?: PackageInfo; 'data-test-subj'?: string; -}> = ({ - from, - cancelUrl, - onCancel, - agentConfig, - packageInfo, - children, - 'data-test-subj': dataTestSubj, -}) => { - const leftColumn = ( - - - {/* eslint-disable-next-line @elastic/eui/href-or-on-click */} - - - - - +}> = memo( + ({ + from, + cancelUrl, + onCancel, + agentConfig, + packageInfo, + children, + 'data-test-subj': dataTestSubj, + }) => { + const pageTitle = useMemo(() => { + if ((from === 'package' || from === 'edit') && packageInfo) { + return ( + + + + + + +

+ {from === 'edit' ? ( + + ) : ( + + )} +

+
+
+
+ ); + } + + return from === 'edit' ? (

- {from === 'edit' ? ( - - ) : ( - - )} +

-
- - - - {from === 'edit' ? ( + ) : ( + +

- ) : from === 'config' ? ( +

+
+ ); + }, [from, packageInfo]); + + const pageDescription = useMemo(() => { + return from === 'edit' ? ( + + ) : from === 'config' ? ( + + ) : ( + + ); + }, [from]); + + const leftColumn = ( + + + {/* eslint-disable-next-line @elastic/eui/href-or-on-click */} + - ) : ( + + + {pageTitle} + + + + {pageDescription} + + + + ); + + const rightColumn = + agentConfig && (from === 'config' || from === 'edit') ? ( + + - )} -
-
-
- ); - const rightColumn = ( - - - - {agentConfig && (from === 'config' || from === 'edit') ? ( - - - - - - {agentConfig?.name || '-'} - - - ) : null} - {packageInfo && from === 'package' ? ( - - - - - - - - - - - {packageInfo?.title || packageInfo?.name || '-'} - - - - - ) : null} - - - ); + + {agentConfig?.name || '-'} + + ) : undefined; - const maxWidth = 770; - return ( - - {children} - - ); -}; + const maxWidth = 770; + return ( + + {children} + + ); + } +); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_config.tsx index 85c0f2134d8dc..98f04dbd92659 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_config.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_config.tsx @@ -3,17 +3,15 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { useState, Fragment } from 'react'; +import React, { useState, Fragment, memo, useMemo } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { + EuiFlexGrid, EuiFlexGroup, EuiFlexItem, EuiText, - EuiTextColor, EuiSpacer, EuiButtonEmpty, - EuiTitle, - EuiIconTip, } from '@elastic/eui'; import { PackageConfigInput, RegistryVarsEntry } from '../../../../types'; import { @@ -29,150 +27,157 @@ export const PackageConfigInputConfig: React.FunctionComponent<{ updatePackageConfigInput: (updatedInput: Partial) => void; inputVarsValidationResults: PackageConfigConfigValidationResults; forceShowErrors?: boolean; -}> = ({ - packageInputVars, - packageConfigInput, - updatePackageConfigInput, - inputVarsValidationResults, - forceShowErrors, -}) => { - // Showing advanced options toggle state - const [isShowingAdvanced, setIsShowingAdvanced] = useState(false); +}> = memo( + ({ + packageInputVars, + packageConfigInput, + updatePackageConfigInput, + inputVarsValidationResults, + forceShowErrors, + }) => { + // Showing advanced options toggle state + const [isShowingAdvanced, setIsShowingAdvanced] = useState(false); - // Errors state - const hasErrors = forceShowErrors && validationHasErrors(inputVarsValidationResults); + // Errors state + const hasErrors = forceShowErrors && validationHasErrors(inputVarsValidationResults); - const requiredVars: RegistryVarsEntry[] = []; - const advancedVars: RegistryVarsEntry[] = []; + const requiredVars: RegistryVarsEntry[] = []; + const advancedVars: RegistryVarsEntry[] = []; - if (packageInputVars) { - packageInputVars.forEach((varDef) => { - if (isAdvancedVar(varDef)) { - advancedVars.push(varDef); - } else { - requiredVars.push(varDef); - } - }); - } + if (packageInputVars) { + packageInputVars.forEach((varDef) => { + if (isAdvancedVar(varDef)) { + advancedVars.push(varDef); + } else { + requiredVars.push(varDef); + } + }); + } + + const advancedVarsWithErrorsCount: number = useMemo( + () => + advancedVars.filter( + ({ name: varName }) => inputVarsValidationResults.vars?.[varName]?.length + ).length, + [advancedVars, inputVarsValidationResults.vars] + ); - return ( - - - - - -

- + return ( + + + + + + +

- -

+

+ + + +

+ +

+
- {hasErrors ? ( - - - } - position="right" - type="alert" - iconProps={{ color: 'danger' }} - /> - - ) : null}
-
- - -

- -

-
-
- - - {requiredVars.map((varDef) => { - const { name: varName, type: varType } = varDef; - const value = packageConfigInput.vars![varName].value; - return ( - - { - updatePackageConfigInput({ - vars: { - ...packageConfigInput.vars, - [varName]: { - type: varType, - value: newValue, + + + + {requiredVars.map((varDef) => { + const { name: varName, type: varType } = varDef; + const value = packageConfigInput.vars![varName].value; + return ( + + { + updatePackageConfigInput({ + vars: { + ...packageConfigInput.vars, + [varName]: { + type: varType, + value: newValue, + }, }, - }, - }); - }} - errors={inputVarsValidationResults.vars![varName]} - forceShowErrors={forceShowErrors} - /> - - ); - })} - {advancedVars.length ? ( - - - {/* Wrapper div to prevent button from going full width */} -
- setIsShowingAdvanced(!isShowingAdvanced)} - flush="left" - > - - -
-
- {isShowingAdvanced - ? advancedVars.map((varDef) => { - const { name: varName, type: varType } = varDef; - const value = packageConfigInput.vars![varName].value; - return ( - - { - updatePackageConfigInput({ - vars: { - ...packageConfigInput.vars, - [varName]: { - type: varType, - value: newValue, - }, - }, - }); - }} - errors={inputVarsValidationResults.vars![varName]} - forceShowErrors={forceShowErrors} + }); + }} + errors={inputVarsValidationResults.vars![varName]} + forceShowErrors={forceShowErrors} + /> + + ); + })} + {advancedVars.length ? ( + + + {/* Wrapper div to prevent button from going full width */} + + + setIsShowingAdvanced(!isShowingAdvanced)} + flush="left" + > + + + + {!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? ( + + + + - ); - }) - : null} - - ) : null} -
-
-
- ); -}; + ) : null} +
+ + {isShowingAdvanced + ? advancedVars.map((varDef) => { + const { name: varName, type: varType } = varDef; + const value = packageConfigInput.vars![varName].value; + return ( + + { + updatePackageConfigInput({ + vars: { + ...packageConfigInput.vars, + [varName]: { + type: varType, + value: newValue, + }, + }, + }); + }} + errors={inputVarsValidationResults.vars![varName]} + forceShowErrors={forceShowErrors} + /> + + ); + }) + : null} + + ) : null} + + + + ); + } +); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_panel.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_panel.tsx index f9c9dcd469b25..af26afdbf74d7 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_panel.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_panel.tsx @@ -3,21 +3,18 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { useState, Fragment } from 'react'; +import React, { useState, Fragment, memo } from 'react'; import styled from 'styled-components'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { - EuiPanel, EuiFlexGroup, EuiFlexItem, EuiSwitch, EuiText, - EuiTextColor, EuiButtonIcon, EuiHorizontalRule, EuiSpacer, - EuiIconTip, } from '@elastic/eui'; import { PackageConfigInput, @@ -25,16 +22,44 @@ import { RegistryInput, RegistryStream, } from '../../../../types'; -import { PackageConfigInputValidationResults, validationHasErrors } from '../services'; +import { + PackageConfigInputValidationResults, + hasInvalidButRequiredVar, + countValidationErrors, +} from '../services'; import { PackageConfigInputConfig } from './package_config_input_config'; import { PackageConfigInputStreamConfig } from './package_config_input_stream'; -const FlushHorizontalRule = styled(EuiHorizontalRule)` - margin-left: -${(props) => props.theme.eui.paddingSizes.m}; - margin-right: -${(props) => props.theme.eui.paddingSizes.m}; - width: auto; +const ShortenedHorizontalRule = styled(EuiHorizontalRule)` + &&& { + width: ${(11 / 12) * 100}%; + margin-left: auto; + } `; +const shouldShowStreamsByDefault = ( + packageInput: RegistryInput, + packageInputStreams: Array, + packageConfigInput: PackageConfigInput +): boolean => { + return ( + packageConfigInput.enabled && + (hasInvalidButRequiredVar(packageInput.vars, packageConfigInput.vars) || + Boolean( + packageInputStreams.find( + (stream) => + stream.enabled && + hasInvalidButRequiredVar( + stream.vars, + packageConfigInput.streams.find( + (pkgStream) => stream.dataset.name === pkgStream.dataset.name + )?.vars + ) + ) + )) + ); +}; + export const PackageConfigInputPanel: React.FunctionComponent<{ packageInput: RegistryInput; packageInputStreams: Array; @@ -42,148 +67,136 @@ export const PackageConfigInputPanel: React.FunctionComponent<{ updatePackageConfigInput: (updatedInput: Partial) => void; inputValidationResults: PackageConfigInputValidationResults; forceShowErrors?: boolean; -}> = ({ - packageInput, - packageInputStreams, - packageConfigInput, - updatePackageConfigInput, - inputValidationResults, - forceShowErrors, -}) => { - // Showing streams toggle state - const [isShowingStreams, setIsShowingStreams] = useState(false); +}> = memo( + ({ + packageInput, + packageInputStreams, + packageConfigInput, + updatePackageConfigInput, + inputValidationResults, + forceShowErrors, + }) => { + // Showing streams toggle state + const [isShowingStreams, setIsShowingStreams] = useState( + shouldShowStreamsByDefault(packageInput, packageInputStreams, packageConfigInput) + ); - // Errors state - const hasErrors = forceShowErrors && validationHasErrors(inputValidationResults); + // Errors state + const errorCount = countValidationErrors(inputValidationResults); + const hasErrors = forceShowErrors && errorCount; - return ( - - {/* Header / input-level toggle */} - - - - - -

- - {packageInput.title || packageInput.type} - -

-
-
- {hasErrors ? ( + const inputStreams = packageInputStreams + .map((packageInputStream) => { + return { + packageInputStream, + packageConfigInputStream: packageConfigInput.streams.find( + (stream) => stream.dataset.name === packageInputStream.dataset.name + ), + }; + }) + .filter((stream) => Boolean(stream.packageConfigInputStream)); + + return ( + <> + {/* Header / input-level toggle */} + + + - - } - position="right" - type="alert" - iconProps={{ color: 'danger' }} - /> + +

{packageInput.title || packageInput.type}

+
- ) : null} -
- } - checked={packageConfigInput.enabled} - onChange={(e) => { - const enabled = e.target.checked; - updatePackageConfigInput({ - enabled, - streams: packageConfigInput.streams.map((stream) => ({ - ...stream, +
+ } + checked={packageConfigInput.enabled} + onChange={(e) => { + const enabled = e.target.checked; + updatePackageConfigInput({ enabled, - })), - }); - }} - /> - - - - - - - - {packageConfigInput.streams.filter((stream) => stream.enabled).length} - - - ), - total: packageInputStreams.length, - }} - /> - - - - setIsShowingStreams(!isShowingStreams)} - color="text" - aria-label={ - isShowingStreams - ? i18n.translate( - 'xpack.ingestManager.createPackageConfig.stepConfigure.hideStreamsAriaLabel', - { - defaultMessage: 'Hide {type} streams', - values: { - type: packageInput.type, - }, - } - ) - : i18n.translate( - 'xpack.ingestManager.createPackageConfig.stepConfigure.showStreamsAriaLabel', - { - defaultMessage: 'Show {type} streams', - values: { - type: packageInput.type, - }, - } - ) + streams: packageConfigInput.streams.map((stream) => ({ + ...stream, + enabled, + })), + }); + if (!enabled && isShowingStreams) { + setIsShowingStreams(false); } - /> - - - - + }} + /> + + + + {hasErrors ? ( + + + + + + ) : null} + + setIsShowingStreams(!isShowingStreams)} + color={hasErrors ? 'danger' : 'text'} + aria-label={ + isShowingStreams + ? i18n.translate( + 'xpack.ingestManager.createPackageConfig.stepConfigure.hideStreamsAriaLabel', + { + defaultMessage: 'Hide {type} inputs', + values: { + type: packageInput.type, + }, + } + ) + : i18n.translate( + 'xpack.ingestManager.createPackageConfig.stepConfigure.showStreamsAriaLabel', + { + defaultMessage: 'Show {type} inputs', + values: { + type: packageInput.type, + }, + } + ) + } + /> + + + + - {/* Header rule break */} - {isShowingStreams ? : null} + {/* Header rule break */} + {isShowingStreams ? : null} - {/* Input level configuration */} - {isShowingStreams && packageInput.vars && packageInput.vars.length ? ( - - - - - ) : null} + {/* Input level configuration */} + {isShowingStreams && packageInput.vars && packageInput.vars.length ? ( + + + + + ) : null} - {/* Per-stream configuration */} - {isShowingStreams ? ( - - {packageInputStreams.map((packageInputStream) => { - const packageConfigInputStream = packageConfigInput.streams.find( - (stream) => stream.dataset.name === packageInputStream.dataset.name - ); - return packageConfigInputStream ? ( - + {/* Per-stream configuration */} + {isShowingStreams ? ( + + {inputStreams.map(({ packageInputStream, packageConfigInputStream }, index) => ( + ) => { @@ -213,17 +226,21 @@ export const PackageConfigInputPanel: React.FunctionComponent<{ updatePackageConfigInput(updatedInput); }} inputStreamValidationResults={ - inputValidationResults.streams![packageConfigInputStream.id] + inputValidationResults.streams![packageConfigInputStream!.id] } forceShowErrors={forceShowErrors} /> - - + {index !== inputStreams.length - 1 ? ( + <> + + + + ) : null} - ) : null; - })} - - ) : null} -
- ); -}; + ))} + + ) : null} + + ); + } +); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_stream.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_stream.tsx index 52a4748fe14c7..11a9df276485b 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_stream.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_stream.tsx @@ -3,18 +3,17 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { useState, Fragment } from 'react'; +import React, { useState, Fragment, memo, useMemo } from 'react'; import ReactMarkdown from 'react-markdown'; import { FormattedMessage } from '@kbn/i18n/react'; import { + EuiFlexGrid, EuiFlexGroup, EuiFlexItem, EuiSwitch, EuiText, EuiSpacer, EuiButtonEmpty, - EuiTextColor, - EuiIconTip, } from '@elastic/eui'; import { PackageConfigInputStream, RegistryStream, RegistryVarsEntry } from '../../../../types'; import { @@ -30,153 +29,157 @@ export const PackageConfigInputStreamConfig: React.FunctionComponent<{ updatePackageConfigInputStream: (updatedStream: Partial) => void; inputStreamValidationResults: PackageConfigConfigValidationResults; forceShowErrors?: boolean; -}> = ({ - packageInputStream, - packageConfigInputStream, - updatePackageConfigInputStream, - inputStreamValidationResults, - forceShowErrors, -}) => { - // Showing advanced options toggle state - const [isShowingAdvanced, setIsShowingAdvanced] = useState(false); +}> = memo( + ({ + packageInputStream, + packageConfigInputStream, + updatePackageConfigInputStream, + inputStreamValidationResults, + forceShowErrors, + }) => { + // Showing advanced options toggle state + const [isShowingAdvanced, setIsShowingAdvanced] = useState(); - // Errors state - const hasErrors = forceShowErrors && validationHasErrors(inputStreamValidationResults); + // Errors state + const hasErrors = forceShowErrors && validationHasErrors(inputStreamValidationResults); - const requiredVars: RegistryVarsEntry[] = []; - const advancedVars: RegistryVarsEntry[] = []; + const requiredVars: RegistryVarsEntry[] = []; + const advancedVars: RegistryVarsEntry[] = []; - if (packageInputStream.vars && packageInputStream.vars.length) { - packageInputStream.vars.forEach((varDef) => { - if (isAdvancedVar(varDef)) { - advancedVars.push(varDef); - } else { - requiredVars.push(varDef); - } - }); - } + if (packageInputStream.vars && packageInputStream.vars.length) { + packageInputStream.vars.forEach((varDef) => { + if (isAdvancedVar(varDef)) { + advancedVars.push(varDef); + } else { + requiredVars.push(varDef); + } + }); + } - return ( - - - - - - {packageInputStream.title} - - - {hasErrors ? ( - - - } - position="right" - type="alert" - iconProps={{ color: 'danger' }} - /> - + const advancedVarsWithErrorsCount: number = useMemo( + () => + advancedVars.filter( + ({ name: varName }) => inputStreamValidationResults.vars?.[varName]?.length + ).length, + [advancedVars, inputStreamValidationResults.vars] + ); + + return ( + + + + + + { + const enabled = e.target.checked; + updatePackageConfigInputStream({ + enabled, + }); + }} + /> + {packageInputStream.description ? ( + + + + + + ) : null} - - } - checked={packageConfigInputStream.enabled} - onChange={(e) => { - const enabled = e.target.checked; - updatePackageConfigInputStream({ - enabled, - }); - }} - /> - {packageInputStream.description ? ( - - - - - - - ) : null} - - - - {requiredVars.map((varDef) => { - const { name: varName, type: varType } = varDef; - const value = packageConfigInputStream.vars![varName].value; - return ( - - { - updatePackageConfigInputStream({ - vars: { - ...packageConfigInputStream.vars, - [varName]: { - type: varType, - value: newValue, + + + + + + {requiredVars.map((varDef) => { + const { name: varName, type: varType } = varDef; + const value = packageConfigInputStream.vars![varName].value; + return ( + + { + updatePackageConfigInputStream({ + vars: { + ...packageConfigInputStream.vars, + [varName]: { + type: varType, + value: newValue, + }, }, - }, - }); - }} - errors={inputStreamValidationResults.vars![varName]} - forceShowErrors={forceShowErrors} - /> - - ); - })} - {advancedVars.length ? ( - - - {/* Wrapper div to prevent button from going full width */} -
- setIsShowingAdvanced(!isShowingAdvanced)} - flush="left" - > - - -
-
- {isShowingAdvanced - ? advancedVars.map((varDef) => { - const { name: varName, type: varType } = varDef; - const value = packageConfigInputStream.vars![varName].value; - return ( - - { - updatePackageConfigInputStream({ - vars: { - ...packageConfigInputStream.vars, - [varName]: { - type: varType, - value: newValue, - }, - }, - }); - }} - errors={inputStreamValidationResults.vars![varName]} - forceShowErrors={forceShowErrors} + }); + }} + errors={inputStreamValidationResults.vars![varName]} + forceShowErrors={forceShowErrors} + /> + + ); + })} + {advancedVars.length ? ( + + + + + setIsShowingAdvanced(!isShowingAdvanced)} + flush="left" + > + + + + {!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? ( + + + + - ); - }) - : null} - - ) : null} -
-
-
- ); -}; + ) : null} + + + {isShowingAdvanced + ? advancedVars.map((varDef) => { + const { name: varName, type: varType } = varDef; + const value = packageConfigInputStream.vars![varName].value; + return ( + + { + updatePackageConfigInputStream({ + vars: { + ...packageConfigInputStream.vars, + [varName]: { + type: varType, + value: newValue, + }, + }, + }); + }} + errors={inputStreamValidationResults.vars![varName]} + forceShowErrors={forceShowErrors} + /> + + ); + }) + : null} + + ) : null} + + + + ); + } +); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_var_field.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_var_field.tsx index 8868e00ecc1f1..eb681096a080e 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_var_field.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_var_field.tsx @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { useState } from 'react'; +import React, { useState, memo, useMemo } from 'react'; import ReactMarkdown from 'react-markdown'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiFormRow, EuiFieldText, EuiComboBox, EuiText, EuiCodeEditor } from '@elastic/eui'; @@ -18,13 +18,13 @@ export const PackageConfigInputVarField: React.FunctionComponent<{ onChange: (newValue: any) => void; errors?: string[] | null; forceShowErrors?: boolean; -}> = ({ varDef, value, onChange, errors: varErrors, forceShowErrors }) => { +}> = memo(({ varDef, value, onChange, errors: varErrors, forceShowErrors }) => { const [isDirty, setIsDirty] = useState(false); const { multi, required, type, title, name, description } = varDef; const isInvalid = (isDirty || forceShowErrors) && !!varErrors; const errors = isInvalid ? varErrors : null; - const renderField = () => { + const field = useMemo(() => { if (multi) { return ( setIsDirty(true)} /> ); - }; + }, [isInvalid, multi, onChange, type, value]); return ( } > - {renderField()} + {field} ); -}; +}); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/index.tsx index b446e6bf97e7b..74cbcdca512db 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/index.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/index.tsx @@ -5,6 +5,7 @@ */ import React, { useState, useEffect, useMemo, useCallback, ReactEventHandler } from 'react'; import { useRouteMatch, useHistory } from 'react-router-dom'; +import styled from 'styled-components'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { @@ -31,6 +32,7 @@ import { useConfig, sendGetAgentStatus, } from '../../../hooks'; +import { Loading } from '../../../components'; import { ConfirmDeployConfigModal } from '../components'; import { CreatePackageConfigPageLayout } from './components'; import { CreatePackageConfigFrom, PackageConfigFormState } from './types'; @@ -45,6 +47,12 @@ import { StepConfigurePackage } from './step_configure_package'; import { StepDefinePackageConfig } from './step_define_package_config'; import { useIntraAppState } from '../../../hooks/use_intra_app_state'; +const StepsWithLessPadding = styled(EuiSteps)` + .euiStep__content { + padding-bottom: ${(props) => props.theme.eui.paddingSizes.m}; + } +`; + export const CreatePackageConfigPage: React.FunctionComponent = () => { const { notifications, @@ -75,6 +83,7 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => { // Agent config and package info states const [agentConfig, setAgentConfig] = useState(); const [packageInfo, setPackageInfo] = useState(); + const [isLoadingSecondStep, setIsLoadingSecondStep] = useState(false); const agentConfigId = agentConfig?.id; // Retrieve agent count @@ -151,40 +160,47 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => { const hasErrors = validationResults ? validationHasErrors(validationResults) : false; + // Update package config validation + const updatePackageConfigValidation = useCallback( + (newPackageConfig?: NewPackageConfig) => { + if (packageInfo) { + const newValidationResult = validatePackageConfig( + newPackageConfig || packageConfig, + packageInfo + ); + setValidationResults(newValidationResult); + // eslint-disable-next-line no-console + console.debug('Package config validation results', newValidationResult); + + return newValidationResult; + } + }, + [packageConfig, packageInfo] + ); + // Update package config method - const updatePackageConfig = (updatedFields: Partial) => { - const newPackageConfig = { - ...packageConfig, - ...updatedFields, - }; - setPackageConfig(newPackageConfig); - - // eslint-disable-next-line no-console - console.debug('Package config updated', newPackageConfig); - const newValidationResults = updatePackageConfigValidation(newPackageConfig); - const hasPackage = newPackageConfig.package; - const hasValidationErrors = newValidationResults - ? validationHasErrors(newValidationResults) - : false; - const hasAgentConfig = newPackageConfig.config_id && newPackageConfig.config_id !== ''; - if (hasPackage && hasAgentConfig && !hasValidationErrors) { - setFormState('VALID'); - } - }; + const updatePackageConfig = useCallback( + (updatedFields: Partial) => { + const newPackageConfig = { + ...packageConfig, + ...updatedFields, + }; + setPackageConfig(newPackageConfig); - const updatePackageConfigValidation = (newPackageConfig?: NewPackageConfig) => { - if (packageInfo) { - const newValidationResult = validatePackageConfig( - newPackageConfig || packageConfig, - packageInfo - ); - setValidationResults(newValidationResult); // eslint-disable-next-line no-console - console.debug('Package config validation results', newValidationResult); - - return newValidationResult; - } - }; + console.debug('Package config updated', newPackageConfig); + const newValidationResults = updatePackageConfigValidation(newPackageConfig); + const hasPackage = newPackageConfig.package; + const hasValidationErrors = newValidationResults + ? validationHasErrors(newValidationResults) + : false; + const hasAgentConfig = newPackageConfig.config_id && newPackageConfig.config_id !== ''; + if (hasPackage && hasAgentConfig && !hasValidationErrors) { + setFormState('VALID'); + } + }, + [packageConfig, updatePackageConfigValidation] + ); // Cancel path const cancelUrl = useMemo(() => { @@ -276,6 +292,7 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => { updatePackageInfo={updatePackageInfo} agentConfig={agentConfig} updateAgentConfig={updateAgentConfig} + setIsLoadingSecondStep={setIsLoadingSecondStep} /> ), [pkgkey, updatePackageInfo, agentConfig, updateAgentConfig] @@ -288,11 +305,47 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => { updateAgentConfig={updateAgentConfig} packageInfo={packageInfo} updatePackageInfo={updatePackageInfo} + setIsLoadingSecondStep={setIsLoadingSecondStep} /> ), [configId, updateAgentConfig, packageInfo, updatePackageInfo] ); + const stepConfigurePackage = useMemo( + () => + isLoadingSecondStep ? ( + + ) : agentConfig && packageInfo ? ( + <> + + + + ) : ( +
+ ), + [ + agentConfig, + formState, + isLoadingSecondStep, + packageConfig, + packageInfo, + updatePackageConfig, + validationResults, + ] + ); + const steps: EuiStepProps[] = [ from === 'package' ? { @@ -310,44 +363,16 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => { }), children: stepSelectPackage, }, - { - title: i18n.translate( - 'xpack.ingestManager.createPackageConfig.stepDefinePackageConfigTitle', - { - defaultMessage: 'Configure integration', - } - ), - status: !packageInfo || !agentConfig ? 'disabled' : undefined, - children: - agentConfig && packageInfo ? ( - - ) : null, - }, { title: i18n.translate( 'xpack.ingestManager.createPackageConfig.stepConfigurePackageConfigTitle', { - defaultMessage: 'Select the data you want to collect', + defaultMessage: 'Configure integration', } ), - status: !packageInfo || !agentConfig ? 'disabled' : undefined, + status: !packageInfo || !agentConfig || isLoadingSecondStep ? 'disabled' : undefined, 'data-test-subj': 'dataCollectionSetupStep', - children: - agentConfig && packageInfo ? ( - - ) : null, + children: stepConfigurePackage, }, ]; @@ -371,7 +396,7 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => { : agentConfig && ( )} - + {/* TODO #64541 - Remove classes */} { : undefined } > - + - {/* eslint-disable-next-line @elastic/eui/href-or-on-click */} - + {!isLoadingSecondStep && agentConfig && packageInfo && formState === 'INVALID' ? ( - + ) : null} - - - + + + {/* eslint-disable-next-line @elastic/eui/href-or-on-click */} + + + + + + + + + + diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.test.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.test.ts new file mode 100644 index 0000000000000..679ae4b1456d6 --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.test.ts @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ +import { hasInvalidButRequiredVar } from './has_invalid_but_required_var'; + +describe('Ingest Manager - hasInvalidButRequiredVar', () => { + it('returns true for invalid & required vars', () => { + expect( + hasInvalidButRequiredVar( + [ + { + name: 'mock_var', + type: 'text', + required: true, + }, + ], + {} + ) + ).toBe(true); + + expect( + hasInvalidButRequiredVar( + [ + { + name: 'mock_var', + type: 'text', + required: true, + }, + ], + { + mock_var: { + value: undefined, + }, + } + ) + ).toBe(true); + }); + + it('returns false for valid & required vars', () => { + expect( + hasInvalidButRequiredVar( + [ + { + name: 'mock_var', + type: 'text', + required: true, + }, + ], + { + mock_var: { + value: 'foo', + }, + } + ) + ).toBe(false); + }); + + it('returns false for optional vars', () => { + expect( + hasInvalidButRequiredVar( + [ + { + name: 'mock_var', + type: 'text', + }, + ], + { + mock_var: { + value: 'foo', + }, + } + ) + ).toBe(false); + + expect( + hasInvalidButRequiredVar( + [ + { + name: 'mock_var', + type: 'text', + required: false, + }, + ], + { + mock_var: { + value: undefined, + }, + } + ) + ).toBe(false); + }); +}); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.ts new file mode 100644 index 0000000000000..f632d40a05621 --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.ts @@ -0,0 +1,26 @@ +/* + * 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 { PackageConfigConfigRecord, RegistryVarsEntry } from '../../../../types'; +import { validatePackageConfigConfig } from './'; + +export const hasInvalidButRequiredVar = ( + registryVars?: RegistryVarsEntry[], + packageConfigVars?: PackageConfigConfigRecord +): boolean => { + return ( + (registryVars && !packageConfigVars) || + Boolean( + registryVars && + registryVars.find( + (registryVar) => + registryVar.required && + (!packageConfigVars || + !packageConfigVars[registryVar.name] || + validatePackageConfigConfig(packageConfigVars[registryVar.name], registryVar)?.length) + ) + ) + ); +}; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/index.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/index.ts index 6cfb1c74bd661..0d33a4e113f03 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/index.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/index.ts @@ -4,10 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ export { isAdvancedVar } from './is_advanced_var'; +export { hasInvalidButRequiredVar } from './has_invalid_but_required_var'; export { PackageConfigValidationResults, PackageConfigConfigValidationResults, PackageConfigInputValidationResults, validatePackageConfig, + validatePackageConfigConfig, validationHasErrors, + countValidationErrors, } from './validate_package_config'; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/is_advanced_var.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/is_advanced_var.ts index 398f1d675c5df..a2f4a6675ac80 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/is_advanced_var.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/is_advanced_var.ts @@ -6,7 +6,7 @@ import { RegistryVarsEntry } from '../../../../types'; export const isAdvancedVar = (varDef: RegistryVarsEntry): boolean => { - if (varDef.show_user || (varDef.required && !varDef.default)) { + if (varDef.show_user || (varDef.required && varDef.default === undefined)) { return false; } return true; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/validate_package_config.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/validate_package_config.ts index cd301747c3f53..bd9d216ca969a 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/validate_package_config.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/validate_package_config.ts @@ -171,7 +171,7 @@ export const validatePackageConfig = ( return validationResults; }; -const validatePackageConfigConfig = ( +export const validatePackageConfigConfig = ( configEntry: PackageConfigConfigRecordEntry, varDef: RegistryVarsEntry ): string[] | null => { @@ -237,13 +237,22 @@ const validatePackageConfigConfig = ( return errors.length ? errors : null; }; -export const validationHasErrors = ( +export const countValidationErrors = ( validationResults: | PackageConfigValidationResults | PackageConfigInputValidationResults | PackageConfigConfigValidationResults -) => { +): number => { const flattenedValidation = getFlattenedObject(validationResults); + const errors = Object.values(flattenedValidation).filter((value) => Boolean(value)) || []; + return errors.length; +}; - return !!Object.entries(flattenedValidation).find(([, value]) => !!value); +export const validationHasErrors = ( + validationResults: + | PackageConfigValidationResults + | PackageConfigInputValidationResults + | PackageConfigConfigValidationResults +): boolean => { + return countValidationErrors(validationResults) > 0; }; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_configure_package.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_configure_package.tsx index eecd204a5e307..380a03e15695b 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_configure_package.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_configure_package.tsx @@ -4,12 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ import React from 'react'; -import { FormattedMessage } from '@kbn/i18n/react'; -import { EuiPanel, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiCallOut } from '@elastic/eui'; -import { i18n } from '@kbn/i18n'; +import { EuiHorizontalRule, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { PackageInfo, RegistryStream, NewPackageConfig, PackageConfigInput } from '../../../types'; import { Loading } from '../../../components'; -import { PackageConfigValidationResults, validationHasErrors } from './services'; +import { PackageConfigValidationResults } from './services'; import { PackageConfigInputPanel, CustomPackageConfig } from './components'; import { CreatePackageConfigFrom } from './types'; @@ -52,8 +50,6 @@ export const StepConfigurePackage: React.FunctionComponent<{ validationResults, submitAttempted, }) => { - const hasErrors = validationResults ? validationHasErrors(validationResults) : false; - // Configure inputs (and their streams) // Assume packages only export one config template for now const renderConfigureInputs = () => @@ -61,76 +57,50 @@ export const StepConfigurePackage: React.FunctionComponent<{ packageInfo.config_templates[0] && packageInfo.config_templates[0].inputs && packageInfo.config_templates[0].inputs.length ? ( - - {packageInfo.config_templates[0].inputs.map((packageInput) => { - const packageConfigInput = packageConfig.inputs.find( - (input) => input.type === packageInput.type - ); - const packageInputStreams = findStreamsForInputType(packageInput.type, packageInfo); - return packageConfigInput ? ( - - ) => { - const indexOfUpdatedInput = packageConfig.inputs.findIndex( - (input) => input.type === packageInput.type - ); - const newInputs = [...packageConfig.inputs]; - newInputs[indexOfUpdatedInput] = { - ...newInputs[indexOfUpdatedInput], - ...updatedInput, - }; - updatePackageConfig({ - inputs: newInputs, - }); - }} - inputValidationResults={validationResults!.inputs![packageConfigInput.type]} - forceShowErrors={submitAttempted} - /> - - ) : null; - })} - + <> + + + {packageInfo.config_templates[0].inputs.map((packageInput) => { + const packageConfigInput = packageConfig.inputs.find( + (input) => input.type === packageInput.type + ); + const packageInputStreams = findStreamsForInputType(packageInput.type, packageInfo); + return packageConfigInput ? ( + + ) => { + const indexOfUpdatedInput = packageConfig.inputs.findIndex( + (input) => input.type === packageInput.type + ); + const newInputs = [...packageConfig.inputs]; + newInputs[indexOfUpdatedInput] = { + ...newInputs[indexOfUpdatedInput], + ...updatedInput, + }; + updatePackageConfig({ + inputs: newInputs, + }); + }} + inputValidationResults={validationResults!.inputs![packageConfigInput.type]} + forceShowErrors={submitAttempted} + /> + + + ) : null; + })} + + ) : ( - - - + ); - return validationResults ? ( - - {renderConfigureInputs()} - {hasErrors && submitAttempted ? ( - - - -

- -

-
- -
- ) : null} -
- ) : ( - - ); + return validationResults ? renderConfigureInputs() : ; }; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_define_package_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_define_package_config.tsx index b2ffe62104eb1..a04d023ebcc48 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_define_package_config.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_define_package_config.tsx @@ -3,17 +3,18 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { useEffect, useState, Fragment } from 'react'; +import React, { useEffect, useState } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { - EuiFlexGrid, - EuiFlexItem, EuiFormRow, EuiFieldText, EuiButtonEmpty, EuiSpacer, EuiText, EuiComboBox, + EuiDescribedFormGroup, + EuiFlexGroup, + EuiFlexItem, } from '@elastic/eui'; import { AgentConfig, PackageInfo, PackageConfig, NewPackageConfig } from '../../../types'; import { packageToPackageConfigInputs } from '../../../services'; @@ -28,7 +29,7 @@ export const StepDefinePackageConfig: React.FunctionComponent<{ validationResults: PackageConfigValidationResults; }> = ({ agentConfig, packageInfo, packageConfig, updatePackageConfig, validationResults }) => { // Form show/hide states - const [isShowingAdvancedDefine, setIsShowingAdvancedDefine] = useState(false); + const [isShowingAdvanced, setIsShowingAdvanced] = useState(false); // Update package config's package and config info useEffect(() => { @@ -74,111 +75,140 @@ export const StepDefinePackageConfig: React.FunctionComponent<{ ]); return validationResults ? ( - <> - - - + + + + } + description={ + + } + > + <> + {/* Name */} + + } + > + + updatePackageConfig({ + name: e.target.value, + }) } - > - - updatePackageConfig({ - name: e.target.value, - }) - } - data-test-subj="packageConfigNameInput" + data-test-subj="packageConfigNameInput" + /> + + + {/* Description */} + - - - - + + } + isInvalid={!!validationResults.description} + error={validationResults.description} + > + + updatePackageConfig({ + description: e.target.value, + }) } - labelAppend={ - + /> + + + + {/* Advanced options toggle */} + + + setIsShowingAdvanced(!isShowingAdvanced)} + flush="left" + > + + + + {!isShowingAdvanced && !!validationResults.namespace ? ( + + - } - isInvalid={!!validationResults.description} - error={validationResults.description} - > - - updatePackageConfig({ - description: e.target.value, - }) + + ) : null} + + + {/* Advanced options content */} + {/* Todo: Populate list of existing namespaces */} + {isShowingAdvanced ? ( + <> + + } - /> - - - - - setIsShowingAdvancedDefine(!isShowingAdvancedDefine)} - > - - - {/* Todo: Populate list of existing namespaces */} - {isShowingAdvancedDefine || !!validationResults.namespace ? ( - - - - - + > + - { - updatePackageConfig({ - namespace: newNamespace, - }); - }} - onChange={(newNamespaces: Array<{ label: string }>) => { - updatePackageConfig({ - namespace: newNamespaces.length ? newNamespaces[0].label : '', - }); - }} - /> - - - - - ) : null} - + onCreateOption={(newNamespace: string) => { + updatePackageConfig({ + namespace: newNamespace, + }); + }} + onChange={(newNamespaces: Array<{ label: string }>) => { + updatePackageConfig({ + namespace: newNamespaces.length ? newNamespaces[0].label : '', + }); + }} + /> + + + ) : null} + + ) : ( ); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_config.tsx index f6391cf1fa456..d3120f9051f45 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_config.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_config.tsx @@ -6,29 +6,50 @@ import React, { useEffect, useState, Fragment } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { EuiFlexGroup, EuiFlexItem, EuiSelectable, EuiSpacer, EuiTextColor } from '@elastic/eui'; +import { + EuiFlexGroup, + EuiFlexItem, + EuiSelectable, + EuiSpacer, + EuiTextColor, + EuiPortal, + EuiButtonEmpty, +} from '@elastic/eui'; import { Error } from '../../../components'; import { AgentConfig, PackageInfo, GetAgentConfigsResponseItem } from '../../../types'; import { isPackageLimited, doesAgentConfigAlreadyIncludePackage } from '../../../services'; -import { useGetPackageInfoByKey, useGetAgentConfigs, sendGetOneAgentConfig } from '../../../hooks'; +import { + useGetPackageInfoByKey, + useGetAgentConfigs, + sendGetOneAgentConfig, + useCapabilities, +} from '../../../hooks'; +import { CreateAgentConfigFlyout } from '../list_page/components'; export const StepSelectConfig: React.FunctionComponent<{ pkgkey: string; updatePackageInfo: (packageInfo: PackageInfo | undefined) => void; agentConfig: AgentConfig | undefined; updateAgentConfig: (config: AgentConfig | undefined) => void; -}> = ({ pkgkey, updatePackageInfo, agentConfig, updateAgentConfig }) => { + setIsLoadingSecondStep: (isLoading: boolean) => void; +}> = ({ pkgkey, updatePackageInfo, agentConfig, updateAgentConfig, setIsLoadingSecondStep }) => { // Selected config state const [selectedConfigId, setSelectedConfigId] = useState( agentConfig ? agentConfig.id : undefined ); const [selectedConfigError, setSelectedConfigError] = useState(); + // Create new config flyout state + const hasWriteCapabilites = useCapabilities().write; + const [isCreateAgentConfigFlyoutOpen, setIsCreateAgentConfigFlyoutOpen] = useState( + false + ); + // Fetch package info const { data: packageInfoData, error: packageInfoError, - isLoading: packageInfoLoading, + isLoading: isPackageInfoLoading, } = useGetPackageInfoByKey(pkgkey); const isLimitedPackage = (packageInfoData && isPackageLimited(packageInfoData.response)) || false; @@ -37,6 +58,7 @@ export const StepSelectConfig: React.FunctionComponent<{ data: agentConfigsData, error: agentConfigsError, isLoading: isAgentConfigsLoading, + sendRequest: refreshAgentConfigs, } = useGetAgentConfigs({ page: 1, perPage: 1000, @@ -64,6 +86,7 @@ export const StepSelectConfig: React.FunctionComponent<{ useEffect(() => { const fetchAgentConfigInfo = async () => { if (selectedConfigId) { + setIsLoadingSecondStep(true); const { data, error } = await sendGetOneAgentConfig(selectedConfigId); if (error) { setSelectedConfigError(error); @@ -76,11 +99,12 @@ export const StepSelectConfig: React.FunctionComponent<{ setSelectedConfigError(undefined); updateAgentConfig(undefined); } + setIsLoadingSecondStep(false); }; if (!agentConfig || selectedConfigId !== agentConfig.id) { fetchAgentConfigInfo(); } - }, [selectedConfigId, agentConfig, updateAgentConfig]); + }, [selectedConfigId, agentConfig, updateAgentConfig, setIsLoadingSecondStep]); // Display package error if there is one if (packageInfoError) { @@ -113,92 +137,125 @@ export const StepSelectConfig: React.FunctionComponent<{ } return ( - - - { - const alreadyHasLimitedPackage = - (isLimitedPackage && - packageInfoData && - doesAgentConfigAlreadyIncludePackage(agentConf, packageInfoData.response.name)) || - false; - return { - label: agentConf.name, - key: agentConf.id, - checked: selectedConfigId === agentConf.id ? 'on' : undefined, - disabled: alreadyHasLimitedPackage, - 'data-test-subj': 'agentConfigItem', - }; - })} - renderOption={(option) => ( - - {option.label} - - - {agentConfigsById[option.key!].description} - - - - - - - - - )} - listProps={{ - bordered: true, - }} - searchProps={{ - placeholder: i18n.translate( - 'xpack.ingestManager.createPackageConfig.StepSelectConfig.filterAgentConfigsInputPlaceholder', - { - defaultMessage: 'Search for agent configurations', + <> + {isCreateAgentConfigFlyoutOpen ? ( + + { + setIsCreateAgentConfigFlyoutOpen(false); + if (newAgentConfig) { + refreshAgentConfigs(); + setSelectedConfigId(newAgentConfig.id); + } + }} + /> + + ) : null} + + + { + const alreadyHasLimitedPackage = + (isLimitedPackage && + packageInfoData && + doesAgentConfigAlreadyIncludePackage(agentConf, packageInfoData.response.name)) || + false; + return { + label: agentConf.name, + key: agentConf.id, + checked: selectedConfigId === agentConf.id ? 'on' : undefined, + disabled: alreadyHasLimitedPackage, + 'data-test-subj': 'agentConfigItem', + }; + })} + renderOption={(option) => ( + + {option.label} + + + {agentConfigsById[option.key!].description} + + + + + + + + + )} + listProps={{ + bordered: true, + }} + searchProps={{ + placeholder: i18n.translate( + 'xpack.ingestManager.createPackageConfig.StepSelectConfig.filterAgentConfigsInputPlaceholder', + { + defaultMessage: 'Search for agent configurations', + } + ), + }} + height={180} + onChange={(options) => { + const selectedOption = options.find((option) => option.checked === 'on'); + if (selectedOption) { + if (selectedOption.key !== selectedConfigId) { + setSelectedConfigId(selectedOption.key); + } + } else { + setSelectedConfigId(undefined); + } + }} + > + {(list, search) => ( + + {search} + + {list} + + )} + + + {/* Display selected agent config error if there is one */} + {selectedConfigError ? ( + + } - ), - }} - height={240} - onChange={(options) => { - const selectedOption = options.find((option) => option.checked === 'on'); - if (selectedOption) { - setSelectedConfigId(selectedOption.key); - } else { - setSelectedConfigId(undefined); - } - }} - > - {(list, search) => ( - - {search} - - {list} - - )} - - - {/* Display selected agent config error if there is one */} - {selectedConfigError ? ( + error={selectedConfigError} + /> + + ) : null} - + setIsCreateAgentConfigFlyoutOpen(true)} + flush="left" + size="s" + > - } - error={selectedConfigError} - /> + +
- ) : null} - + + ); }; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_package.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_package.tsx index 204b862bd4dc4..048ae101fcd6f 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_package.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_package.tsx @@ -22,7 +22,14 @@ export const StepSelectPackage: React.FunctionComponent<{ updateAgentConfig: (config: AgentConfig | undefined) => void; packageInfo?: PackageInfo; updatePackageInfo: (packageInfo: PackageInfo | undefined) => void; -}> = ({ agentConfigId, updateAgentConfig, packageInfo, updatePackageInfo }) => { + setIsLoadingSecondStep: (isLoading: boolean) => void; +}> = ({ + agentConfigId, + updateAgentConfig, + packageInfo, + updatePackageInfo, + setIsLoadingSecondStep, +}) => { // Selected package state const [selectedPkgKey, setSelectedPkgKey] = useState( packageInfo ? `${packageInfo.name}-${packageInfo.version}` : undefined @@ -30,7 +37,11 @@ export const StepSelectPackage: React.FunctionComponent<{ const [selectedPkgError, setSelectedPkgError] = useState(); // Fetch agent config info - const { data: agentConfigData, error: agentConfigError } = useGetOneAgentConfig(agentConfigId); + const { + data: agentConfigData, + error: agentConfigError, + isLoading: isAgentConfigsLoading, + } = useGetOneAgentConfig(agentConfigId); // Fetch packages info // Filter out limited packages already part of selected agent config @@ -66,6 +77,7 @@ export const StepSelectPackage: React.FunctionComponent<{ useEffect(() => { const fetchPackageInfo = async () => { if (selectedPkgKey) { + setIsLoadingSecondStep(true); const { data, error } = await sendGetPackageInfoByKey(selectedPkgKey); if (error) { setSelectedPkgError(error); @@ -74,6 +86,7 @@ export const StepSelectPackage: React.FunctionComponent<{ setSelectedPkgError(undefined); updatePackageInfo(data.response); } + setIsLoadingSecondStep(false); } else { setSelectedPkgError(undefined); updatePackageInfo(undefined); @@ -82,7 +95,7 @@ export const StepSelectPackage: React.FunctionComponent<{ if (!packageInfo || selectedPkgKey !== `${packageInfo.name}-${packageInfo.version}`) { fetchPackageInfo(); } - }, [selectedPkgKey, packageInfo, updatePackageInfo]); + }, [selectedPkgKey, packageInfo, updatePackageInfo, setIsLoadingSecondStep]); // Display agent config error if there is one if (agentConfigError) { @@ -121,7 +134,7 @@ export const StepSelectPackage: React.FunctionComponent<{ searchable allowExclusions={false} singleSelection={true} - isLoading={isPackagesLoading || isLimitedPackagesLoading} + isLoading={isPackagesLoading || isLimitedPackagesLoading || isAgentConfigsLoading} options={packages.map(({ title, name, version, icons }) => { const pkgkey = `${name}-${version}`; return { @@ -154,7 +167,9 @@ export const StepSelectPackage: React.FunctionComponent<{ onChange={(options) => { const selectedOption = options.find((option) => option.checked === 'on'); if (selectedOption) { - setSelectedPkgKey(selectedOption.key); + if (selectedOption.key !== selectedPkgKey) { + setSelectedPkgKey(selectedOption.key); + } } else { setSelectedPkgKey(undefined); } diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/edit_package_config_page/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/edit_package_config_page/index.tsx index 52fd95d663671..f4411a6057a15 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/edit_package_config_page/index.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/edit_package_config_page/index.tsx @@ -3,14 +3,13 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useCallback, useMemo } from 'react'; import { useRouteMatch, useHistory } from 'react-router-dom'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButtonEmpty, EuiButton, - EuiSteps, EuiBottomBar, EuiFlexGroup, EuiFlexItem, @@ -160,38 +159,45 @@ export const EditPackageConfigPage: React.FunctionComponent = () => { const [validationResults, setValidationResults] = useState(); const hasErrors = validationResults ? validationHasErrors(validationResults) : false; - // Update package config method - const updatePackageConfig = (updatedFields: Partial) => { - const newPackageConfig = { - ...packageConfig, - ...updatedFields, - }; - setPackageConfig(newPackageConfig); + // Update package config validation + const updatePackageConfigValidation = useCallback( + (newPackageConfig?: UpdatePackageConfig) => { + if (packageInfo) { + const newValidationResult = validatePackageConfig( + newPackageConfig || packageConfig, + packageInfo + ); + setValidationResults(newValidationResult); + // eslint-disable-next-line no-console + console.debug('Package config validation results', newValidationResult); - // eslint-disable-next-line no-console - console.debug('Package config updated', newPackageConfig); - const newValidationResults = updatePackageConfigValidation(newPackageConfig); - const hasValidationErrors = newValidationResults - ? validationHasErrors(newValidationResults) - : false; - if (!hasValidationErrors) { - setFormState('VALID'); - } - }; + return newValidationResult; + } + }, + [packageConfig, packageInfo] + ); - const updatePackageConfigValidation = (newPackageConfig?: UpdatePackageConfig) => { - if (packageInfo) { - const newValidationResult = validatePackageConfig( - newPackageConfig || packageConfig, - packageInfo - ); - setValidationResults(newValidationResult); - // eslint-disable-next-line no-console - console.debug('Package config validation results', newValidationResult); + // Update package config method + const updatePackageConfig = useCallback( + (updatedFields: Partial) => { + const newPackageConfig = { + ...packageConfig, + ...updatedFields, + }; + setPackageConfig(newPackageConfig); - return newValidationResult; - } - }; + // eslint-disable-next-line no-console + console.debug('Package config updated', newPackageConfig); + const newValidationResults = updatePackageConfigValidation(newPackageConfig); + const hasValidationErrors = newValidationResults + ? validationHasErrors(newValidationResults) + : false; + if (!hasValidationErrors) { + setFormState('VALID'); + } + }, + [packageConfig, updatePackageConfigValidation] + ); // Cancel url const cancelUrl = getHref('configuration_details', { configId }); @@ -271,6 +277,40 @@ export const EditPackageConfigPage: React.FunctionComponent = () => { packageInfo, }; + const configurePackage = useMemo( + () => + agentConfig && packageInfo ? ( + <> + + + + + ) : null, + [ + agentConfig, + formState, + packageConfig, + packageConfigId, + packageInfo, + updatePackageConfig, + validationResults, + ] + ); + return ( {isLoadingData ? ( @@ -301,46 +341,7 @@ export const EditPackageConfigPage: React.FunctionComponent = () => { onCancel={() => setFormState('VALID')} /> )} - - ), - }, - { - title: i18n.translate( - 'xpack.ingestManager.editPackageConfig.stepConfigurePackageConfigTitle', - { - defaultMessage: 'Select the data you want to collect', - } - ), - children: ( - - ), - }, - ]} - /> + {configurePackage} {/* TODO #64541 - Remove classes */} { : undefined } > - + - + {agentConfig && packageInfo && formState === 'INVALID' ? ( - + ) : null} - - - + + + + + + + + + + + + diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx index d1abd88adba86..795c46ec282c5 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx @@ -18,12 +18,12 @@ import { EuiButton, EuiText, } from '@elastic/eui'; -import { NewAgentConfig } from '../../../../types'; +import { NewAgentConfig, AgentConfig } from '../../../../types'; import { useCapabilities, useCore, sendCreateAgentConfig } from '../../../../hooks'; import { AgentConfigForm, agentConfigFormValidation } from '../../components'; interface Props { - onClose: () => void; + onClose: (createdAgentConfig?: AgentConfig) => void; } export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClose }) => { @@ -86,7 +86,7 @@ export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClos - + onClose()} flush="left"> = ({ onClos } ) ); - onClose(); + onClose(data.item); } else { notifications.toasts.addDanger( error diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts index 170a9cedc08d9..dc27da18bc008 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts @@ -18,6 +18,7 @@ export { UpdatePackageConfig, PackageConfigInput, PackageConfigInputStream, + PackageConfigConfigRecord, PackageConfigConfigRecordEntry, Output, DataStream, diff --git a/x-pack/plugins/ingest_manager/server/services/package_config.ts b/x-pack/plugins/ingest_manager/server/services/package_config.ts index 9433a81e74b07..e8ca09a83c2b6 100644 --- a/x-pack/plugins/ingest_manager/server/services/package_config.ts +++ b/x-pack/plugins/ingest_manager/server/services/package_config.ts @@ -44,6 +44,20 @@ class PackageConfigService { packageConfig: NewPackageConfig, options?: { id?: string; user?: AuthenticatedUser } ): Promise { + // Check that its agent config does not have a package config with the same name + const parentAgentConfig = await agentConfigService.get(soClient, packageConfig.config_id); + if (!parentAgentConfig) { + throw new Error('Agent config not found'); + } else { + if ( + (parentAgentConfig.package_configs as PackageConfig[]).find( + (siblingPackageConfig) => siblingPackageConfig.name === packageConfig.name + ) + ) { + throw new Error('There is already a package with the same name on this agent config'); + } + } + // Make sure the associated package is installed if (packageConfig.package?.name) { const [, pkgInfo] = await Promise.all([ @@ -225,6 +239,21 @@ class PackageConfigService { throw new Error('Package config not found'); } + // Check that its agent config does not have a package config with the same name + const parentAgentConfig = await agentConfigService.get(soClient, packageConfig.config_id); + if (!parentAgentConfig) { + throw new Error('Agent config not found'); + } else { + if ( + (parentAgentConfig.package_configs as PackageConfig[]).find( + (siblingPackageConfig) => + siblingPackageConfig.id !== id && siblingPackageConfig.name === packageConfig.name + ) + ) { + throw new Error('There is already a package with the same name on this agent config'); + } + } + await soClient.update( SAVED_OBJECT_TYPE, id, diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 4118053396e90..97afa9e058b98 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -8173,7 +8173,6 @@ "xpack.ingestManager.createPackageConfig.agentConfigurationNameLabel": "構成", "xpack.ingestManager.createPackageConfig.cancelButton": "キャンセル", "xpack.ingestManager.createPackageConfig.cancelLinkText": "キャンセル", - "xpack.ingestManager.createPackageConfig.packageNameLabel": "統合", "xpack.ingestManager.createPackageConfig.pageDescriptionfromConfig": "次の手順に従い、統合をこのエージェント構成に追加します。", "xpack.ingestManager.createPackageConfig.pageDescriptionfromPackage": "次の手順に従い、この統合をエージェント構成に追加します。", "xpack.ingestManager.createPackageConfig.pageTitle": "データソースを追加", @@ -8184,19 +8183,12 @@ "xpack.ingestManager.createPackageConfig.stepConfigure.packageConfigNameInputLabel": "データソース名", "xpack.ingestManager.createPackageConfig.stepConfigure.packageConfigNamespaceInputLabel": "名前空間", "xpack.ingestManager.createPackageConfig.stepConfigure.hideStreamsAriaLabel": "{type} ストリームを隠す", - "xpack.ingestManager.createPackageConfig.stepConfigure.inputConfigErrorsTooltip": "構成エラーを修正してください", - "xpack.ingestManager.createPackageConfig.stepConfigure.inputLevelErrorsTooltip": "構成エラーを修正してください", "xpack.ingestManager.createPackageConfig.stepConfigure.inputSettingsDescription": "次の設定はすべてのストリームに適用されます。", "xpack.ingestManager.createPackageConfig.stepConfigure.inputSettingsTitle": "設定", "xpack.ingestManager.createPackageConfig.stepConfigure.inputVarFieldOptionalLabel": "オプション", "xpack.ingestManager.createPackageConfig.stepConfigure.noConfigOptionsMessage": "構成するものがありません", "xpack.ingestManager.createPackageConfig.stepConfigure.showStreamsAriaLabel": "{type} ストリームを表示", - "xpack.ingestManager.createPackageConfig.stepConfigure.streamLevelErrorsTooltip": "構成エラーを修正してください", - "xpack.ingestManager.createPackageConfig.stepConfigure.streamsEnabledCountText": "{count} / {total, plural, one {# ストリーム} other {# ストリーム}}が有効です", "xpack.ingestManager.createPackageConfig.stepConfigure.toggleAdvancedOptionsButtonText": "高度なオプション", - "xpack.ingestManager.createPackageConfig.stepConfigure.validationErrorText": "続行する前に、上記のエラーを修正してください", - "xpack.ingestManager.createPackageConfig.stepConfigure.validationErrorTitle": "データソース構成にエラーがあります", - "xpack.ingestManager.createPackageConfig.stepDefinePackageConfigTitle": "データソースを定義", "xpack.ingestManager.createPackageConfig.stepSelectAgentConfigTitle": "エージェント構成を選択する", "xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigAgentsCountText": "{count, plural, one {# エージェント} other {# エージェント}}", "xpack.ingestManager.createPackageConfig.StepSelectConfig.errorLoadingAgentConfigsTitle": "エージェント構成の読み込みエラー", @@ -8268,8 +8260,6 @@ "xpack.ingestManager.editPackageConfig.pageDescription": "次の手順に従い、このデータソースを編集します。", "xpack.ingestManager.editPackageConfig.pageTitle": "データソースを編集", "xpack.ingestManager.editPackageConfig.saveButton": "データソースを保存", - "xpack.ingestManager.editPackageConfig.stepConfigurePackageConfigTitle": "収集するデータを選択", - "xpack.ingestManager.editPackageConfig.stepDefinePackageConfigTitle": "データソースを定義", "xpack.ingestManager.editPackageConfig.updatedNotificationMessage": "フリートは'{agentConfigName}'構成で使用されているすべてのエージェントに更新をデプロイします。", "xpack.ingestManager.editPackageConfig.updatedNotificationTitle": "正常に'{packageConfigName}'を更新しました", "xpack.ingestManager.enrollemntAPIKeyList.emptyMessage": "登録トークンが見つかりません。", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 01939bea417d4..31a33bfa09b64 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -8178,7 +8178,6 @@ "xpack.ingestManager.createPackageConfig.agentConfigurationNameLabel": "配置", "xpack.ingestManager.createPackageConfig.cancelButton": "取消", "xpack.ingestManager.createPackageConfig.cancelLinkText": "取消", - "xpack.ingestManager.createPackageConfig.packageNameLabel": "集成", "xpack.ingestManager.createPackageConfig.pageDescriptionfromConfig": "按照下面的说明将集成添加此代理配置。", "xpack.ingestManager.createPackageConfig.pageDescriptionfromPackage": "按照下面的说明将此集成添加代理配置。", "xpack.ingestManager.createPackageConfig.pageTitle": "添加数据源", @@ -8189,19 +8188,12 @@ "xpack.ingestManager.createPackageConfig.stepConfigure.packageConfigNameInputLabel": "数据源名称", "xpack.ingestManager.createPackageConfig.stepConfigure.packageConfigNamespaceInputLabel": "命名空间", "xpack.ingestManager.createPackageConfig.stepConfigure.hideStreamsAriaLabel": "隐藏 {type} 流", - "xpack.ingestManager.createPackageConfig.stepConfigure.inputConfigErrorsTooltip": "解决配置错误", - "xpack.ingestManager.createPackageConfig.stepConfigure.inputLevelErrorsTooltip": "解决配置错误", "xpack.ingestManager.createPackageConfig.stepConfigure.inputSettingsDescription": "以下设置适用于所有流。", "xpack.ingestManager.createPackageConfig.stepConfigure.inputSettingsTitle": "设置", "xpack.ingestManager.createPackageConfig.stepConfigure.inputVarFieldOptionalLabel": "可选", "xpack.ingestManager.createPackageConfig.stepConfigure.noConfigOptionsMessage": "没有可配置的内容", "xpack.ingestManager.createPackageConfig.stepConfigure.showStreamsAriaLabel": "显示 {type} 流", - "xpack.ingestManager.createPackageConfig.stepConfigure.streamLevelErrorsTooltip": "解决配置错误", - "xpack.ingestManager.createPackageConfig.stepConfigure.streamsEnabledCountText": "{count} / {total, plural, one {# 个流} other {# 个流}}已启用", "xpack.ingestManager.createPackageConfig.stepConfigure.toggleAdvancedOptionsButtonText": "高级选项", - "xpack.ingestManager.createPackageConfig.stepConfigure.validationErrorText": "在继续之前请解决上述错误", - "xpack.ingestManager.createPackageConfig.stepConfigure.validationErrorTitle": "您的数据源配置有错误", - "xpack.ingestManager.createPackageConfig.stepDefinePackageConfigTitle": "定义您的数据源", "xpack.ingestManager.createPackageConfig.stepSelectAgentConfigTitle": "选择代理配置", "xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigAgentsCountText": "{count, plural, one {# 个代理} other {# 个代理}}", "xpack.ingestManager.createPackageConfig.StepSelectConfig.errorLoadingAgentConfigsTitle": "加载代理配置时出错", @@ -8273,8 +8265,6 @@ "xpack.ingestManager.editPackageConfig.pageDescription": "按照下面的说明编辑此数据源。", "xpack.ingestManager.editPackageConfig.pageTitle": "编辑数据源", "xpack.ingestManager.editPackageConfig.saveButton": "保存数据源", - "xpack.ingestManager.editPackageConfig.stepConfigurePackageConfigTitle": "选择要收集的数据", - "xpack.ingestManager.editPackageConfig.stepDefinePackageConfigTitle": "定义您的数据源", "xpack.ingestManager.editPackageConfig.updatedNotificationMessage": "Fleet 会将更新部署到所有使用配置“{agentConfigName}”的代理", "xpack.ingestManager.editPackageConfig.updatedNotificationTitle": "已成功更新“{packageConfigName}”", "xpack.ingestManager.enrollemntAPIKeyList.emptyMessage": "未找到任何注册令牌。", diff --git a/x-pack/test/ingest_manager_api_integration/apis/index.js b/x-pack/test/ingest_manager_api_integration/apis/index.js index 30c49140c6e2a..81848917f9b05 100644 --- a/x-pack/test/ingest_manager_api_integration/apis/index.js +++ b/x-pack/test/ingest_manager_api_integration/apis/index.js @@ -17,5 +17,6 @@ export default function ({ loadTestFile }) { // Package configs loadTestFile(require.resolve('./package_config/create')); + loadTestFile(require.resolve('./package_config/update')); }); } diff --git a/x-pack/test/ingest_manager_api_integration/apis/package_config/create.ts b/x-pack/test/ingest_manager_api_integration/apis/package_config/create.ts index c7748ab255f43..cae4ff79bdef6 100644 --- a/x-pack/test/ingest_manager_api_integration/apis/package_config/create.ts +++ b/x-pack/test/ingest_manager_api_integration/apis/package_config/create.ts @@ -126,5 +126,48 @@ export default function ({ getService }: FtrProviderContext) { warnAndSkipTest(this, log); } }); + + it('should return a 500 if there is another package config with the same name', async function () { + if (server.enabled) { + await supertest + .post(`/api/ingest_manager/package_configs`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'same-name-test-1', + description: '', + namespace: 'default', + config_id: agentConfigId, + enabled: true, + output_id: '', + inputs: [], + package: { + name: 'filetest', + title: 'For File Tests', + version: '0.1.0', + }, + }) + .expect(200); + await supertest + .post(`/api/ingest_manager/package_configs`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'same-name-test-1', + description: '', + namespace: 'default', + config_id: agentConfigId, + enabled: true, + output_id: '', + inputs: [], + package: { + name: 'filetest', + title: 'For File Tests', + version: '0.1.0', + }, + }) + .expect(500); + } else { + warnAndSkipTest(this, log); + } + }); }); } diff --git a/x-pack/test/ingest_manager_api_integration/apis/package_config/update.ts b/x-pack/test/ingest_manager_api_integration/apis/package_config/update.ts new file mode 100644 index 0000000000000..0251fef5f767c --- /dev/null +++ b/x-pack/test/ingest_manager_api_integration/apis/package_config/update.ts @@ -0,0 +1,127 @@ +/* + * 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 expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; +import { warnAndSkipTest } from '../../helpers'; + +export default function ({ getService }: FtrProviderContext) { + const log = getService('log'); + const supertest = getService('supertest'); + const dockerServers = getService('dockerServers'); + + const server = dockerServers.get('registry'); + // use function () {} and not () => {} here + // because `this` has to point to the Mocha context + // see https://mochajs.org/#arrow-functions + + describe('Package Config - update', async function () { + let agentConfigId: string; + let packageConfigId: string; + let packageConfigId2: string; + + before(async function () { + const { body: agentConfigResponse } = await supertest + .post(`/api/ingest_manager/agent_configs`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'Test config', + namespace: 'default', + }); + agentConfigId = agentConfigResponse.item.id; + + const { body: packageConfigResponse } = await supertest + .post(`/api/ingest_manager/package_configs`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'filetest-1', + description: '', + namespace: 'default', + config_id: agentConfigId, + enabled: true, + output_id: '', + inputs: [], + package: { + name: 'filetest', + title: 'For File Tests', + version: '0.1.0', + }, + }); + packageConfigId = packageConfigResponse.item.id; + + const { body: packageConfigResponse2 } = await supertest + .post(`/api/ingest_manager/package_configs`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'filetest-2', + description: '', + namespace: 'default', + config_id: agentConfigId, + enabled: true, + output_id: '', + inputs: [], + package: { + name: 'filetest', + title: 'For File Tests', + version: '0.1.0', + }, + }); + packageConfigId2 = packageConfigResponse2.item.id; + }); + + it('should work with valid values', async function () { + if (server.enabled) { + const { body: apiResponse } = await supertest + .put(`/api/ingest_manager/package_configs/${packageConfigId}`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'filetest-1', + description: '', + namespace: 'updated_namespace', + config_id: agentConfigId, + enabled: true, + output_id: '', + inputs: [], + package: { + name: 'filetest', + title: 'For File Tests', + version: '0.1.0', + }, + }) + .expect(200); + + expect(apiResponse.success).to.be(true); + } else { + warnAndSkipTest(this, log); + } + }); + + it('should return a 500 if there is another package config with the same name', async function () { + if (server.enabled) { + await supertest + .put(`/api/ingest_manager/package_configs/${packageConfigId2}`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'filetest-1', + description: '', + namespace: 'updated_namespace', + config_id: agentConfigId, + enabled: true, + output_id: '', + inputs: [], + package: { + name: 'filetest', + title: 'For File Tests', + version: '0.1.0', + }, + }) + .expect(500); + } else { + warnAndSkipTest(this, log); + } + }); + }); +} From 8a4d0d06a5edcc8d3679a3a04964c87ce1a7cd27 Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 13 Jul 2020 08:16:26 -0700 Subject: [PATCH 24/28] add old .chromium to gitignore to prevent it from being accidentally committed --- x-pack/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/.gitignore b/x-pack/.gitignore index e181caf2b1a49..0c916ef0e9b91 100644 --- a/x-pack/.gitignore +++ b/x-pack/.gitignore @@ -6,6 +6,7 @@ /test/page_load_metrics/screenshots /test/functional/apps/reporting/reports/session /test/reporting/configs/failure_debug/ +/plugins/reporting/.chromium/ /legacy/plugins/reporting/.chromium/ /legacy/plugins/reporting/.phantom/ /plugins/reporting/chromium/ From 327fed87bbb369b3061de3862a1ceefcbfa1e5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Mon, 13 Jul 2020 17:21:22 +0200 Subject: [PATCH 25/28] [APM] Improvements to the ML Settings page (#71309) --- .../Settings/anomaly_detection/add_environments.tsx | 8 +++++++- .../app/Settings/anomaly_detection/index.tsx | 8 ++++++-- .../app/Settings/anomaly_detection/jobs_list.tsx | 12 +++++++----- .../anomaly_detection/get_anomaly_detection_jobs.ts | 2 +- ...obs_by_group.ts => get_ml_jobs_with_apm_group.ts} | 0 .../server/lib/anomaly_detection/has_legacy_jobs.ts | 2 +- .../apm/server/routes/settings/anomaly_detection.ts | 7 +++++-- x-pack/plugins/apm/typings/anomaly_detection.ts | 10 ---------- 8 files changed, 27 insertions(+), 22 deletions(-) rename x-pack/plugins/apm/server/lib/anomaly_detection/{get_ml_jobs_by_group.ts => get_ml_jobs_with_apm_group.ts} (100%) delete mode 100644 x-pack/plugins/apm/typings/anomaly_detection.ts diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx index 98b4ae2f4b63f..4c056d48f4b14 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx @@ -50,6 +50,8 @@ export const AddEnvironments = ({ disabled: currentEnvironments.includes(env), })); + const [isSaving, setIsSaving] = useState(false); + const [selectedOptions, setSelected] = useState< Array> >([]); @@ -127,9 +129,12 @@ export const AddEnvironments = ({ { + setIsSaving(true); + const selectedEnvironments = selectedOptions.map( ({ value }) => value as string ); @@ -140,6 +145,7 @@ export const AddEnvironments = ({ if (success) { onCreateJobSuccess(); } + setIsSaving(false); }} > {i18n.translate( diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx index 6f985d06dba9d..f02350fafbabb 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx @@ -15,7 +15,11 @@ import { LicensePrompt } from '../../../shared/LicensePrompt'; import { useLicense } from '../../../../hooks/useLicense'; import { APIReturnType } from '../../../../services/rest/createCallApmApi'; -const DEFAULT_VALUE: APIReturnType<'/api/apm/settings/anomaly-detection'> = { +export type AnomalyDetectionApiResponse = APIReturnType< + '/api/apm/settings/anomaly-detection' +>; + +const DEFAULT_VALUE: AnomalyDetectionApiResponse = { jobs: [], hasLegacyJobs: false, }; @@ -80,7 +84,7 @@ export const AnomalyDetection = () => { ) : ( { setViewAddEnvironments(true); diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx index 34687e5a8094e..5954b82f3b9e7 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx @@ -19,13 +19,15 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { FETCH_STATUS } from '../../../../hooks/useFetcher'; import { ITableColumn, ManagedTable } from '../../../shared/ManagedTable'; import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt'; -import { AnomalyDetectionJobByEnv } from '../../../../../typings/anomaly_detection'; import { MLJobLink } from '../../../shared/Links/MachineLearningLinks/MLJobLink'; import { MLLink } from '../../../shared/Links/MachineLearningLinks/MLLink'; import { getEnvironmentLabel } from '../../../../../common/environment_filter_values'; import { LegacyJobsCallout } from './legacy_jobs_callout'; +import { AnomalyDetectionApiResponse } from './index'; -const columns: Array> = [ +type Jobs = AnomalyDetectionApiResponse['jobs']; + +const columns: Array> = [ { field: 'environment', name: i18n.translate( @@ -57,13 +59,13 @@ const columns: Array> = [ interface Props { status: FETCH_STATUS; onAddEnvironments: () => void; - anomalyDetectionJobsByEnv: AnomalyDetectionJobByEnv[]; + jobs: Jobs; hasLegacyJobs: boolean; } export const JobsList = ({ status, onAddEnvironments, - anomalyDetectionJobsByEnv, + jobs, hasLegacyJobs, }: Props) => { const isLoading = @@ -128,7 +130,7 @@ export const JobsList = ({ ) } columns={columns} - items={isLoading || hasFetchFailure ? [] : anomalyDetectionJobsByEnv} + items={jobs} /> diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts index 8fdebeb597eaf..13b30f159eed1 100644 --- a/x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts +++ b/x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts @@ -6,7 +6,7 @@ import { Logger } from 'kibana/server'; import { Setup } from '../helpers/setup_request'; -import { getMlJobsWithAPMGroup } from './get_ml_jobs_by_group'; +import { getMlJobsWithAPMGroup } from './get_ml_jobs_with_apm_group'; export async function getAnomalyDetectionJobs(setup: Setup, logger: Logger) { const { ml } = setup; diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/get_ml_jobs_by_group.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/get_ml_jobs_with_apm_group.ts similarity index 100% rename from x-pack/plugins/apm/server/lib/anomaly_detection/get_ml_jobs_by_group.ts rename to x-pack/plugins/apm/server/lib/anomaly_detection/get_ml_jobs_with_apm_group.ts diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/has_legacy_jobs.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/has_legacy_jobs.ts index bf502607fcc1d..999d28309121a 100644 --- a/x-pack/plugins/apm/server/lib/anomaly_detection/has_legacy_jobs.ts +++ b/x-pack/plugins/apm/server/lib/anomaly_detection/has_legacy_jobs.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { Setup } from '../helpers/setup_request'; -import { getMlJobsWithAPMGroup } from './get_ml_jobs_by_group'; +import { getMlJobsWithAPMGroup } from './get_ml_jobs_with_apm_group'; // Determine whether there are any legacy ml jobs. // A legacy ML job has a job id that ends with "high_mean_response_time" and created_by=ml-module-apm-transaction diff --git a/x-pack/plugins/apm/server/routes/settings/anomaly_detection.ts b/x-pack/plugins/apm/server/routes/settings/anomaly_detection.ts index 7009470e1ff17..4d564b773e397 100644 --- a/x-pack/plugins/apm/server/routes/settings/anomaly_detection.ts +++ b/x-pack/plugins/apm/server/routes/settings/anomaly_detection.ts @@ -18,10 +18,13 @@ export const anomalyDetectionJobsRoute = createRoute(() => ({ path: '/api/apm/settings/anomaly-detection', handler: async ({ context, request }) => { const setup = await setupRequest(context, request); - const jobs = await getAnomalyDetectionJobs(setup, context.logger); + const [jobs, legacyJobs] = await Promise.all([ + getAnomalyDetectionJobs(setup, context.logger), + hasLegacyJobs(setup), + ]); return { jobs, - hasLegacyJobs: await hasLegacyJobs(setup), + hasLegacyJobs: legacyJobs, }; }, })); diff --git a/x-pack/plugins/apm/typings/anomaly_detection.ts b/x-pack/plugins/apm/typings/anomaly_detection.ts deleted file mode 100644 index 30dc92c36dea4..0000000000000 --- a/x-pack/plugins/apm/typings/anomaly_detection.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * 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 interface AnomalyDetectionJobByEnv { - environment: string; - job_id: string; -} From 24edc804c94a0df8a7a8ddece377978882d5c364 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Mon, 13 Jul 2020 16:30:03 +0100 Subject: [PATCH 26/28] Node options from cfg file for production (#62468) * chore(NA): load NODE_OPTIONS from options files across environments * chore(NA): move node.ci.options to config folder * docs(NA): update docs to explain how to set node options from the cfg fil * chore(NA): removed test npm scripts * fix(NA): typo on setup script for CI * chore(NA): add debug info * chore(NA): export options on CI * chore(NA): remove debug info * chore(NA): support for configurable config folder using env var * chore(NA): add node.options file into docker img * fix(NA): use calculated config dir on node options for ci * chore(NA): node bin scripts bootstrap and node_with_options implementation for bash * chore(NA): complete node_with_options scripts with bat version * chore(NA): add bin/node dev script and remove cli for run_with_node_options * chore(NA): increase default maxBuffer * chore(NA): remove run with options script from package.json * chore(NA): include kbn-node script and underlying usage of it * chore(NA): remove change on eslint * chore(NA): correct typo on kbn node script comment Co-authored-by: Tyler Smalley * chore(NA): correct typo on kbn node script comment Co-authored-by: Tyler Smalley * chore(NA): add line to describe each option should be specified in a separated line * chore(NA): remove node options from dev and ci env * chore(NA): remove changes from package.json * chore(NA): fix docker image build * chore(NA): change value for example of --max-old-space-size in the node.options file Co-authored-by: Tyler Smalley * chore(NA): remove --no-warnings from node.options and force it in the bin scripts * chore(NA): prevent 'The system cannot find the file' error message * chore(NA): introduce slash when building path for %DIR% * chore(NA): read options from file only if it exists Co-authored-by: Jonathan Budzenski Co-authored-by: Elastic Machine Co-authored-by: Tyler Smalley --- .gitignore | 1 + config/node.options | 6 +++++ docs/setup/production.asciidoc | 4 ++-- package.json | 2 +- src/dev/build/tasks/bin/scripts/kibana | 7 +++++- .../build/tasks/bin/scripts/kibana-keystore | 7 +++++- .../tasks/bin/scripts/kibana-keystore.bat | 17 ++++++++++++- src/dev/build/tasks/bin/scripts/kibana-plugin | 7 +++++- .../build/tasks/bin/scripts/kibana-plugin.bat | 23 +++++++++++++++--- src/dev/build/tasks/bin/scripts/kibana.bat | 24 +++++++++++++++++-- src/dev/build/tasks/copy_source_task.js | 1 + 11 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 config/node.options diff --git a/.gitignore b/.gitignore index 716cea937f9c0..dfd02de7b1186 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ disabledPlugins webpackstats.json /config/* !/config/kibana.yml +!/config/node.options coverage selenium .babel_register_cache.json diff --git a/config/node.options b/config/node.options new file mode 100644 index 0000000000000..2927d1b576716 --- /dev/null +++ b/config/node.options @@ -0,0 +1,6 @@ +## Node command line options +## See `node --help` and `node --v8-options` for available options +## Please note you should specify one option per line + +## max size of old space in megabytes +#--max-old-space-size=4096 diff --git a/docs/setup/production.asciidoc b/docs/setup/production.asciidoc index 72f275e237490..afb4b37df6a28 100644 --- a/docs/setup/production.asciidoc +++ b/docs/setup/production.asciidoc @@ -167,9 +167,9 @@ These can be used to automatically update the list of hosts as a cluster is resi Kibana has a default maximum memory limit of 1.4 GB, and in most cases, we recommend leaving this unconfigured. In some scenarios, such as large reporting jobs, it may make sense to tweak limits to meet more specific requirements. -You can modify this limit by setting `--max-old-space-size` in the `NODE_OPTIONS` environment variable. For deb and rpm, packages this is passed in via `/etc/default/kibana` and can be appended to the bottom of the file. +You can modify this limit by setting `--max-old-space-size` in the `node.options` config file that can be found inside `kibana/config` folder or any other configured with the environment variable `KIBANA_PATH_CONF` (for example in debian based system would be `/etc/kibana`). The option accepts a limit in MB: -------- -NODE_OPTIONS="--max-old-space-size=2048" bin/kibana +--max-old-space-size=2048 -------- diff --git a/package.json b/package.json index 7889909b15244..7ab6bfb91a376 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "uiFramework:documentComponent": "cd packages/kbn-ui-framework && yarn documentComponent", "kbn:watch": "node scripts/kibana --dev --logging.json=false", "build:types": "tsc --p tsconfig.types.json", - "docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept", + "docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept", "kbn:bootstrap": "node scripts/register_git_hook", "spec_to_console": "node scripts/spec_to_console", "backport-skip-ci": "backport --prDescription \"[skip-ci]\"", diff --git a/src/dev/build/tasks/bin/scripts/kibana b/src/dev/build/tasks/bin/scripts/kibana index 558facb9da32b..3283e17008e7c 100755 --- a/src/dev/build/tasks/bin/scripts/kibana +++ b/src/dev/build/tasks/bin/scripts/kibana @@ -14,6 +14,7 @@ while [ -h "$SCRIPT" ] ; do done DIR="$(dirname "${SCRIPT}")/.." +CONFIG_DIR=${KIBANA_PATH_CONF:-"$DIR/config"} NODE="${DIR}/node/bin/node" test -x "$NODE" if [ ! -x "$NODE" ]; then @@ -21,4 +22,8 @@ if [ ! -x "$NODE" ]; then exit 1 fi -NODE_OPTIONS="--no-warnings --max-http-header-size=65536 ${NODE_OPTIONS}" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli" ${@} +if [ -f "${CONFIG_DIR}/node.options" ]; then + KBN_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)" +fi + +NODE_OPTIONS="--no-warnings --max-http-header-size=65536 $KBN_NODE_OPTS $NODE_OPTIONS" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli" ${@} diff --git a/src/dev/build/tasks/bin/scripts/kibana-keystore b/src/dev/build/tasks/bin/scripts/kibana-keystore index 43800c7b895d3..f83df118d24e8 100755 --- a/src/dev/build/tasks/bin/scripts/kibana-keystore +++ b/src/dev/build/tasks/bin/scripts/kibana-keystore @@ -14,6 +14,7 @@ while [ -h "$SCRIPT" ] ; do done DIR="$(dirname "${SCRIPT}")/.." +CONFIG_DIR=${KIBANA_PATH_CONF:-"$DIR/config"} NODE="${DIR}/node/bin/node" test -x "$NODE" if [ ! -x "$NODE" ]; then @@ -21,4 +22,8 @@ if [ ! -x "$NODE" ]; then exit 1 fi -"${NODE}" "${DIR}/src/cli_keystore" "$@" +if [ -f "${CONFIG_DIR}/node.options" ]; then + KBN_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)" +fi + +NODE_OPTIONS="$KBN_NODE_OPTS $NODE_OPTIONS" "${NODE}" "${DIR}/src/cli_keystore" "$@" diff --git a/src/dev/build/tasks/bin/scripts/kibana-keystore.bat b/src/dev/build/tasks/bin/scripts/kibana-keystore.bat index b8311db2cfae5..389eb5bf488e4 100644 --- a/src/dev/build/tasks/bin/scripts/kibana-keystore.bat +++ b/src/dev/build/tasks/bin/scripts/kibana-keystore.bat @@ -1,6 +1,6 @@ @echo off -SETLOCAL +SETLOCAL ENABLEDELAYEDEXPANSION set SCRIPT_DIR=%~dp0 for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI @@ -12,6 +12,21 @@ If Not Exist "%NODE%" ( Exit /B 1 ) +set CONFIG_DIR=%KIBANA_PATH_CONF% +If [%KIBANA_PATH_CONF%] == [] ( + set CONFIG_DIR=%DIR%\config +) + +IF EXIST "%CONFIG_DIR%\node.options" ( + for /F "eol=# tokens=*" %%i in (%CONFIG_DIR%\node.options) do ( + If [!NODE_OPTIONS!] == [] ( + set "NODE_OPTIONS=%%i" + ) Else ( + set "NODE_OPTIONS=!NODE_OPTIONS! %%i" + ) + ) +) + TITLE Kibana Keystore "%NODE%" "%DIR%\src\cli_keystore" %* diff --git a/src/dev/build/tasks/bin/scripts/kibana-plugin b/src/dev/build/tasks/bin/scripts/kibana-plugin index b843d4966c6d1..f1102e1ef5a32 100755 --- a/src/dev/build/tasks/bin/scripts/kibana-plugin +++ b/src/dev/build/tasks/bin/scripts/kibana-plugin @@ -14,6 +14,7 @@ while [ -h "$SCRIPT" ] ; do done DIR="$(dirname "${SCRIPT}")/.." +CONFIG_DIR=${KIBANA_PATH_CONF:-"$DIR/config"} NODE="${DIR}/node/bin/node" test -x "$NODE" if [ ! -x "$NODE" ]; then @@ -21,4 +22,8 @@ if [ ! -x "$NODE" ]; then exit 1 fi -NODE_OPTIONS="--no-warnings ${NODE_OPTIONS}" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli_plugin" "$@" +if [ -f "${CONFIG_DIR}/node.options" ]; then + KBN_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)" +fi + +NODE_OPTIONS="--no-warnings $KBN_NODE_OPTS $NODE_OPTIONS" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli_plugin" "$@" diff --git a/src/dev/build/tasks/bin/scripts/kibana-plugin.bat b/src/dev/build/tasks/bin/scripts/kibana-plugin.bat index bf382a0657ade..6815b1b9eab8c 100755 --- a/src/dev/build/tasks/bin/scripts/kibana-plugin.bat +++ b/src/dev/build/tasks/bin/scripts/kibana-plugin.bat @@ -1,6 +1,6 @@ @echo off -SETLOCAL +SETLOCAL ENABLEDELAYEDEXPANSION set SCRIPT_DIR=%~dp0 for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI @@ -13,9 +13,26 @@ If Not Exist "%NODE%" ( Exit /B 1 ) -TITLE Kibana Server +set CONFIG_DIR=%KIBANA_PATH_CONF% +If [%KIBANA_PATH_CONF%] == [] ( + set CONFIG_DIR=%DIR%\config +) + +IF EXIST "%CONFIG_DIR%\node.options" ( + for /F "eol=# tokens=*" %%i in (%CONFIG_DIR%\node.options) do ( + If [!NODE_OPTIONS!] == [] ( + set "NODE_OPTIONS=%%i" + ) Else ( + set "NODE_OPTIONS=!NODE_OPTIONS! %%i" + ) + ) +) + +:: Include pre-defined node option +set "NODE_OPTIONS=--no-warnings %NODE_OPTIONS%" -set "NODE_OPTIONS=--no-warnings %NODE_OPTIONS%" && "%NODE%" "%DIR%\src\cli_plugin" %* +TITLE Kibana Server +"%NODE%" "%DIR%\src\cli_plugin" %* :finally diff --git a/src/dev/build/tasks/bin/scripts/kibana.bat b/src/dev/build/tasks/bin/scripts/kibana.bat index 9d8ba359e53af..d3edc92f110a5 100755 --- a/src/dev/build/tasks/bin/scripts/kibana.bat +++ b/src/dev/build/tasks/bin/scripts/kibana.bat @@ -1,6 +1,6 @@ @echo off -SETLOCAL +SETLOCAL ENABLEDELAYEDEXPANSION set SCRIPT_DIR=%~dp0 for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI @@ -14,7 +14,27 @@ If Not Exist "%NODE%" ( Exit /B 1 ) -set "NODE_OPTIONS=--no-warnings --max-http-header-size=65536 %NODE_OPTIONS%" && "%NODE%" "%DIR%\src\cli" %* +set CONFIG_DIR=%KIBANA_PATH_CONF% +If [%KIBANA_PATH_CONF%] == [] ( + set CONFIG_DIR=%DIR%\config +) + +IF EXIST "%CONFIG_DIR%\node.options" ( + for /F "eol=# tokens=*" %%i in (%CONFIG_DIR%\node.options) do ( + If [!NODE_OPTIONS!] == [] ( + set "NODE_OPTIONS=%%i" + ) Else ( + set "NODE_OPTIONS=!NODE_OPTIONS! %%i" + ) + ) +) + +:: Include pre-defined node option +set "NODE_OPTIONS=--no-warnings --max-http-header-size=65536 %NODE_OPTIONS%" + +:: This should run independently as the last instruction +:: as we need NODE_OPTIONS previously set to expand +"%NODE%" "%DIR%\src\cli" %* :finally diff --git a/src/dev/build/tasks/copy_source_task.js b/src/dev/build/tasks/copy_source_task.js index 32eb7bf8712e3..e34f05bd6cfff 100644 --- a/src/dev/build/tasks/copy_source_task.js +++ b/src/dev/build/tasks/copy_source_task.js @@ -43,6 +43,7 @@ export const CopySourceTask = { 'typings/**', 'webpackShims/**', 'config/kibana.yml', + 'config/node.options', 'tsconfig*.json', '.i18nrc.json', 'kibana.d.ts', From 17dc0439e21737cfd9c4a598028251771cdfb5e0 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 13 Jul 2020 11:33:51 -0400 Subject: [PATCH 27/28] [Ingest Manager] Add UI to enroll standalone agent (#71288) --- .../common/services/config_to_yaml.ts | 2 +- .../hooks/use_request/agent_config.ts | 11 ++ .../hooks/use_request/enrollment_api_keys.ts | 12 ++ .../config_selection.tsx | 163 ++++++++++------ .../agent_enrollment_flyout/index.tsx | 119 +++--------- .../managed_instructions.tsx | 91 +++++++++ .../standalone_instructions.tsx | 181 ++++++++++++++++++ .../agent_enrollment_flyout/steps.tsx | 66 +++++++ .../server/routes/agent_config/handlers.ts | 21 +- .../server/services/agent_config.ts | 10 +- .../server/types/rest_spec/agent_config.ts | 1 + .../translations/translations/ja-JP.json | 1 - .../translations/translations/zh-CN.json | 1 - 13 files changed, 516 insertions(+), 163 deletions(-) create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/managed_instructions.tsx create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/standalone_instructions.tsx create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/steps.tsx diff --git a/x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts b/x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts index c2043a40369e2..7e03e4572f9ee 100644 --- a/x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts +++ b/x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts @@ -11,8 +11,8 @@ const CONFIG_KEYS_ORDER = [ 'name', 'revision', 'type', - 'settings', 'outputs', + 'settings', 'inputs', 'enabled', 'use_output', diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts index 56b78c6faa93a..0bb09c2731032 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts @@ -48,6 +48,17 @@ export const useGetOneAgentConfigFull = (agentConfigId: string) => { }); }; +export const sendGetOneAgentConfigFull = ( + agentConfigId: string, + query: { standalone?: boolean } = {} +) => { + return sendRequest({ + path: agentConfigRouteService.getInfoFullPath(agentConfigId), + method: 'get', + query, + }); +}; + export const sendGetOneAgentConfig = (agentConfigId: string) => { return sendRequest({ path: agentConfigRouteService.getInfoPath(agentConfigId), diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/enrollment_api_keys.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/enrollment_api_keys.ts index 10d9e03e986e1..5a334e2739027 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/enrollment_api_keys.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/enrollment_api_keys.ts @@ -44,6 +44,18 @@ export function sendDeleteOneEnrollmentAPIKey(keyId: string, options?: RequestOp }); } +export function sendGetEnrollmentAPIKeys( + query: GetEnrollmentAPIKeysRequest['query'], + options?: RequestOptions +) { + return sendRequest({ + method: 'get', + path: enrollmentAPIKeyRouteService.getListPath(), + query, + ...options, + }); +} + export function useGetEnrollmentAPIKeys( query: GetEnrollmentAPIKeysRequest['query'], options?: RequestOptions diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx index 8cd337586d1bc..6f53a237187e5 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx @@ -4,46 +4,91 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiSelect, EuiSpacer, EuiText, EuiButtonEmpty } from '@elastic/eui'; -import { AgentConfig } from '../../../../types'; -import { useGetEnrollmentAPIKeys } from '../../../../hooks'; +import { AgentConfig, GetEnrollmentAPIKeysResponse } from '../../../../types'; +import { sendGetEnrollmentAPIKeys, useCore } from '../../../../hooks'; import { AgentConfigPackageBadges } from '../agent_config_package_badges'; -interface Props { +type Props = { agentConfigs: AgentConfig[]; - onKeyChange: (key: string) => void; -} + onConfigChange?: (key: string) => void; +} & ( + | { + withKeySelection: true; + onKeyChange?: (key: string) => void; + } + | { + withKeySelection: false; + } +); -export const EnrollmentStepAgentConfig: React.FC = ({ agentConfigs, onKeyChange }) => { - const [isAuthenticationSettingsOpen, setIsAuthenticationSettingsOpen] = useState(false); - const enrollmentAPIKeysRequest = useGetEnrollmentAPIKeys({ - page: 1, - perPage: 1000, - }); +export const EnrollmentStepAgentConfig: React.FC = (props) => { + const { notifications } = useCore(); + const { withKeySelection, agentConfigs, onConfigChange } = props; + const onKeyChange = props.withKeySelection && props.onKeyChange; + const [isAuthenticationSettingsOpen, setIsAuthenticationSettingsOpen] = useState(false); + const [enrollmentAPIKeys, setEnrollmentAPIKeys] = useState( + [] + ); const [selectedState, setSelectedState] = useState<{ agentConfigId?: string; enrollmentAPIKeyId?: string; }>({ agentConfigId: agentConfigs.length ? agentConfigs[0].id : undefined, }); - const filteredEnrollmentAPIKeys = React.useMemo(() => { - if (!selectedState.agentConfigId || !enrollmentAPIKeysRequest.data) { - return []; + + useEffect(() => { + if (onConfigChange && selectedState.agentConfigId) { + onConfigChange(selectedState.agentConfigId); } + }, [selectedState.agentConfigId, onConfigChange]); - return enrollmentAPIKeysRequest.data.list.filter( - (key) => key.config_id === selectedState.agentConfigId - ); - }, [enrollmentAPIKeysRequest.data, selectedState.agentConfigId]); + useEffect(() => { + if (!withKeySelection) { + return; + } + if (!selectedState.agentConfigId) { + setEnrollmentAPIKeys([]); + return; + } + + async function fetchEnrollmentAPIKeys() { + try { + const res = await sendGetEnrollmentAPIKeys({ + page: 1, + perPage: 10000, + }); + if (res.error) { + throw res.error; + } + + if (!res.data) { + throw new Error('No data while fetching enrollment API keys'); + } + + setEnrollmentAPIKeys( + res.data.list.filter((key) => key.config_id === selectedState.agentConfigId) + ); + } catch (error) { + notifications.toasts.addError(error, { + title: 'Error', + }); + } + } + fetchEnrollmentAPIKeys(); + }, [withKeySelection, selectedState.agentConfigId, notifications.toasts]); // Select first API key when config change React.useEffect(() => { - if (!selectedState.enrollmentAPIKeyId && filteredEnrollmentAPIKeys.length > 0) { - const enrollmentAPIKeyId = filteredEnrollmentAPIKeys[0].id; + if (!withKeySelection || !onKeyChange) { + return; + } + if (!selectedState.enrollmentAPIKeyId && enrollmentAPIKeys.length > 0) { + const enrollmentAPIKeyId = enrollmentAPIKeys[0].id; setSelectedState({ agentConfigId: selectedState.agentConfigId, enrollmentAPIKeyId, @@ -51,7 +96,7 @@ export const EnrollmentStepAgentConfig: React.FC = ({ agentConfigs, onKey onKeyChange(enrollmentAPIKeyId); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [filteredEnrollmentAPIKeys, selectedState.enrollmentAPIKeyId, selectedState.agentConfigId]); + }, [enrollmentAPIKeys, selectedState.enrollmentAPIKeyId, selectedState.agentConfigId]); return ( <> @@ -85,43 +130,47 @@ export const EnrollmentStepAgentConfig: React.FC = ({ agentConfigs, onKey {selectedState.agentConfigId && ( )} - - setIsAuthenticationSettingsOpen(!isAuthenticationSettingsOpen)} - > - - - {isAuthenticationSettingsOpen && ( + {withKeySelection && onKeyChange && ( <> - ({ - value: key.id, - text: key.name, - }))} - value={selectedState.enrollmentAPIKeyId || undefined} - prepend={ - - - - } - onChange={(e) => { - setSelectedState({ - ...selectedState, - enrollmentAPIKeyId: e.target.value, - }); - onKeyChange(e.target.value); - }} - /> + setIsAuthenticationSettingsOpen(!isAuthenticationSettingsOpen)} + > + + + {isAuthenticationSettingsOpen && ( + <> + + ({ + value: key.id, + text: key.name, + }))} + value={selectedState.enrollmentAPIKeyId || undefined} + prepend={ + + + + } + onChange={(e) => { + setSelectedState({ + ...selectedState, + enrollmentAPIKeyId: e.target.value, + }); + onKeyChange(e.target.value); + }} + /> + + )} )} diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx index 43173124d6bae..5a9d3b7efe1bb 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx @@ -14,23 +14,13 @@ import { EuiButtonEmpty, EuiButton, EuiFlyoutFooter, - EuiSteps, - EuiText, - EuiLink, + EuiTab, + EuiTabs, } from '@elastic/eui'; -import { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps'; -import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { AgentConfig } from '../../../../types'; -import { EnrollmentStepAgentConfig } from './config_selection'; -import { - useGetOneEnrollmentAPIKey, - useCore, - useGetSettings, - useLink, - useFleetStatus, -} from '../../../../hooks'; -import { ManualInstructions } from '../../../../components/enrollment_instructions'; +import { ManagedInstructions } from './managed_instructions'; +import { StandaloneInstructions } from './standalone_instructions'; interface Props { onClose: () => void; @@ -41,99 +31,40 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ onClose, agentConfigs = [], }) => { - const { getHref } = useLink(); - const core = useCore(); - const fleetStatus = useFleetStatus(); - - const [selectedAPIKeyId, setSelectedAPIKeyId] = useState(); - - const settings = useGetSettings(); - const apiKey = useGetOneEnrollmentAPIKey(selectedAPIKeyId); - - const kibanaUrl = - settings.data?.item?.kibana_url ?? `${window.location.origin}${core.http.basePath.get()}`; - const kibanaCASha256 = settings.data?.item?.kibana_ca_sha256; - - const steps: EuiContainedStepProps[] = [ - { - title: i18n.translate('xpack.ingestManager.agentEnrollment.stepDownloadAgentTitle', { - defaultMessage: 'Download the Elastic Agent', - }), - children: ( - - - - - ), - }} - /> - - ), - }, - { - title: i18n.translate('xpack.ingestManager.agentEnrollment.stepChooseAgentConfigTitle', { - defaultMessage: 'Choose an agent configuration', - }), - children: ( - - ), - }, - { - title: i18n.translate('xpack.ingestManager.agentEnrollment.stepRunAgentTitle', { - defaultMessage: 'Enroll and run the Elastic Agent', - }), - children: apiKey.data && ( - - ), - }, - ]; + const [mode, setMode] = useState<'managed' | 'standalone'>('managed'); return ( - +

+ + setMode('managed')}> + + + setMode('standalone')}> + + +
+ - {fleetStatus.isReady ? ( - <> - - + {mode === 'managed' ? ( + ) : ( - <> - - - - ), - }} - /> - + )} diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/managed_instructions.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/managed_instructions.tsx new file mode 100644 index 0000000000000..aabbd37e809a8 --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/managed_instructions.tsx @@ -0,0 +1,91 @@ +/* + * 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 React, { useState } from 'react'; +import { EuiSteps, EuiLink, EuiText, EuiSpacer } from '@elastic/eui'; +import { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { AgentConfig } from '../../../../types'; +import { + useGetOneEnrollmentAPIKey, + useCore, + useGetSettings, + useLink, + useFleetStatus, +} from '../../../../hooks'; +import { ManualInstructions } from '../../../../components/enrollment_instructions'; +import { DownloadStep, AgentConfigSelectionStep } from './steps'; + +interface Props { + agentConfigs: AgentConfig[]; +} + +export const ManagedInstructions: React.FunctionComponent = ({ agentConfigs = [] }) => { + const { getHref } = useLink(); + const core = useCore(); + const fleetStatus = useFleetStatus(); + + const [selectedAPIKeyId, setSelectedAPIKeyId] = useState(); + + const settings = useGetSettings(); + const apiKey = useGetOneEnrollmentAPIKey(selectedAPIKeyId); + + const kibanaUrl = + settings.data?.item?.kibana_url ?? `${window.location.origin}${core.http.basePath.get()}`; + const kibanaCASha256 = settings.data?.item?.kibana_ca_sha256; + + const steps: EuiContainedStepProps[] = [ + DownloadStep(), + AgentConfigSelectionStep({ agentConfigs, setSelectedAPIKeyId }), + { + title: i18n.translate('xpack.ingestManager.agentEnrollment.stepEnrollAndRunAgentTitle', { + defaultMessage: 'Enroll and start the Elastic Agent', + }), + children: apiKey.data && ( + + ), + }, + ]; + + return ( + <> + + + + + {fleetStatus.isReady ? ( + <> + + + ) : ( + <> + + + + ), + }} + /> + + )}{' '} + + ); +}; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/standalone_instructions.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/standalone_instructions.tsx new file mode 100644 index 0000000000000..27f64059deb84 --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/standalone_instructions.tsx @@ -0,0 +1,181 @@ +/* + * 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 React, { useState, useEffect, useMemo } from 'react'; +import { + EuiSteps, + EuiText, + EuiSpacer, + EuiButton, + EuiCode, + EuiFlexItem, + EuiFlexGroup, + EuiCodeBlock, + EuiCopy, +} from '@elastic/eui'; +import { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { AgentConfig } from '../../../../types'; +import { useCore, sendGetOneAgentConfigFull } from '../../../../hooks'; +import { DownloadStep, AgentConfigSelectionStep } from './steps'; +import { configToYaml, agentConfigRouteService } from '../../../../services'; + +interface Props { + agentConfigs: AgentConfig[]; +} + +const RUN_INSTRUCTIONS = './elastic-agent run'; + +export const StandaloneInstructions: React.FunctionComponent = ({ agentConfigs = [] }) => { + const core = useCore(); + const { notifications } = core; + + const [selectedConfigId, setSelectedConfigId] = useState(); + const [fullAgentConfig, setFullAgentConfig] = useState(); + + const downloadLink = selectedConfigId + ? core.http.basePath.prepend( + `${agentConfigRouteService.getInfoFullDownloadPath(selectedConfigId)}?standalone=true` + ) + : undefined; + + useEffect(() => { + async function fetchFullConfig() { + try { + if (!selectedConfigId) { + return; + } + const res = await sendGetOneAgentConfigFull(selectedConfigId, { standalone: true }); + if (res.error) { + throw res.error; + } + + if (!res.data) { + throw new Error('No data while fetching full agent config'); + } + + setFullAgentConfig(res.data.item); + } catch (error) { + notifications.toasts.addError(error, { + title: 'Error', + }); + } + } + fetchFullConfig(); + }, [selectedConfigId, notifications.toasts]); + + const yaml = useMemo(() => configToYaml(fullAgentConfig), [fullAgentConfig]); + const steps: EuiContainedStepProps[] = [ + DownloadStep(), + AgentConfigSelectionStep({ agentConfigs, setSelectedConfigId }), + { + title: i18n.translate('xpack.ingestManager.agentEnrollment.stepConfigureAgentTitle', { + defaultMessage: 'Configure the agent', + }), + children: ( + <> + + elastic-agent.yml, + ESUsernameVariable: ES_USERNAME, + ESPasswordVariable: ES_PASSWORD, + outputSection: outputs, + }} + /> + + + + + {(copy) => ( + + + + )} + + + + + + + + + + + {yaml} + + + + ), + }, + { + title: i18n.translate('xpack.ingestManager.agentEnrollment.stepRunAgentTitle', { + defaultMessage: 'Start the agent', + }), + children: ( + <> + + + + {RUN_INSTRUCTIONS} + + + {(copy) => ( + + + + )} + + + + ), + }, + { + title: i18n.translate('xpack.ingestManager.agentEnrollment.stepCheckForDataTitle', { + defaultMessage: 'Check for data', + }), + status: 'incomplete', + children: ( + <> + + + + + ), + }, + ]; + + return ( + <> + + + + + + + ); +}; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/steps.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/steps.tsx new file mode 100644 index 0000000000000..267f9027a094a --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/steps.tsx @@ -0,0 +1,66 @@ +/* + * 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 React from 'react'; +import { EuiText, EuiButton, EuiSpacer } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { EnrollmentStepAgentConfig } from './config_selection'; +import { AgentConfig } from '../../../../types'; + +export const DownloadStep = () => { + return { + title: i18n.translate('xpack.ingestManager.agentEnrollment.stepDownloadAgentTitle', { + defaultMessage: 'Download the Elastic Agent', + }), + children: ( + <> + + + + + + + + + ), + }; +}; + +export const AgentConfigSelectionStep = ({ + agentConfigs, + setSelectedAPIKeyId, + setSelectedConfigId, +}: { + agentConfigs: AgentConfig[]; + setSelectedAPIKeyId?: (key: string) => void; + setSelectedConfigId?: (configId: string) => void; +}) => { + return { + title: i18n.translate('xpack.ingestManager.agentEnrollment.stepChooseAgentConfigTitle', { + defaultMessage: 'Choose an agent configuration', + }), + children: ( + + ), + }; +}; diff --git a/x-pack/plugins/ingest_manager/server/routes/agent_config/handlers.ts b/x-pack/plugins/ingest_manager/server/routes/agent_config/handlers.ts index 110f6b9950829..2aaf889296bd6 100644 --- a/x-pack/plugins/ingest_manager/server/routes/agent_config/handlers.ts +++ b/x-pack/plugins/ingest_manager/server/routes/agent_config/handlers.ts @@ -232,15 +232,17 @@ export const deleteAgentConfigsHandler: RequestHandler< } }; -export const getFullAgentConfig: RequestHandler> = async (context, request, response) => { +export const getFullAgentConfig: RequestHandler< + TypeOf, + TypeOf +> = async (context, request, response) => { const soClient = context.core.savedObjects.client; try { const fullAgentConfig = await agentConfigService.getFullConfig( soClient, - request.params.agentConfigId + request.params.agentConfigId, + { standalone: request.query.standalone === true } ); if (fullAgentConfig) { const body: GetFullAgentConfigResponse = { @@ -264,16 +266,19 @@ export const getFullAgentConfig: RequestHandler> = async (context, request, response) => { +export const downloadFullAgentConfig: RequestHandler< + TypeOf, + TypeOf +> = async (context, request, response) => { const soClient = context.core.savedObjects.client; const { params: { agentConfigId }, } = request; try { - const fullAgentConfig = await agentConfigService.getFullConfig(soClient, agentConfigId); + const fullAgentConfig = await agentConfigService.getFullConfig(soClient, agentConfigId, { + standalone: request.query.standalone === true, + }); if (fullAgentConfig) { const body = configToYaml(fullAgentConfig); const headers: ResponseHeaders = { diff --git a/x-pack/plugins/ingest_manager/server/services/agent_config.ts b/x-pack/plugins/ingest_manager/server/services/agent_config.ts index fe247d5b91db0..5f98c8881388d 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_config.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_config.ts @@ -365,7 +365,8 @@ class AgentConfigService { public async getFullConfig( soClient: SavedObjectsClientContract, - id: string + id: string, + options?: { standalone: boolean } ): Promise { let config; @@ -400,6 +401,13 @@ class AgentConfigService { api_key, ...outputConfig, }; + + if (options?.standalone) { + delete outputs[name].api_key; + outputs[name].username = 'ES_USERNAME'; + outputs[name].password = 'ES_PASSWORD'; + } + return outputs; }, {} as FullAgentConfig['outputs'] diff --git a/x-pack/plugins/ingest_manager/server/types/rest_spec/agent_config.ts b/x-pack/plugins/ingest_manager/server/types/rest_spec/agent_config.ts index d076a803f4b53..594bd141459c1 100644 --- a/x-pack/plugins/ingest_manager/server/types/rest_spec/agent_config.ts +++ b/x-pack/plugins/ingest_manager/server/types/rest_spec/agent_config.ts @@ -51,5 +51,6 @@ export const GetFullAgentConfigRequestSchema = { }), query: schema.object({ download: schema.maybe(schema.boolean()), + standalone: schema.maybe(schema.boolean()), }), }; diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 97afa9e058b98..e28ef8ff07bdd 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -8042,7 +8042,6 @@ "xpack.ingestManager.agentDetails.viewAgentListTitle": "すべてのエージェント構成を表示", "xpack.ingestManager.agentEnrollment.cancelButtonLabel": "キャンセル", "xpack.ingestManager.agentEnrollment.continueButtonLabel": "続行", - "xpack.ingestManager.agentEnrollment.downloadDescription": "ホストのコンピューターでElasticエージェントをダウンロードします。エージェントバイナリをダウンロードできます。検証署名はElasticの{downloadLink}にあります。", "xpack.ingestManager.agentEnrollment.downloadLink": "ダウンロードページ", "xpack.ingestManager.agentEnrollment.fleetNotInitializedText": "エージェントを登録する前に、フリートを設定する必要があります。{link}", "xpack.ingestManager.agentEnrollment.flyoutTitle": "新しいエージェントを登録", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 31a33bfa09b64..1df676ba7cffd 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -8047,7 +8047,6 @@ "xpack.ingestManager.agentDetails.viewAgentListTitle": "查看所有代理配置", "xpack.ingestManager.agentEnrollment.cancelButtonLabel": "取消", "xpack.ingestManager.agentEnrollment.continueButtonLabel": "继续", - "xpack.ingestManager.agentEnrollment.downloadDescription": "在主机计算机上下载 Elastic 代理。可以从 Elastic 的{downloadLink}下载代理二进制文件及其验证签名。", "xpack.ingestManager.agentEnrollment.downloadLink": "下载页面", "xpack.ingestManager.agentEnrollment.fleetNotInitializedText": "注册代理前需要设置 Fleet。{link}", "xpack.ingestManager.agentEnrollment.flyoutTitle": "注册新代理", From b435d4608036c89439d1cfec6349ac7bc22adbca Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Mon, 13 Jul 2020 16:43:40 +0100 Subject: [PATCH 28/28] skip flaky suite (#71361) --- .../cypress/integration/timeline_toggle_column.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/cypress/integration/timeline_toggle_column.spec.ts b/x-pack/plugins/security_solution/cypress/integration/timeline_toggle_column.spec.ts index 12e6f3db9b61e..759eec69bc022 100644 --- a/x-pack/plugins/security_solution/cypress/integration/timeline_toggle_column.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/timeline_toggle_column.spec.ts @@ -24,7 +24,8 @@ import { import { HOSTS_URL } from '../urls/navigation'; -describe('toggle column in timeline', () => { +// Flaky: https://github.com/elastic/kibana/issues/71361 +describe.skip('toggle column in timeline', () => { before(() => { loginAndWaitForPage(HOSTS_URL); });