Skip to content

Commit

Permalink
Merge branch 'main' into im/details_page/fix_ilm
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliacech authored Nov 8, 2023
2 parents 2e5fb8e + 3a78410 commit e385871
Show file tree
Hide file tree
Showing 338 changed files with 3,238 additions and 2,951 deletions.
195 changes: 124 additions & 71 deletions .github/CODEOWNERS

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@
"json-stringify-safe": "5.0.1",
"jsonwebtoken": "^9.0.0",
"jsts": "^1.6.2",
"kea": "^2.4.2",
"kea": "^2.6.0",
"langchain": "^0.0.151",
"launchdarkly-js-client-sdk": "^3.1.4",
"launchdarkly-node-server-sdk": "^7.0.3",
Expand Down Expand Up @@ -1276,7 +1276,6 @@
"@storybook/react-docgen-typescript-plugin": "^1.0.1",
"@storybook/testing-react": "^1.3.0",
"@storybook/theming": "^6.5.16",
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,52 @@ describe('MessageConversion', () => {
'\\u001b\\u0000[31mESC-INJECTION-LFUNICODE:\\u001b[32mSUCCESSFUL\\u001b[0m\\u0007\n\nInjecting 10.000 lols 😂\\u001b[10000;b\\u0007'
);
});

test('it should encode/escape ANSI chars lines from the message when not a string', () => {
expect(
MessageConversion.convert(
{
...baseRecord,
// @ts-expect-error message is supposed to be a string
message: {
toString: () => 'toString...\u001b[5;7;6mThis is Fine\u001b[27m',
},
},
false
)
).toEqual('toString...\\u001b[5;7;6mThis is Fine\\u001b[27m');
});

test('it should encode/escape ANSI chars lines from the error stack', () => {
const error = new Error('Something went bad');
error.stack = 'stack...\u001b[5;7;6mThis is Fine\u001b[27m';
expect(
MessageConversion.convert(
{
...baseRecord,
message: 'Some message that will be ignored',
error,
},
false
)
).toEqual('stack...\\u001b[5;7;6mThis is Fine\\u001b[27m');
});

