Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into fix/baseline-…
Browse files Browse the repository at this point in the history
…metric-inconsistency
  • Loading branch information
spalger committed Mar 2, 2021
2 parents d205869 + 6be9ada commit 06dcc1d
Show file tree
Hide file tree
Showing 83 changed files with 9,557 additions and 2,325 deletions.
2 changes: 2 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ as uiSettings within the code.
|{kib-repo}blob/{branch}/src/plugins/apm_oss/README.asciidoc[apmOss]
|undefined
|{kib-repo}blob/{branch}/src/plugins/bfetch/README.md[bfetch]
|bfetch allows to batch HTTP requests and streams responses back.
Expand Down
45 changes: 7 additions & 38 deletions docs/user/alerting/action-types/jira.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,13 @@ API token (or password):: Jira API authentication token (or password) for HTTP

Jira actions have the following configuration properties:

Subaction:: The subaction to perform: `pushToService`, `getIncident`, `issueTypes`, `fieldsByIssueType`, `issues`, `issue`, or `getFields`.
Subaction params:: The parameters of the subaction.

==== `pushToService` subaction configuration

Incident:: A Jira incident has the following properties:
* `summary` - The title of the issue.
* `description` - A description of the issue.
* `externalId` - The ID of the issue in Jira. If present, the issue is updated. Otherwise, a new issue is created.
* `issueType` - The ID of the issue type in Jira.
* `priority` - The priority level in Jira. Example: `Medium`.
* `labels` - An array of labels. Labels cannot contain spaces.
* `parent` - The parent issue ID or key. Only for subtask issue types.
Comments:: A comment in the form of `{ commentId: string, version: string, comment: string }`.

==== `getIncident` subaction configuration

External ID:: The ID of the issue in Jira.

==== `issueTypes` subaction configuration

The `issueTypes` subaction has no parameters. Provide an empty object `{}`.

==== `fieldsByIssueType` subaction configuration

ID:: The ID of the issue in Jira.

==== `issues` subaction configuration

Title:: The title to search for.

==== `issue` subaction configuration

ID:: The ID of the issue in Jira.

==== `getFields` subaction configuration

The `getFields` subaction has no parameters. Provide an empty object `{}`.
Issue type:: The type of the issue.
Priority:: The priority of the incident.
Labels:: The labels for the incident.
Title:: A title for the issue, used for searching the contents of the knowledge base.
Description:: The details about the incident.
Parent:: The ID or key of the parent issue. Only for `Subtask` issue types.
Additional comments:: Additional information for the client, such as how to troubleshoot the issue.

[[configuring-jira]]
==== Configuring and testing Jira
Expand Down
29 changes: 5 additions & 24 deletions docs/user/alerting/action-types/resilient.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,11 @@ API key secret:: The authentication key secret for HTTP Basic authentication.

IBM Resilient actions have the following configuration properties:

Subaction:: The subaction to perform: `pushToService`, `getFields`, `incidentTypes`, or `severity`.
Subaction params:: The parameters of the subaction.

==== `pushToService` subaction configuration

Incident:: The IBM resilient incident has the following properties:
* `name` - A name for the issue, used for searching the contents of the knowledge base.
* `description` - The details about the incident.
* `externalId` - The ID of the incident in IBM Resilient. If present, the incident is updated. Otherwise, a new incident is created.
* `incidentTypes` - An array with the IDs of IBM Resilient incident types.
* `severityCode` - The IBM Resilient ID of the severity code.
Comments:: A comment in the form of `{ commentId: string, version: string, comment: string }`.

===== `getFields` subaction configuration

The `getFields` subaction has not parameters. Provide an empty object `{}`.

===== `incidentTypes` subaction configuration

The `incidentTypes` subaction has no parameters. Provide an empty object `{}`.

===== `severity` subaction configuration

The `severity` subaction has no parameters. Provide an empty object `{}`.
Incident types:: The type of the incident.
Severity code:: The severity of the incident.
Name:: A name for the issue, used for searching the contents of the knowledge base.
Description:: The details about the incident.
Additional comments:: Additional information for the client, such as how to troubleshoot the issue.

