Skip to content

Commit

Permalink
Merge branch 'main' into data-stream/retention-period-bug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaStoeva authored Oct 16, 2024
2 parents a719654 + 3d28d17 commit 7609dae
Show file tree
Hide file tree
Showing 82 changed files with 9,091 additions and 518 deletions.
12 changes: 12 additions & 0 deletions oas_docs/output/kibana.serverless.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35266,6 +35266,10 @@ paths:
schema:
nullable: true
type: string
- in: query
name: associatedFilter
schema:
$ref: '#/components/schemas/Security_Timeline_API_AssociatedFilterType'
responses:
'200':
content:
Expand Down Expand Up @@ -49419,6 +49423,14 @@ components:
Security_Osquery_API_VersionOrUndefined:
$ref: '#/components/schemas/Security_Osquery_API_Version'
nullable: true
Security_Timeline_API_AssociatedFilterType:
description: Filter notes based on their association with a document or saved object.
enum:
- document_only
- saved_object_only
- document_and_saved_object
- orphan
type: string
Security_Timeline_API_BareNote:
type: object
properties:
Expand Down
12 changes: 12 additions & 0 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35266,6 +35266,10 @@ paths:
schema:
nullable: true
type: string
- in: query
name: associatedFilter
schema:
$ref: '#/components/schemas/Security_Timeline_API_AssociatedFilterType'
responses:
'200':
content:
Expand Down Expand Up @@ -49419,6 +49423,14 @@ components:
Security_Osquery_API_VersionOrUndefined:
$ref: '#/components/schemas/Security_Osquery_API_Version'
nullable: true
Security_Timeline_API_AssociatedFilterType:
description: Filter notes based on their association with a document or saved object.
enum:
- document_only
- saved_object_only
- document_and_saved_object
- orphan
type: string
Security_Timeline_API_BareNote:
type: object
properties:
Expand Down
12 changes: 12 additions & 0 deletions oas_docs/output/kibana.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38697,6 +38697,10 @@ paths:
schema:
nullable: true
type: string
- in: query
name: associatedFilter
schema:
$ref: '#/components/schemas/Security_Timeline_API_AssociatedFilterType'
responses:
'200':
content:
Expand Down Expand Up @@ -58185,6 +58189,14 @@ components:
Security_Osquery_API_VersionOrUndefined:
$ref: '#/components/schemas/Security_Osquery_API_Version'
nullable: true
Security_Timeline_API_AssociatedFilterType:
description: Filter notes based on their association with a document or saved object.
enum:
- document_only
- saved_object_only
- document_and_saved_object
- orphan
type: string
Security_Timeline_API_BareNote:
type: object
properties:
Expand Down
12 changes: 12 additions & 0 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38697,6 +38697,10 @@ paths:
schema:
nullable: true
type: string
- in: query
name: associatedFilter
schema:
$ref: '#/components/schemas/Security_Timeline_API_AssociatedFilterType'
responses:
'200':
content:
Expand Down Expand Up @@ -58185,6 +58189,14 @@ components:
Security_Osquery_API_VersionOrUndefined:
$ref: '#/components/schemas/Security_Osquery_API_Version'
nullable: true
Security_Timeline_API_AssociatedFilterType:
description: Filter notes based on their association with a document or saved object.
enum:
- document_only
- saved_object_only
- document_and_saved_object
- orphan
type: string
Security_Timeline_API_BareNote:
type: object
properties:
Expand Down
34 changes: 5 additions & 29 deletions packages/kbn-elastic-agent-utils/src/agent_names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,13 @@ export const ELASTIC_AGENT_NAMES: ElasticAgentName[] = [
];

