Skip to content

Commit

Permalink
Merge branch 'master' into migrate-off-karma/canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jul 27, 2020
2 parents 533548e + b15a0a9 commit 7d0018a
Show file tree
Hide file tree
Showing 560 changed files with 11,255 additions and 7,186 deletions.
21 changes: 12 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,19 +771,22 @@ module.exports = {
},

/**
* APM overrides
* APM and Observability overrides
*/
{
files: ['x-pack/plugins/apm/**/*.js'],
files: [
'x-pack/plugins/apm/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/observability/**/*.{js,mjs,ts,tsx}',
],
rules: {
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
'no-console': ['warn', { allow: ['error'] }],
},
},
{
plugins: ['react-hooks'],
files: ['x-pack/plugins/apm/**/*.{ts,tsx}'],
rules: {
'react/function-component-definition': [
'warn',
{
namedComponents: 'function-declaration',
unnamedComponents: 'arrow-function',
},
],
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
'react-hooks/exhaustive-deps': ['error', { additionalHooks: '^useFetcher$' }],
},
Expand Down
6 changes: 5 additions & 1 deletion docs/developer/advanced/running-elasticsearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ This will run a snapshot of {es} that is usually built nightly. Read more about
----
yarn es snapshot
----
By default, two users are added to Elasticsearch:

- A superuser with username: `elastic` and password: `changeme`, which can be used to log into Kibana with.
- A user with username: `kibana_system` and password `changeme`. This account is used by the Kibana server to authenticate itself to Elasticsearch, and to perform certain actions on behalf of the end user. These credentials should be specified in your kibana.yml as described in <<using-kibana-with-security>>

See all available options, like how to specify a specific license, with the `--help` flag.

Expand Down Expand Up @@ -115,4 +119,4 @@ PUT _cluster/settings
}
----

Follow the cross-cluster search instructions for setting up index patterns to search across clusters (<<management-cross-cluster-search>>).
Follow the cross-cluster search instructions for setting up index patterns to search across clusters (<<management-cross-cluster-search>>).
14 changes: 14 additions & 0 deletions docs/maps/trouble-shooting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ image::maps/images/inspector.png[]
[float]
=== Solutions to common problems

[float]
==== Index not listed when adding layer

* Verify your geospatial data is correctly mapped as {ref}/geo-point.html[geo_point] or {ref}/geo-shape.html[geo_shape].
** Run `GET myIndexPatternTitle/_field_caps?fields=myGeoFieldName` in <<console-kibana, Console>>, replacing `myIndexPatternTitle` and `myGeoFieldName` with your index pattern title and geospatial field name.
** Ensure response specifies `type` as `geo_point` or `geo_shape`.
* Verify your geospatial data is correctly mapped in your <<managing-fields, Kibana index pattern>>.
** Open your index pattern in <<management, Stack Management>>.
** Ensure your geospatial field type is `geo_point` or `geo_shape`.
** Ensure your geospatial field is searchable and aggregatable.
** If your geospatial field type does not match your Elasticsearch mapping, click the *Refresh* button to refresh the field list from Elasticsearch.
* Index patterns with thousands of fields can exceed the default maximum payload size.
Increase <<settings, `server.maxPayloadBytes`>> for large index patterns.

[float]
==== Features are not displayed

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
"@types/accept": "3.1.1",
"@types/angular": "^1.6.56",
"@types/angular-mocks": "^1.7.0",
"@types/archiver": "^3.1.0",
"@types/babel__core": "^7.1.2",
"@types/bluebird": "^3.1.1",
"@types/boom": "^7.2.0",
Expand Down Expand Up @@ -398,6 +399,7 @@
"@types/testing-library__react-hooks": "^3.1.0",
"@types/type-detect": "^4.0.1",
"@types/uuid": "^3.4.4",
"@types/vinyl": "^2.0.4",
"@types/vinyl-fs": "^2.4.11",
"@types/zen-observable": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^2.34.0",
Expand Down Expand Up @@ -433,7 +435,7 @@
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.4",
"eslint-plugin-react-perf": "^3.2.3",
"exit-hook": "^2.2.0",
Expand Down Expand Up @@ -474,6 +476,7 @@
"license-checker": "^16.0.0",
"listr": "^0.14.1",
"load-grunt-config": "^3.0.1",
"load-json-file": "^6.2.0",
"mocha": "^7.1.1",
"mock-fs": "^4.12.0",
"mock-http-server": "1.3.0",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"normalize-path": "^3.0.0",
"moment": "^2.24.0",
"rxjs": "^6.5.5",
"strip-ansi": "^6.0.0",
"tree-kill": "^1.2.2",
"tslib": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