test('it should encode/escape ANSI chars lines from the error stack when not a string', () => {
expect(
MessageConversion.convert(
{
...baseRecord,
message: 'Some message that will be ignored',
error: {
// @ts-expect-error message is supposed to be a string
stack: {
toString: () => 'stackToString...\u001b[5;7;6mThis is Fine\u001b[27m',
},
},
},
false
)
).toEqual('stackToString...\\u001b[5;7;6mThis is Fine\\u001b[27m');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ export const MessageConversion: Conversion = {
pattern: /%message/g,
convert(record: LogRecord) {
// Error stack is much more useful than just the message.
const str = record.error?.stack || record.message;
let str = record.error?.stack || record.message;
// typings may be wrong, there's scenarios where the message is not a plain string (e.g error stacks from the ES client)
if (typeof str !== 'string') {
str = String(str);
}

return typeof str === 'string' // We need to validate it's a string because, despite types, there are use case where it's not a string :/
? str.replace(
CONTROL_CHAR_REGEXP,
// Escaping control chars via JSON.stringify to maintain consistency with `meta` and the JSON layout.
// This way, post analysis of the logs is easier as we can search the same patterns.
// Our benchmark didn't show a big difference in performance between custom-escaping vs. JSON.stringify one.
// The slice is removing the double-quotes.
(substr) => JSON.stringify(substr).slice(1, -1)
)
: str;
return str.replace(
CONTROL_CHAR_REGEXP,
// Escaping control chars via JSON.stringify to maintain consistency with `meta` and the JSON layout.
// This way, post analysis of the logs is easier as we can search the same patterns.
// Our benchmark didn't show a big difference in performance between custom-escaping vs. JSON.stringify one.
// The slice is removing the double-quotes.
(substr) => JSON.stringify(substr).slice(1, -1)
);
},
};
2 changes: 1 addition & 1 deletion packages/deeplinks/observability/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/deeplinks-observability",
"owner": "@elastic/apm-ui"
"owner": "@elastic/obs-ux-logs-team"
}
2 changes: 1 addition & 1 deletion packages/kbn-apm-synthtrace-client/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"type": "shared-common",
"id": "@kbn/apm-synthtrace-client",
"devOnly": true,
"owner": "@elastic/apm-ui"
"owner": "@elastic/obs-ux-infra_services-team"
}
2 changes: 1 addition & 1 deletion packages/kbn-apm-synthtrace/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"type": "shared-server",
"id": "@kbn/apm-synthtrace",
"devOnly": true,
"owner": "@elastic/apm-ui"
"owner": "@elastic/obs-ux-infra_services-team"
}
2 changes: 1 addition & 1 deletion packages/kbn-apm-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/apm-utils",
"owner": "@elastic/apm-ui"
"owner": "@elastic/obs-ux-infra_services-team"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
EuiDataGridRefProps,
type EuiDataGridColumnCellAction,
} from '@elastic/eui';
import { render, waitFor } from '@testing-library/react';
import { act, renderHook } from '@testing-library/react-hooks';
import { render, waitFor, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import { makeAction } from '../mocks/helpers';
import {
useDataGridColumnsCellActions,
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-custom-integrations/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/custom-integrations",
"owner": "@elastic/infra-monitoring-ui"
"owner": "@elastic/obs-ux-logs-team"
}
2 changes: 1 addition & 1 deletion packages/kbn-es-types/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/es-types",
"owner": ["@elastic/kibana-core", "@elastic/apm-ui"]
"owner": ["@elastic/kibana-core", "@elastic/obs-knowledge-team"]
}
2 changes: 1 addition & 1 deletion packages/kbn-eslint-plugin-i18n/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "shared-common",
"id": "@kbn/eslint-plugin-i18n",
"owner": "@elastic/actionable-observability",
"owner": "@elastic/obs-knowledge-team",
"devOnly": true
}
2 changes: 1 addition & 1 deletion packages/kbn-eslint-plugin-telemetry/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "shared-common",
"id": "@kbn/eslint-plugin-telemetry",
"owner": "@elastic/actionable-observability",
"owner": "@elastic/obs-knowledge-team",
"devOnly": true
}
2 changes: 1 addition & 1 deletion packages/kbn-io-ts-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/io-ts-utils",
"owner": "@elastic/apm-ui"
"owner": "@elastic/obs-knowledge-team"
}
2 changes: 1 addition & 1 deletion packages/kbn-lens-embeddable-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-browser",
"id": "@kbn/lens-embeddable-utils",
"owner": "@elastic/infra-monitoring-ui"
"owner": "@elastic/obs-ux-infra_services-team"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { z } from "zod";
import { requiredOptional, isValidDateMath } from "@kbn/zod-helpers"
import { requiredOptional, isValidDateMath, ArrayFromString, BooleanFromString } from "@kbn/zod-helpers"

