Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix/number-to-str…
Browse files Browse the repository at this point in the history
…ing-yaml
  • Loading branch information
jen-huang committed Feb 5, 2021
2 parents 37eddc0 + 83e866d commit c4d7ae1
Show file tree
Hide file tree
Showing 268 changed files with 7,017 additions and 2,965 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ target
snapshots.js

!/.eslintrc.js
!.storybook

# plugin overrides
/src/core/lib/kbn_internal_native_observable
Expand Down
22 changes: 21 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,22 @@ module.exports = {

/**
* Enterprise Search overrides
* NOTE: We also have a single rule at the bottom of the file that
* overrides Prettier's default of not linting unnecessary backticks
*/
{
// All files
files: ['x-pack/plugins/enterprise_search/**/*.{ts,tsx}'],
excludedFiles: ['x-pack/plugins/enterprise_search/**/*.{test,mock}.{ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
'react/jsx-boolean-value': ['error', 'never'],
},
},
{
// Source files only - allow `any` in test/mock files
files: ['x-pack/plugins/enterprise_search/**/*.{ts,tsx}'],
excludedFiles: ['x-pack/plugins/enterprise_search/**/*.{test,mock}.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
},
},
Expand Down Expand Up @@ -1260,6 +1270,16 @@ module.exports = {
...require('eslint-config-prettier/@typescript-eslint').rules,
},
},
/**
* Enterprise Search Prettier override
* Lints unnecessary backticks - @see https://github.com/prettier/eslint-config-prettier/blob/main/README.md#forbid-unnecessary-backticks
*/
{
files: ['x-pack/plugins/enterprise_search/**/*.{ts,tsx}'],
rules: {
quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: false }],
},
},

{
files: [
Expand Down
4 changes: 2 additions & 2 deletions docs/developer/architecture/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ To begin plugin development, we recommend reading our overview of how plugins wo
* <<kibana-platform-plugin-api>>

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].
READMEs inside our plugins folders: {kib-repo}tree/{branch}/src/plugins[src/plugins] and
{kib-repo}/tree/{branch}/x-pack/plugins[x-pack/plugins].

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]

Expand Down
18 changes: 0 additions & 18 deletions docs/developer/getting-started/running-kibana-advanced.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@ By default, you can log in with username `elastic` and password
`changeme`. See the `--help` options on `yarn es <command>` if
you’d like to configure a different password.

[discrete]
=== 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
----

[discrete]
=== Unsupported URL Type

Expand Down
4 changes: 2 additions & 2 deletions docs/maps/maps-aggregations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ To enable a blended layer that dynamically shows clusters or documents:

[role="xpack"]
[[maps-top-hits-aggregation]]
=== Top hits per entity
=== Display the most relevant documents per entity

You can display the most relevant documents per entity, for example, the most recent GPS tracks per flight.
Use *Top hits per entity* to display the most relevant documents per entity, for example, the most recent GPS tracks per flight route.
To get this data, {es} first groups your data using a {ref}/search-aggregations-bucket-terms-aggregation.html[terms aggregation],
then accumulates the most relevant documents based on sort order for each entry using a {ref}/search-aggregations-metrics-top-hits-aggregation.html[top hits metric aggregation].

Expand Down
8 changes: 2 additions & 6 deletions docs/setup/docker.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ A list of all published Docker images and tags is available at
https://www.docker.elastic.co[www.docker.elastic.co]. The source code is in
https://github.com/elastic/dockerfiles/tree/{branch}/kibana[GitHub].

These images are free to use under the Elastic license. They contain open source
and free commercial features and access to paid commercial features.
<<managing-licenses,Start a 30-day trial>> to try out all of the
paid commercial features. See the
https://www.elastic.co/subscriptions[Subscriptions] page for information about
Elastic license levels.
These images contain both free and subscription features.
<<managing-licenses,Start a 30-day trial>> to try out all of the features.

[float]
[[pull-image]]
Expand Down
9 changes: 2 additions & 7 deletions docs/user/alerting/geo-alert-types.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
[[geo-alert-types]]
== Geo alert types

experimental[] Two additional stack alerts are available:
<<alert-type-tracking-threshold>> and <<alert-type-tracking-containment>>. To enable,
add the following configuration to your `kibana.yml`:

```yml
xpack.stack_alerts.enableGeoAlerting: true
```
Two additional stack alerts are available:
<<alert-type-tracking-threshold>> and <<alert-type-tracking-containment>>.

As with other stack alerts, you need `all` access to the *Stack Alerts* feature
to be able to create and edit either of the geo alerts.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@elastic/datemath": "link:packages/elastic-datemath",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary",
"@elastic/ems-client": "7.11.0",
"@elastic/eui": "31.3.0",
"@elastic/eui": "31.4.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "^9.0.1-kibana3",
"@elastic/node-crypto": "1.2.1",
Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-legacy-logging/src/utils/get_payload_size.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { createGunzip } from 'zlib';
import mockFs from 'mock-fs';
import { createReadStream } from 'fs';