export { withProcRunner, ProcRunner } from './proc_runner';
export * from './tooling_log';
export { createAbsolutePathSerializer } from './serializers';
export * from './serializers';
export {
CA_CERT_PATH,
ES_KEY_PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { REPO_ROOT } from '../repo_root';

export function createAbsolutePathSerializer(rootPath: string = REPO_ROOT) {
return {
serialize: (value: string) => value.replace(rootPath, '<absolute path>').replace(/\\/g, '/'),
test: (value: any) => typeof value === 'string' && value.startsWith(rootPath),
serialize: (value: string) => value.replace(rootPath, '<absolute path>').replace(/\\/g, '/'),
};
}
25 changes: 25 additions & 0 deletions packages/kbn-dev-utils/src/serializers/any_instance_serizlizer.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.
*/

export function createAnyInstanceSerializer(Class: Function, name?: string) {
return {
test: (v: any) => v instanceof Class,
serialize: () => `<${name ?? Class.name}>`,
};
}
5 changes: 4 additions & 1 deletion packages/kbn-dev-utils/src/serializers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
* under the License.
*/

export { createAbsolutePathSerializer } from './absolute_path_serializer';
export * from './absolute_path_serializer';
export * from './strip_ansi_serializer';
export * from './recursive_serializer';
export * from './any_instance_serizlizer';
29 changes: 29 additions & 0 deletions packages/kbn-dev-utils/src/serializers/recursive_serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

export function createRecursiveSerializer(test: (v: any) => boolean, print: (v: any) => string) {
return {
test: (v: any) => test(v),
serialize: (v: any, ...rest: any[]) => {
const replacement = print(v);
const printer = rest.pop()!;
return printer(replacement, ...rest);
},
};
}
29 changes: 29 additions & 0 deletions packages/kbn-dev-utils/src/serializers/strip_ansi_serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 stripAnsi from 'strip-ansi';

import { createRecursiveSerializer } from './recursive_serializer';

export function createStripAnsiSerializer() {
return createRecursiveSerializer(
(v) => typeof v === 'string' && stripAnsi(v) !== v,
(v) => stripAnsi(v)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from './run';
export * from './src/index';
1 change: 1 addition & 0 deletions packages/kbn-pm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": [
"./index.d.ts",
"./src/**/*.ts",
"./dist/*.d.ts",
],
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-spec-to-console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ At the root of the Kibana repository, run the following commands:

```sh
# OSS
yarn spec_to_console -g "<ELASTICSEARCH-REPO-FOLDER>/rest-api-spec/src/main/resources/rest-api-spec/api/*" -d "src/plugins/console/server/lib/spec_definitions/json"
yarn spec_to_console -g "<ELASTICSEARCH-REPO-FOLDER>/rest-api-spec/src/main/resources/rest-api-spec/api/*" -d "src/plugins/console/server/lib/spec_definitions/json/generated"

# X-pack
yarn spec_to_console -g "<ELASTICSEARCH-REPO-FOLDER>/x-pack/plugin/src/test/resources/rest-api-spec/api/*" -d "x-pack/plugins/console_extensions/server/lib/spec_definitions/json"
yarn spec_to_console -g "<ELASTICSEARCH-REPO-FOLDER>/x-pack/plugin/src/test/resources/rest-api-spec/api/*" -d "x-pack/plugins/console_extensions/server/lib/spec_definitions/json/generated"
```

### Information used in Console that is not available in the REST spec
Expand Down
30 changes: 22 additions & 8 deletions src/core/server/elasticsearch/client/configure_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,40 @@ describe('configureClient', () => {
});

describe('Client logging', () => {
it('logs error when the client emits an error', () => {
it('logs error when the client emits an @elastic/elasticsearch error', () => {
const client = configureClient(config, { logger, scoped: false });

const response = createApiResponse({ body: {} });
client.emit('response', new errors.TimeoutError('message', response), response);

expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(`
Array [
Array [
"[TimeoutError]: message",
],
]
`);
});

it('logs error when the client emits an ResponseError returned by elasticsearch', () => {
const client = configureClient(config, { logger, scoped: false });

const response = createApiResponse({
statusCode: 400,
headers: {},
body: {
error: {
type: 'error message',
type: 'illegal_argument_exception',
reason: 'request [/_path] contains unrecognized parameter: [name]',
},
},
});
client.emit('response', new errors.ResponseError(response), null);
client.emit('response', new Error('some error'), null);
client.emit('response', new errors.ResponseError(response), response);

expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(`
Array [
Array [
"ResponseError: error message",
],
Array [
"Error: some error",
"[illegal_argument_exception]: request [/_path] contains unrecognized parameter: [name]",
],
]
`);
Expand Down
13 changes: 10 additions & 3 deletions src/core/server/elasticsearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { stringify } from 'querystring';
import { Client } from '@elastic/elasticsearch';
import { Logger } from '../../logging';
import { parseClientOptions, ElasticsearchClientConfig } from './client_config';
import { isResponseError } from './errors';

export const configureClient = (
config: ElasticsearchClientConfig,
Expand All @@ -35,9 +36,15 @@ export const configureClient = (
};

const addLogging = (client: Client, logger: Logger, logQueries: boolean) => {
client.on('response', (err, event) => {
if (err) {
logger.error(`${err.name}: ${err.message}`);
client.on('response', (error, event) => {
if (error) {
const errorMessage =
// error details for response errors provided by elasticsearch
isResponseError(error)
? `[${event.body.error.type}]: ${event.body.error.reason}`
: `[${error.name}]: ${error.message}`;

logger.error(errorMessage);
}
if (event && logQueries) {
const params = event.meta.request.params;
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/elasticsearch/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

export { ElasticsearchClient } from './types';
export * from './types';
export { IScopedClusterClient, ScopedClusterClient } from './scoped_cluster_client';
export { ElasticsearchClientConfig } from './client_config';
export { IClusterClient, ICustomClusterClient, ClusterClient } from './cluster_client';
Expand Down
Loading

0 comments on commit 7d0018a

Please sign in to comment.