export type OpenTelemetryAgentName =
| 'otlp'
| 'opentelemetry'
| 'opentelemetry/cpp'
| 'opentelemetry/dotnet'
| 'opentelemetry/erlang'
| 'opentelemetry/go'
| 'opentelemetry/java'
| 'opentelemetry/nodejs'
| 'opentelemetry/php'
| 'opentelemetry/python'
| 'opentelemetry/ruby'
| 'opentelemetry/rust'
| 'opentelemetry/swift'
| 'opentelemetry/android'
| 'opentelemetry/webjs'
| 'otlp/cpp'
| 'otlp/dotnet'
| 'otlp/erlang'
| 'otlp/go'
| 'otlp/java'
| 'otlp/nodejs'
| 'otlp/php'
| 'otlp/python'
| 'otlp/ruby'
| 'otlp/rust'
| 'otlp/swift'
| 'otlp/android'
| 'otlp/webjs';
| 'otlp'
| `opentelemetry/${string}`
| `otlp/${string}`;
export const OPEN_TELEMETRY_BASE_AGENT_NAMES: OpenTelemetryAgentName[] = ['otlp', 'opentelemetry'];
export const OPEN_TELEMETRY_AGENT_NAMES: OpenTelemetryAgentName[] = [
'otlp',
'opentelemetry',
...OPEN_TELEMETRY_BASE_AGENT_NAMES,
'opentelemetry/cpp',
'opentelemetry/dotnet',
'opentelemetry/erlang',
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es-types/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ export interface ESQLSearchParams {
query: string;
filter?: unknown;
locale?: string;
include_ccs_metadata?: boolean;
dropNullColumns?: boolean;
params?: Array<Record<string, string | undefined>>;
}
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/parser/__tests__/columns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';

describe('Column Identifier Expressions', () => {
it('can parse un-quoted identifiers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';

describe('commands', () => {
describe('correctly formatted, basic usage', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/parser/__tests__/from.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';

describe('FROM', () => {
describe('correctly formatted', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';
import { Walker } from '../../walker';

describe('function AST nodes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';
import { ESQLFunction, ESQLInlineCast, ESQLSingleAstItem } from '../../types';

describe('Inline cast (::)', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/parser/__tests__/literal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';
import { ESQLLiteral } from '../../types';

describe('literal expression', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/parser/__tests__/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';

describe('METRICS', () => {
describe('correctly formatted', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/parser/__tests__/params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';
import { Walker } from '../../walker';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/parser/__tests__/rename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';

describe('RENAME', () => {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/parser/__tests__/sort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';

describe('SORT', () => {
describe('correctly formatted', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/parser/__tests__/where.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getAstAndSyntaxErrors as parse } from '..';
import { parse } from '..';

describe('WHERE', () => {
describe('correctly formatted', () => {
Expand Down
85 changes: 59 additions & 26 deletions packages/kbn-esql-ast/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,66 @@ export interface ParseResult {
}

export const parse = (text: string | undefined, options: ParseOptions = {}): ParseResult => {
if (text == null) {
const commands: ESQLAstQueryExpression['commands'] = [];
return { ast: commands, root: Builder.expression.query(commands), errors: [], tokens: [] };
try {
if (text == null) {
const commands: ESQLAstQueryExpression['commands'] = [];
return { ast: commands, root: Builder.expression.query(commands), errors: [], tokens: [] };
}
const errorListener = new ESQLErrorListener();
const parseListener = new ESQLAstBuilderListener();
const { tokens, parser } = getParser(
CharStreams.fromString(text),
errorListener,
parseListener
);

parser[GRAMMAR_ROOT_RULE]();

const errors = errorListener.getErrors().filter((error) => {
return !SYNTAX_ERRORS_TO_IGNORE.includes(error.message);
});
const { ast: commands } = parseListener.getAst();
const root = Builder.expression.query(commands, {
location: {
min: 0,
max: text.length - 1,
},
});

if (options.withFormatting) {
const decorations = collectDecorations(tokens);
attachDecorations(root, tokens.tokens, decorations.lines);
}

return { root, ast: commands, errors, tokens: tokens.tokens };
} catch (error) {
/**
* Parsing should never fail, meaning this branch should never execute. But
* if it does fail, we want to log the error message for easier debugging.
*/
// eslint-disable-next-line no-console
console.error(error);

const root = Builder.expression.query();

return {
root,
ast: root.commands,
errors: [
{
startLineNumber: 0,
endLineNumber: 0,
startColumn: 0,
endColumn: 0,
message:
'Parsing internal error: ' +
(!!error && typeof error === 'object' ? String(error.message) : String(error)),
severity: 'error',
},
],
tokens: [],
};
}
const errorListener = new ESQLErrorListener();
const parseListener = new ESQLAstBuilderListener();
const { tokens, parser } = getParser(CharStreams.fromString(text), errorListener, parseListener);

parser[GRAMMAR_ROOT_RULE]();

const errors = errorListener.getErrors().filter((error) => {
return !SYNTAX_ERRORS_TO_IGNORE.includes(error.message);
});
const { ast: commands } = parseListener.getAst();
const root = Builder.expression.query(commands, {
location: {
min: 0,
max: text.length - 1,
},
});

if (options.withFormatting) {
const decorations = collectDecorations(tokens);
attachDecorations(root, tokens.tokens, decorations.lines);
}

return { root, ast: commands, errors, tokens: tokens.tokens };
};

export const parseErrors = (text: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export interface MappedTypes {
mappedTypeWithOneInlineProp: {
[key in 'prop3']: number;
};
mappedTypeWithLiteralTemplates: {
[key in MappedTypeProps | `templated_prop/${string}`]: number;
};
}

export type RecordWithKnownProps = Record<MappedTypeProps, number>;
Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-telemetry-tools/src/tools/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ describe('getDescriptor', () => {
mappedTypeWithOneInlineProp: {
prop3: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
},
mappedTypeWithLiteralTemplates: {
prop1: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
prop2: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
// ideally, it'd be `templated_prop/@@INDEX@@` to be more explicit. But we're going with the fuzzier approach
// for now as it may require more changes downstream that are not worth it.
'@@INDEX@@': { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
},
});
});

Expand Down
11 changes: 8 additions & 3 deletions packages/kbn-telemetry-tools/src/tools/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ export function getConstraints(node: ts.Node, program: ts.Program): any {
return node.literal.text;
}

if (ts.isStringLiteral(node)) {
if (ts.isStringLiteral(node) || ts.isStringLiteralLike(node)) {
return node.text;
}

// template literals such as `smth/${string}`
if (ts.isTemplateLiteralTypeNode(node) || ts.isTemplateExpression(node)) {
return '@@INDEX@@'; // just map it to any kind of string. We can enforce it further in the future if we see fit.
}

if (ts.isImportSpecifier(node) || ts.isExportSpecifier(node)) {
const source = node.getSourceFile();
const importedModuleName = getModuleSpecifier(node);
Expand Down Expand Up @@ -180,9 +185,9 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
const constraintsArray = Array.isArray(constraints) ? constraints : [constraints];
if (typeof constraintsArray[0] === 'string') {
return constraintsArray.reduce((acc, c) => {
(acc as Record<string, unknown>)[c] = descriptor;
acc[c] = descriptor;
return acc;
}, {});
}, {} as Record<string, unknown>);
}
}
return { '@@INDEX@@': descriptor };
Expand Down
Loading

0 comments on commit 7609dae

Please sign in to comment.