[[configuring-resilient]]
==== Configuring and testing IBM Resilient
Expand Down
33 changes: 6 additions & 27 deletions docs/user/alerting/action-types/servicenow.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,12 @@ Password:: Password for HTTP Basic authentication.

ServiceNow actions have the following configuration properties:

Subaction:: The subaction to perform: `pushToService`, `getFields`, `getIncident`, or `getChoices`.
Subaction params:: The parameters of the subaction.

==== `pushToService` subaction configuration

Incident:: The ServiceNow incident has the following properties:
* `short_description` - A short description for the incident, used for searching the contents of the knowledge base.
* `description` - The details about the incident.
* `externalId` - The ID of the incident in ServiceNow. If present, the incident is updated. Otherwise, a new incident is created.
* `severity` - The severity of the incident.
* `urgency` - The extent to which the incident resolution can delay.
* `impact` - The effect an incident has on business. Can be measured by the number of affected users or by how critical it is to the business in question.
* `category` - The name of the category in ServiceNow.
* `subcategory` - The name of the subcategory in ServiceNow.
Comments:: A comment in the form of `{ commentId: string, version: string, comment: string }`.

===== `getFields` subaction configuration

The `getFields` subaction has no parameters. Provide an empty object `{}`.

===== `getIncident` subaction configuration

External ID:: The ID of the incident in ServiceNow.

===== `getChoices` subaction configuration

Fields:: An array of fields. Example: `[priority, category, impact]`.
Urgency:: The extent to which the incident resolution can delay.
Severity:: The severity of the incident.
Impact:: The effect an incident has on business. Can be measured by the number of affected users or by how critical it is to the business in question.
Short description:: A short description for the incident, used for searching the contents of the knowledge base.
Description:: The details about the incident.
Additional comments:: Additional information for the client, such as how to troubleshoot the issue.

[[configuring-servicenow]]
==== Configuring and testing ServiceNow
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
"@cypress/webpack-preprocessor": "^5.5.0",
"@elastic/apm-rum": "^5.6.1",
"@elastic/apm-rum-react": "^1.2.5",
"@elastic/charts": "25.0.1",
"@elastic/charts": "25.1.0",
"@elastic/eslint-config-kibana": "link:packages/elastic-eslint-config-kibana",
"@elastic/eslint-plugin-eui": "0.0.2",
"@elastic/github-checks-reporter": "0.0.20b3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ function* printPlugins(plugins: Plugins, includes: string[]) {
yield `|{kib-repo}blob/{branch}/${path}[${plugin.id}]`;
}

if (!plugin.relativeReadmePath || plugin.readmeSnippet) {
yield plugin.readmeSnippet ? `|${plugin.readmeSnippet}` : '|WARNING: Missing README.';
yield '';
}
yield plugin.relativeReadmePath === undefined
? '|WARNING: Missing README.'
: `|${plugin.readmeSnippet}`;

yield '';
}
}

Expand Down
106 changes: 76 additions & 30 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,9 +6,10 @@
* Side Public License, v 1.
*/

import { createGunzip } from 'zlib';
import mockFs from 'mock-fs';
import { createReadStream } from 'fs';
import { PassThrough } from 'stream';
import { createGzip, createGunzip } from 'zlib';

import { getResponsePayloadBytes } from './get_payload_size';

Expand All @@ -27,38 +28,74 @@ describe('getPayloadSize', () => {
});
});

