Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into feat/networkt…
Browse files Browse the repository at this point in the history
…-http-search-strategy

# Conflicts:
#	x-pack/plugins/security_solution/common/search_strategy/security_solution/index.ts
#	x-pack/plugins/security_solution/common/search_strategy/security_solution/network/index.ts
#	x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/index.ts
  • Loading branch information
patrykkopycinski committed Aug 31, 2020
2 parents e17a88f + 325b82b commit 78f0897
Show file tree
Hide file tree
Showing 45 changed files with 415 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ target
/x-pack/legacy/plugins/maps/public/vendor/**

# package overrides
/packages/eslint-config-kibana
/packages/elastic-eslint-config-kibana
/packages/kbn-interpreter/src/common/lib/grammar.js
/packages/kbn-plugin-generator/template
/packages/kbn-pm/dist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ If you’re installing dependencies and seeing an error that looks
something like

....
Unsupported URL Type: link:packages/eslint-config-kibana
Unsupported URL Type: link:packages/elastic-eslint-config-kibana
....

you’re likely running `npm`. To install dependencies in {kib} you
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# eslint-config-kibana
# elastic-eslint-config-kibana

The eslint config used by the kibana team

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"main": ".eslintrc.js",
"repository": {
"type": "git",
"url": "git+https:/elastic/eslint-config-kibana.git"
"url": "git+https:/elastic/kibana.git"
},
"keywords": [],
"author": "Spencer Alger <[email protected]>",
"license": "Apache-2.0",
"bugs": {
"url": "https:/elastic/kibana/tree/master/packages/eslint-config-kibana"
"url": "https:/elastic/kibana/tree/master/packages/elastic-eslint-config-kibana"
},
"homepage": "https:/elastic/kibana/tree/master/packages/eslint-config-kibana",
"homepage": "https:/elastic/kibana/tree/master/packages/elastic-eslint-config-kibana",
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^3.10.0",
"@typescript-eslint/parser": "^3.10.0",
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/kbn-pm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ From a plugin perspective there are two different types of Kibana dependencies:
runtime and static dependencies. Runtime dependencies are things that are
instantiated at runtime and that are injected into the plugin, for example
config and elasticsearch clients. Static dependencies are those dependencies
that we want to `import`. `eslint-config-kibana` is one example of this, and
that we want to `import`. `elastic-eslint-config-kibana` is one example of this, and
it's actually needed because eslint requires it to be a separate package. But we
also have dependencies like `datemath`, `flot`, `eui` and others that we
control, but where we want to `import` them in plugins instead of injecting them
Expand Down
28 changes: 10 additions & 18 deletions src/plugins/home/public/application/components/tutorial/tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,18 @@ class TutorialUi extends React.Component {
* @return {Promise<string>}
*/
fetchEsHitsStatus = async (esHitsCheckConfig) => {
const searchHeader = JSON.stringify({ index: esHitsCheckConfig.index });
const searchBody = JSON.stringify({ query: esHitsCheckConfig.query, size: 1 });
const response = await fetch(this.props.addBasePath('/elasticsearch/_msearch'), {
method: 'post',
body: `${searchHeader}\n${searchBody}\n`,
headers: {
accept: 'application/json',
'content-type': 'application/x-ndjson',
'kbn-xsrf': 'kibana',
},
credentials: 'same-origin',
});

if (response.status > 300) {
const { http } = getServices();
try {
const response = await http.post('/api/home/hits_status', {
body: JSON.stringify({
index: esHitsCheckConfig.index,
query: esHitsCheckConfig.query,
}),
});
return response.count > 0 ? StatusCheckStates.HAS_DATA : StatusCheckStates.NO_DATA;
} catch (e) {
return StatusCheckStates.ERROR;
}

const results = await response.json();
const numHits = _.get(results, 'responses.[0].hits.hits.length', 0);
return numHits === 0 ? StatusCheckStates.NO_DATA : StatusCheckStates.HAS_DATA;
};

renderInstructionSetsToggle = () => {
Expand Down
29 changes: 23 additions & 6 deletions src/plugins/home/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

import { registryForTutorialsMock, registryForSampleDataMock } from './plugin.test.mocks';
import { HomeServerPlugin } from './plugin';
import { coreMock } from '../../../core/server/mocks';
import { CoreSetup } from '../../../core/server';

type MockedKeys<T> = { [P in keyof T]: jest.Mocked<T[P]> };
import { coreMock, httpServiceMock } from '../../../core/server/mocks';

describe('HomeServerPlugin', () => {
beforeEach(() => {
Expand All @@ -33,8 +30,16 @@ describe('HomeServerPlugin', () => {
});

describe('setup', () => {
const mockCoreSetup: MockedKeys<CoreSetup> = coreMock.createSetup();
const initContext = coreMock.createPluginInitializerContext();
let mockCoreSetup: ReturnType<typeof coreMock.createSetup>;
let initContext: ReturnType<typeof coreMock.createPluginInitializerContext>;
let routerMock: ReturnType<typeof httpServiceMock.createRouter>;

beforeEach(() => {
mockCoreSetup = coreMock.createSetup();
routerMock = httpServiceMock.createRouter();
mockCoreSetup.http.createRouter.mockReturnValue(routerMock);
initContext = coreMock.createPluginInitializerContext();
});

test('wires up tutorials provider service and returns registerTutorial and addScopedTutorialContextFactory', () => {
const setup = new HomeServerPlugin(initContext).setup(mockCoreSetup, {});
Expand All @@ -52,6 +57,18 @@ describe('HomeServerPlugin', () => {
expect(setup.sampleData).toHaveProperty('addAppLinksToSampleDataset');
expect(setup.sampleData).toHaveProperty('replacePanelInSampleDatasetDashboard');
});

test('registers the `/api/home/hits_status` route', () => {
new HomeServerPlugin(initContext).setup(mockCoreSetup, {});

expect(routerMock.post).toHaveBeenCalledTimes(1);
expect(routerMock.post).toHaveBeenCalledWith(
expect.objectContaining({
path: '/api/home/hits_status',
}),
expect.any(Function)
);
});
});

describe('start', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/home/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { UsageCollectionSetup } from '../../usage_collection/server';
import { capabilitiesProvider } from './capabilities_provider';
import { sampleDataTelemetry } from './saved_objects';
import { registerRoutes } from './routes';

interface HomeServerPluginSetupDependencies {
usageCollection?: UsageCollectionSetup;
Expand All @@ -41,6 +42,10 @@ export class HomeServerPlugin implements Plugin<HomeServerPluginSetup, HomeServe
public setup(core: CoreSetup, plugins: HomeServerPluginSetupDependencies): HomeServerPluginSetup {
core.capabilities.registerProvider(capabilitiesProvider);
core.savedObjects.registerType(sampleDataTelemetry);

const router = core.http.createRouter();
registerRoutes(router);

return {
tutorials: { ...this.tutorialsRegistry.setup(core) },
sampleData: { ...this.sampleDataRegistry.setup(core, plugins.usageCollection) },
Expand Down
60 changes: 60 additions & 0 deletions src/plugins/home/server/routes/fetch_es_hits_status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 { schema } from '@kbn/config-schema';
import { IRouter } from 'src/core/server';

export const registerHitsStatusRoute = (router: IRouter) => {
router.post(
{
path: '/api/home/hits_status',
validate: {
body: schema.object({
index: schema.string(),
query: schema.recordOf(schema.string(), schema.any()),
}),
},
},
router.handleLegacyErrors(async (context, req, res) => {
const { index, query } = req.body;
const client = context.core.elasticsearch.client;

try {
const { body } = await client.asCurrentUser.search({
index,
size: 1,
body: {
query,
},
});
const count = body.hits.hits.length;

return res.ok({
body: {
count,
},
});
} catch (e) {
return res.badRequest({
body: e,
});
}
})
);
};
25 changes: 25 additions & 0 deletions src/plugins/home/server/routes/index.ts
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.
*/

import { IRouter } from 'src/core/server';
import { registerHitsStatusRoute } from './fetch_es_hits_status';

export const registerRoutes = (router: IRouter) => {
registerHitsStatusRoute(router);
};
15 changes: 0 additions & 15 deletions x-pack/plugins/canvas/public/__tests__/setup.js

This file was deleted.

Loading

0 comments on commit 78f0897

Please sign in to comment.