Expand Down Expand Up @@ -54,6 +55,11 @@ describe('getPayloadSize', () => {
const result = getResponsePayloadBytes(readStream);
expect(result).toBe(Buffer.byteLength(data));
});

test('ignores streams that are not instances of ReadStream', async () => {
const result = getResponsePayloadBytes(createGunzip());
expect(result).toBe(undefined);
});
});

describe('handles plain responses', () => {
Expand All @@ -72,6 +78,11 @@ describe('getPayloadSize', () => {
const result = getResponsePayloadBytes(payload);
expect(result).toBe(JSON.stringify(payload).length);
});

test('returns undefined when source is not plain object', () => {
const result = getResponsePayloadBytes([1, 2, 3]);
expect(result).toBe(undefined);
});
});

describe('handles content-length header', () => {
Expand Down
9 changes: 4 additions & 5 deletions packages/kbn-legacy-logging/src/utils/get_payload_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
* Side Public License, v 1.
*/

import type { ReadStream } from 'fs';
import { isPlainObject } from 'lodash';
import { ReadStream } from 'fs';
import type { ResponseObject } from '@hapi/hapi';

const isBuffer = (obj: unknown): obj is Buffer => Buffer.isBuffer(obj);
const isObject = (obj: unknown): obj is Record<string, unknown> =>
typeof obj === 'object' && obj !== null;
const isFsReadStream = (obj: unknown): obj is ReadStream =>
typeof obj === 'object' && obj !== null && 'bytesRead' in obj;
typeof obj === 'object' && obj !== null && 'bytesRead' in obj && obj instanceof ReadStream;
const isString = (obj: unknown): obj is string => typeof obj === 'string';

/**
Expand Down Expand Up @@ -56,7 +55,7 @@ export function getResponsePayloadBytes(
return Buffer.byteLength(payload);
}

if (isObject(payload)) {
if (isPlainObject(payload)) {
return Buffer.byteLength(JSON.stringify(payload));
}

Expand Down
24 changes: 24 additions & 0 deletions src/core/server/http/logging/get_payload_size.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { createGunzip } from 'zlib';
import type { Request } from '@hapi/hapi';
import Boom from '@hapi/boom';

Expand Down Expand Up @@ -96,6 +97,18 @@ describe('getPayloadSize', () => {

expect(result).toBe(Buffer.byteLength(data));
});

test('ignores streams that are not instances of ReadStream', async () => {
const result = getResponsePayloadBytes(
{
variety: 'stream',
source: createGunzip(),
} as Response,
logger
);

expect(result).toBe(undefined);
});
});

describe('handles plain responses', () => {
Expand Down Expand Up @@ -132,6 +145,17 @@ describe('getPayloadSize', () => {
);
expect(result).toBe(JSON.stringify(payload).length);
});

test('returns undefined when source is not a plain object', () => {
const result = getResponsePayloadBytes(
{
variety: 'plain',
source: [1, 2, 3],
} as Response,
logger
);
expect(result).toBe(undefined);
});
});

describe('handles content-length header', () => {
Expand Down
22 changes: 16 additions & 6 deletions src/core/server/http/logging/get_payload_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Side Public License, v 1.
*/

import type { ReadStream } from 'fs';
import { isPlainObject } from 'lodash';
import { ReadStream } from 'fs';
import { isBoom } from '@hapi/boom';
import type { Request } from '@hapi/hapi';
import { Logger } from '../../logging';
Expand All @@ -17,8 +18,15 @@ const isBuffer = (src: unknown, res: Response): src is Buffer => {
return !isBoom(res) && res.variety === 'buffer' && res.source === src;
};
const isFsReadStream = (src: unknown, res: Response): src is ReadStream => {
return !isBoom(res) && res.variety === 'stream' && res.source === src;
return (
!isBoom(res) &&
res.variety === 'stream' &&
res.source === src &&
res.source instanceof ReadStream
);
};
const isString = (src: unknown, res: Response): src is string =>
!isBoom(res) && res.variety === 'plain' && typeof src === 'string';

/**
* Attempts to determine the size (in bytes) of a Hapi response
Expand Down Expand Up @@ -57,10 +65,12 @@ export function getResponsePayloadBytes(response: Response, log: Logger): number
return response.source.bytesRead;
}

if (response.variety === 'plain') {
return typeof response.source === 'string'
? Buffer.byteLength(response.source)
: Buffer.byteLength(JSON.stringify(response.source));
if (isString(response.source, response)) {
return Buffer.byteLength(response.source);
}

if (response.variety === 'plain' && isPlainObject(response.source)) {
return Buffer.byteLength(JSON.stringify(response.source));
}
} catch (e) {
// We intentionally swallow any errors as this information is
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/dashboard/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = require('@kbn/storybook').defaultConfig;
5 changes: 3 additions & 2 deletions src/plugins/dashboard/.storybook/storyshots.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import fs from 'fs';
Expand Down
Loading

0 comments on commit c4d7ae1

Please sign in to comment.