describe('handles fs streams', () => {
describe('handles streams', () => {
afterEach(() => mockFs.restore());

test('with ascii characters', async () => {
mockFs({ 'test.txt': 'heya' });
const readStream = createReadStream('test.txt');

let data = '';
for await (const chunk of readStream) {
data += chunk;
}

const result = getResponsePayloadBytes(readStream);
expect(result).toBe(Buffer.byteLength(data));
});

test('with special characters', async () => {
mockFs({ 'test.txt': '¡hola!' });
const readStream = createReadStream('test.txt');

let data = '';
for await (const chunk of readStream) {
data += chunk;
}

const result = getResponsePayloadBytes(readStream);
expect(result).toBe(Buffer.byteLength(data));
test('ignores streams that are not fs or zlib streams', async () => {
const result = getResponsePayloadBytes(new PassThrough());
expect(result).toBe(undefined);
});

test('ignores streams that are not instances of ReadStream', async () => {
const result = getResponsePayloadBytes(createGunzip());
expect(result).toBe(undefined);
describe('fs streams', () => {
test('with ascii characters', async () => {
mockFs({ 'test.txt': 'heya' });
const readStream = createReadStream('test.txt');

let data = '';
for await (const chunk of readStream) {
data += chunk;
}

const result = getResponsePayloadBytes(readStream);
expect(result).toBe(Buffer.byteLength(data));
});

test('with special characters', async () => {
mockFs({ 'test.txt': '¡hola!' });
const readStream = createReadStream('test.txt');

let data = '';
for await (const chunk of readStream) {
data += chunk;
}

const result = getResponsePayloadBytes(readStream);
expect(result).toBe(Buffer.byteLength(data));
});

describe('zlib streams', () => {
test('with ascii characters', async () => {
mockFs({ 'test.txt': 'heya' });
const readStream = createReadStream('test.txt');
const source = readStream.pipe(createGzip()).pipe(createGunzip());

let data = '';
for await (const chunk of source) {
data += chunk;
}

const result = getResponsePayloadBytes(source);

expect(data).toBe('heya');
expect(result).toBe(source.bytesWritten);
});

test('with special characters', async () => {
mockFs({ 'test.txt': '¡hola!' });
const readStream = createReadStream('test.txt');
const source = readStream.pipe(createGzip()).pipe(createGunzip());

let data = '';
for await (const chunk of source) {
data += chunk;
}

const result = getResponsePayloadBytes(source);

expect(data).toBe('¡hola!');
expect(result).toBe(source.bytesWritten);
});
});
});
});

Expand All @@ -79,8 +116,17 @@ describe('getPayloadSize', () => {
expect(result).toBe(JSON.stringify(payload).length);
});

test('when source is array object', () => {
const payload = [{ message: 'hey' }, { message: 'ya' }];
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]);
class TestClass {
constructor() {}
}
const result = getResponsePayloadBytes(new TestClass());
expect(result).toBe(undefined);
});
});
Expand Down
10 changes: 9 additions & 1 deletion packages/kbn-legacy-logging/src/utils/get_payload_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

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

const isBuffer = (obj: unknown): obj is Buffer => Buffer.isBuffer(obj);
const isFsReadStream = (obj: unknown): obj is ReadStream =>
typeof obj === 'object' && obj !== null && 'bytesRead' in obj && obj instanceof ReadStream;
const isZlibStream = (obj: unknown): obj is Zlib => {
return typeof obj === 'object' && obj !== null && 'bytesWritten' in obj;
};
const isString = (obj: unknown): obj is string => typeof obj === 'string';

/**
Expand Down Expand Up @@ -51,11 +55,15 @@ export function getResponsePayloadBytes(
return payload.bytesRead;
}

if (isZlibStream(payload)) {
return payload.bytesWritten;
}

if (isString(payload)) {
return Buffer.byteLength(payload);
}

if (isPlainObject(payload)) {
if (isPlainObject(payload) || Array.isArray(payload)) {
return Buffer.byteLength(JSON.stringify(payload));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { parsedIndexedInterfaceWithNoMatchingSchema } from './parsed_indexed_int
import { parsedNestedCollector } from './parsed_nested_collector';
import { parsedSchemaDefinedWithSpreadsCollector } from './parsed_schema_defined_with_spreads_collector';
import { parsedWorkingCollector } from './parsed_working_collector';
import { parsedCollectorWithDescription } from './parsed_working_collector_with_description';
import { ParsedUsageCollection } from '../ts_parser';

export const allExtractedCollectors: ParsedUsageCollection[] = [
Expand All @@ -22,5 +23,6 @@ export const allExtractedCollectors: ParsedUsageCollection[] = [
parsedIndexedInterfaceWithNoMatchingSchema,
parsedNestedCollector,
parsedSchemaDefinedWithSpreadsCollector,
parsedCollectorWithDescription,
parsedWorkingCollector,
];
Loading

0 comments on commit 06dcc1d

Please sign in to comment.