Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into feature/unlin…
Browse files Browse the repository at this point in the history
…kFromLibraryActionWithInterface
  • Loading branch information
ThomThomson committed Aug 17, 2020
2 parents 5798261 + 7d3fe58 commit 21c7e03
Show file tree
Hide file tree
Showing 169 changed files with 2,263 additions and 1,034 deletions.
21 changes: 21 additions & 0 deletions .ci/Jenkinsfile_security_cypress
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/groovy

library 'kibana-pipeline-library'
kibanaLibrary.load()

kibanaPipeline(timeoutMinutes: 180) {
slackNotifications.onFailure(
disabled: !params.NOTIFY_ON_FAILURE,
channel: '#security-solution-slack-testing'
) {
catchError {
workers.base(size: 's', ramDisk: false) {
kibanaPipeline.bash('test/scripts/jenkins_security_solution_cypress.sh', 'Execute Security Solution Cypress Tests')
}
}
}

if (params.NOTIFY_ON_FAILURE) {
kibanaPipeline.sendMail(to: '[email protected]')
}
}
5 changes: 0 additions & 5 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ function applyConfigOverrides(rawConfig, opts, extraCliOptions) {
if (opts.verbose) set('logging.verbose', true);
if (opts.logFile) set('logging.dest', opts.logFile);

if (opts.optimize) {
set('server.autoListen', false);
set('plugins.initialize', false);
}

set('plugins.scanDirs', _.compact([].concat(get('plugins.scanDirs'), opts.pluginDir)));
set(
'plugins.paths',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
# Description: Kibana
### END INIT INFO

#
# Source function libraries if present.
# (It improves integration with systemd)
#
# Red Hat
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions

# Debian
elif [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions

# SUSE
elif [ -f /etc/rc.status ]; then
. /etc/rc.status
rc_reset
fi

name=kibana
program=/usr/share/kibana/bin/kibana
pidfile="/var/run/kibana/$name.pid"
Expand Down
1 change: 1 addition & 0 deletions src/dev/jest/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default {
setupFilesAfterEnv: [
'<rootDir>/src/dev/jest/setup/mocks.js',
'<rootDir>/src/dev/jest/setup/react_testing_library.js',
'<rootDir>/src/dev/jest/setup/default_timeout.js',
],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest',
coverageReporters: !!process.env.CODE_COVERAGE ? ['json'] : ['html', 'text'],
Expand Down
25 changes: 25 additions & 0 deletions src/dev/jest/setup/default_timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

/* eslint-env jest */

/**
* Set the default timeout for the unit tests to 30 seconds, temporarily
*/
jest.setTimeout(30 * 1000);
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
&.kbnQueryBar__datePickerWrapper-isHidden {
width: 0;
overflow: hidden;
max-width: 0;
}
}
}
1 change: 0 additions & 1 deletion src/plugins/discover/public/application/angular/doc.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div class="app-container">
<discover-doc
es-client="esClient"
id="id"
index="index"
index-pattern-id="indexPatternId"
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/discover/public/application/angular/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ app.directive('discoverDoc', function (reactDirective: any) {
['index', { watchDepth: 'value' }],
['indexPatternId', { watchDepth: 'reference' }],
['indexPatternService', { watchDepth: 'reference' }],
['esClient', { watchDepth: 'reference' }],
],
{ restrict: 'E' }
);
Expand All @@ -51,10 +50,9 @@ app.config(($routeProvider: any) => {
.when('/doc/:indexPattern/:index', {
// have to be written as function expression, because it's not compiled in dev mode
// eslint-disable-next-line object-shorthand
controller: function ($scope: LazyScope, $route: any, es: any) {
controller: function ($scope: LazyScope, $route: any) {
timefilter.disableAutoRefreshSelector();
timefilter.disableTimeRangeSelector();
$scope.esClient = es;
$scope.id = $route.current.params.id;
$scope.index = $route.current.params.index;
$scope.indexPatternId = $route.current.params.indexPattern;
Expand Down
30 changes: 19 additions & 11 deletions src/plugins/discover/public/application/components/doc/doc.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
import { throwError, of } from 'rxjs';
import React from 'react';
import { act } from 'react-dom/test-utils';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { ReactWrapper } from 'enzyme';
import { findTestSubject } from '@elastic/eui/lib/test';
import { Doc, DocProps } from './doc';

const mockSearchApi = jest.fn();

jest.mock('../../../kibana_services', () => {
let registry: any[] = [];

Expand All @@ -31,6 +34,11 @@ jest.mock('../../../kibana_services', () => {
metadata: {
branch: 'test',
},
data: {
search: {
search: mockSearchApi,
},
},
}),
getDocViewsRegistry: () => ({
addDocView(view: any) {
Expand Down Expand Up @@ -59,7 +67,7 @@ const waitForPromises = async () =>
* this works but logs ugly error messages until we're using React 16.9
* should be adapted when we upgrade
*/
async function mountDoc(search: () => void, update = false, indexPatternGetter: any = null) {
async function mountDoc(update = false, indexPatternGetter: any = null) {
const indexPattern = {
getComputedFields: () => [],
};
Expand All @@ -70,7 +78,6 @@ async function mountDoc(search: () => void, update = false, indexPatternGetter:
const props = {
id: '1',
index: 'index1',
esClient: { search } as any,
indexPatternId: 'xyz',
indexPatternService,
} as DocProps;
Expand All @@ -88,32 +95,33 @@ async function mountDoc(search: () => void, update = false, indexPatternGetter:

describe('Test of <Doc /> of Discover', () => {
test('renders loading msg', async () => {
const comp = await mountDoc(jest.fn());
const comp = await mountDoc();
expect(findTestSubject(comp, 'doc-msg-loading').length).toBe(1);
});

test('renders IndexPattern notFound msg', async () => {
const indexPatternGetter = jest.fn(() => Promise.reject({ savedObjectId: '007' }));
const comp = await mountDoc(jest.fn(), true, indexPatternGetter);
const comp = await mountDoc(true, indexPatternGetter);
expect(findTestSubject(comp, 'doc-msg-notFoundIndexPattern').length).toBe(1);
});

test('renders notFound msg', async () => {
const search = jest.fn(() => Promise.reject({ status: 404 }));
const comp = await mountDoc(search, true);
mockSearchApi.mockImplementation(() => throwError({ status: 404 }));
const comp = await mountDoc(true);
expect(findTestSubject(comp, 'doc-msg-notFound').length).toBe(1);
});

test('renders error msg', async () => {
const search = jest.fn(() => Promise.reject('whatever'));
const comp = await mountDoc(search, true);
mockSearchApi.mockImplementation(() => throwError({ error: 'something else' }));
const comp = await mountDoc(true);
expect(findTestSubject(comp, 'doc-msg-error').length).toBe(1);
});

test('renders elasticsearch hit ', async () => {
const hit = { hits: { total: 1, hits: [{ _id: 1, _source: { test: 1 } }] } };
const search = jest.fn(() => Promise.resolve(hit));
const comp = await mountDoc(search, true);
mockSearchApi.mockImplementation(() =>
of({ rawResponse: { hits: { total: 1, hits: [{ _id: 1, _source: { test: 1 } }] } } })
);
const comp = await mountDoc(true);
expect(findTestSubject(comp, 'doc-hit').length).toBe(1);
});
});
17 changes: 0 additions & 17 deletions src/plugins/discover/public/application/components/doc/doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ import { IndexPatternsContract } from 'src/plugins/data/public';
import { ElasticRequestState, useEsDocSearch } from './use_es_doc_search';
import { getServices } from '../../../kibana_services';
import { DocViewer } from '../doc_viewer/doc_viewer';
import { ElasticSearchHit } from '../../doc_views/doc_views_types';

export interface ElasticSearchResult {
hits: {
hits: [ElasticSearchHit];
max_score: number;
};
timed_out: boolean;
took: number;
shards: Record<string, unknown>;
}

export interface DocProps {
/**
Expand All @@ -53,12 +42,6 @@ export interface DocProps {
* IndexPatternService to get a given index pattern by ID
*/
indexPatternService: IndexPatternsContract;
/**
* Client of ElasticSearch to use for the query
*/
esClient: {
search: (payload: { index: string; body: Record<string, any> }) => Promise<ElasticSearchResult>;
};
}

export function Doc(props: DocProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
import { renderHook, act } from '@testing-library/react-hooks';
import { buildSearchBody, useEsDocSearch, ElasticRequestState } from './use_es_doc_search';
import { DocProps } from './doc';
import { Observable } from 'rxjs';

const mockSearchResult = new Observable();

jest.mock('../../../kibana_services', () => ({
getServices: () => ({
data: {
search: {
search: jest.fn(() => {
return mockSearchResult;
}),
},
},
}),
}));

describe('Test of <Doc /> helper / hook', () => {
test('buildSearchBody', () => {
Expand Down Expand Up @@ -53,7 +68,6 @@ describe('Test of <Doc /> helper / hook', () => {
const props = {
id: '1',
index: 'index1',
esClient: { search: jest.fn(() => new Promise(() => {})) },
indexPatternId: 'xyz',
indexPatternService,
} as DocProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import { useEffect, useState } from 'react';
import { IndexPattern } from '../../../kibana_services';
import { IndexPattern, getServices } from '../../../kibana_services';
import { DocProps } from './doc';
import { ElasticSearchHit } from '../../doc_views/doc_views_types';

Expand Down Expand Up @@ -53,7 +53,6 @@ export function buildSearchBody(id: string, indexPattern: IndexPattern): Record<
* Custom react hook for querying a single doc in ElasticSearch
*/
export function useEsDocSearch({
esClient,
id,
index,
indexPatternId,
Expand All @@ -69,12 +68,18 @@ export function useEsDocSearch({
const indexPatternEntity = await indexPatternService.get(indexPatternId);
setIndexPattern(indexPatternEntity);

const { hits } = await esClient.search({
index,
body: buildSearchBody(id, indexPatternEntity),
});
const { rawResponse } = await getServices()
.data.search.search({
params: {
index,
body: buildSearchBody(id, indexPatternEntity),
},
})
.toPromise();

if (hits && hits.hits && hits.hits[0]) {
const hits = rawResponse.hits;

if (hits?.hits?.[0]) {
setStatus(ElasticRequestState.Found);
setHit(hits.hits[0]);
} else {
Expand All @@ -91,6 +96,6 @@ export function useEsDocSearch({
}
}
requestData();
}, [esClient, id, index, indexPatternId, indexPatternService]);
}, [id, index, indexPatternId, indexPatternService]);
return [status, hit, indexPattern];
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IndexPattern } from '../../../../../data/public';

it('returns the `JsonCodeEditor` component', () => {
const props = {
hit: { _index: 'test', _source: { test: 123 } },
hit: { _index: 'test', _type: 'doc', _id: 'foo', _score: 1, _source: { test: 123 } },
columns: [],
indexPattern: {} as IndexPattern,
filter: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ describe('DocViewTable at Discover', () => {

const hit = {
_index: 'logstash-2014.09.09',
_type: 'doc',
_id: 'id123',
_score: 1,
_source: {
message:
Expand Down Expand Up @@ -191,6 +193,8 @@ describe('DocViewTable at Discover Doc', () => {
const hit = {
_index: 'logstash-2014.09.09',
_score: 1,
_type: 'doc',
_id: 'id123',
_source: {
extension: 'html',
not_mapped: 'yes',
Expand All @@ -213,6 +217,9 @@ describe('DocViewTable at Discover Context', () => {
// here no toggleColumnButtons are rendered
const hit = {
_index: 'logstash-2014.09.09',
_type: 'doc',
_id: 'id123',
_score: 1,
_source: {
message:
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { ComponentType } from 'react';
import { IScope } from 'angular';
import { SearchResponse } from 'elasticsearch';
import { IndexPattern } from '../../../../data/public';

export interface AngularDirective {
Expand All @@ -27,7 +28,7 @@ export interface AngularDirective {

export type AngularScope = IScope;

export type ElasticSearchHit = Record<string, string | number | Record<string, unknown>>;
export type ElasticSearchHit<T = unknown> = SearchResponse<T>['hits']['hits'][number];

export interface FieldMapping {
filterable?: boolean;
Expand Down
Loading

0 comments on commit 21c7e03

Please sign in to comment.