{{> disclaimer}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,17 @@
{{~/if~}}

{{~#if (eq type "array")}}
z.preprocess(
(value: unknown) => (typeof value === "string") ? value === '' ? [] : value.split(",") : value,
z.array({{~> zod_schema_item items ~}})
)
ArrayFromString({{~> zod_schema_item items ~}})
{{~#if minItems}}.min({{minItems}}){{/if~}}
{{~#if maxItems}}.max({{maxItems}}){{/if~}}
{{~#if (eq requiredBool false)}}.optional(){{/if~}}
{{~#if (defined default)}}.default({{{toJSON default}}}){{/if~}}
{{~/if~}}

{{~#if (eq type "boolean")}}
z.preprocess(
(value: unknown) => (typeof value === "boolean") ? String(value) : value,
z.enum(["true", "false"])
{{~#if (defined default)}}.default("{{{toJSON default}}}"){{/if~}}
.transform((value) => value === "true")
)
BooleanFromString
{{~#if (eq requiredBool false)}}.optional(){{/if~}}
{{~#if (defined default)}}.default({{{toJSON default}}}){{/if~}}
{{~/if~}}

{{~#if (eq type "string")}}
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-profiling-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/profiling-utils",
"owner": "@elastic/profiling-ui"
"owner": "@elastic/obs-ux-infra_services-team"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jest.mock('@elastic/eui', () => ({
}));

import * as eui from '@elastic/eui';
import { waitFor } from '@testing-library/dom';
import { waitFor } from '@testing-library/react';
import { ResizableLayoutDirection } from '../types';

describe('Panels resizable', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-rule-data-utils/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "@kbn/rule-data-utils",
"owner": [
"@elastic/security-detections-response",
"@elastic/actionable-observability",
"@elastic/response-ops"
"@elastic/response-ops",
"@elastic/obs-ux-management-team"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { waitFor } from '@testing-library/dom';
import { waitFor } from '@testing-library/react';
import { act, renderHook } from '@testing-library/react-hooks';
import { useExceptionListHeader } from './use_list_header';

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-server-route-repository/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/server-route-repository",
"owner": "@elastic/apm-ui"
"owner": ["@elastic/obs-knowledge-team", "@elastic/obs-ux-management-team"]
}
2 changes: 1 addition & 1 deletion packages/kbn-shared-svg/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/shared-svg",
"owner": "@elastic/apm-ui"
"owner": "@elastic/obs-ux-infra_services-team"
}
2 changes: 1 addition & 1 deletion packages/kbn-typed-react-router-config/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/typed-react-router-config",
"owner": "@elastic/apm-ui"
"owner": ["@elastic/obs-knowledge-team", "@elastic/obs-ux-management-team"]
}
2 changes: 1 addition & 1 deletion packages/kbn-use-tracked-promise/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/use-tracked-promise",
"owner": "@elastic/infra-monitoring-ui"
"owner": "@elastic/obs-ux-logs-team"
}
2 changes: 1 addition & 1 deletion packages/kbn-xstate-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/xstate-utils",
"owner": "@elastic/infra-monitoring-ui"
"owner": "@elastic/obs-ux-logs-team"
}
3 changes: 3 additions & 0 deletions packages/kbn-zod-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
* Side Public License, v 1.
*/

export * from './src/array_from_string';
export * from './src/boolean_from_string';
export * from './src/expect_parse_error';
export * from './src/expect_parse_success';
export * from './src/is_valid_date_math';
export * from './src/required_optional';
export * from './src/safe_parse_result';
export * from './src/stringify_zod_error';
34 changes: 34 additions & 0 deletions packages/kbn-zod-helpers/src/array_from_string.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 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 { ArrayFromString } from './array_from_string';
import * as z from 'zod';

describe('ArrayFromString', () => {
const itemsSchema = z.string();

it('should return an array when input is a string', () => {
const result = ArrayFromString(itemsSchema).parse('a,b,c');
expect(result).toEqual(['a', 'b', 'c']);
});

it('should return an empty array when input is an empty string', () => {
const result = ArrayFromString(itemsSchema).parse('');
expect(result).toEqual([]);
});

it('should return the input as is when it is not a string', () => {
const input = ['a', 'b', 'c'];
const result = ArrayFromString(itemsSchema).parse(input);
expect(result).toEqual(input);
});

it('should throw an error when input is not a string or an array', () => {
expect(() => ArrayFromString(itemsSchema).parse(123)).toThrow();
});
});
24 changes: 24 additions & 0 deletions packages/kbn-zod-helpers/src/array_from_string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 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 * as z from 'zod';

/**
* This is a helper schema to convert comma separated strings to arrays. Useful
* for processing query params.
*
* @param schema Array items schema
* @returns Array schema that accepts a comma-separated string as input
*/
export function ArrayFromString<T extends z.ZodTypeAny>(schema: T) {
return z.preprocess(
(value: unknown) =>
typeof value === 'string' ? (value === '' ? [] : value.split(',')) : value,
z.array(schema)
);
}
32 changes: 32 additions & 0 deletions packages/kbn-zod-helpers/src/boolean_from_string.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 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 { BooleanFromString } from './boolean_from_string';

describe('BooleanFromString', () => {
it('should return true when input is "true"', () => {
expect(BooleanFromString.parse('true')).toBe(true);
});

it('should return false when input is "false"', () => {
expect(BooleanFromString.parse('false')).toBe(false);
});

it('should return true when input is true', () => {
expect(BooleanFromString.parse(true)).toBe(true);
});

it('should return false when input is false', () => {
expect(BooleanFromString.parse(false)).toBe(false);
});

it('should throw an error when input is not a boolean or "true" or "false"', () => {
expect(() => BooleanFromString.parse('not a boolean')).toThrow();
expect(() => BooleanFromString.parse(42)).toThrow();
});
});
Loading

0 comments on commit e385871

Please sign in to comment.