Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
19cfadb
[Streams] Refactor APIs to follow Elasticsearch conventions
simianhacker Dec 17, 2024
ee1004e
Merge branch 'main' of github.com:elastic/kibana into streams/refacto…
simianhacker Dec 18, 2024
af2813c
Fixing security solution missing line ending
simianhacker Dec 18, 2024
236fbda
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Dec 18, 2024
528bc3f
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Dec 18, 2024
4c09c02
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Dec 18, 2024
a2dc69b
Adding FieldDefinitionConfigWithName; refactoring the sample preview …
simianhacker Dec 19, 2024
8a9ff5b
Merge branch 'main' of github.com:elastic/kibana into streams/refacto…
simianhacker Dec 19, 2024
bcec475
more cleanup
simianhacker Dec 19, 2024
c8b9d32
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Dec 19, 2024
e236177
Additional type cleanup
simianhacker Dec 19, 2024
51f97ed
Merge branch 'main' of github.com:elastic/kibana into streams/refacto…
simianhacker Dec 19, 2024
1579521
Fixing duplicate schema
simianhacker Dec 19, 2024
f00910c
moving routing and wired under ingest
simianhacker Dec 19, 2024
534f2ec
Merge branch 'main' of github.com:elastic/kibana into streams/refacto…
simianhacker Dec 19, 2024
bbb2811
removing common/index.ts
simianhacker Dec 19, 2024
ad36456
Merge remote-tracking branch 'upstream/main' into streams/refactor-ap…
flash1293 Dec 20, 2024
e4b7272
fix tests
flash1293 Dec 20, 2024
2651d16
Merge remote-tracking branch 'upstream/main' into streams/refactor-ap…
flash1293 Dec 23, 2024
71cd57a
fix tests
flash1293 Dec 23, 2024
43b377a
make work with otel
flash1293 Dec 23, 2024
045ac92
Add validation
flash1293 Dec 28, 2024
f76893a
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Dec 28, 2024
00df8b8
some fixes
flash1293 Dec 28, 2024
43b12f8
map base otel fields correctly
flash1293 Dec 28, 2024
3a410a7
fix some problems
flash1293 Dec 28, 2024
7e44d7e
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Dec 29, 2024
9b250a8
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Feb 12, 2025
eaac34a
make it work and so on
flash1293 Feb 12, 2025
f1e8230
fix
flash1293 Feb 12, 2025
845ab5e
fix
flash1293 Feb 12, 2025
44db04d
support both
flash1293 Feb 13, 2025
f2127a8
support full list of resource attributes
flash1293 Feb 13, 2025
d43b0e7
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Feb 25, 2025
17eb555
show everything correctly
flash1293 Feb 25, 2025
a820669
clean up lots of things
flash1293 Feb 25, 2025
7570fc0
fix some things and validate more
flash1293 Feb 25, 2025
4f858e4
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Feb 26, 2025
1213399
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 4, 2025
92c28cc
cleanups
flash1293 Mar 4, 2025
d1c0e82
fix stuff
flash1293 Mar 4, 2025
a792e52
fix i18n
flash1293 Mar 4, 2025
8b2af76
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 7, 2025
d1ca8b0
fix stuff
flash1293 Mar 7, 2025
aad3e6b
fix types
flash1293 Mar 7, 2025
afe1010
fix tests and stuff
flash1293 Mar 7, 2025
e6cef2c
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 7, 2025
bd42ae6
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Mar 10, 2025
aac6504
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 11, 2025
564969c
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 12, 2025
1b0393e
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 12, 2025
e71a03f
fix types
flash1293 Mar 12, 2025
fcf5b1f
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 13, 2025
461b9a8
fix tests
flash1293 Mar 13, 2025
294fe55
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 13, 2025
5c8956b
fix stuff
flash1293 Mar 13, 2025
fa84a80
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Mar 21, 2025
a80821d
fix suggestions
flash1293 Mar 21, 2025
5398324
remove stuff
flash1293 Mar 21, 2025
9b7c487
update update yada yada
flash1293 Mar 21, 2025
11b4dd1
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Mar 24, 2025
aa96c98
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Mar 26, 2025
5997ca1
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Mar 28, 2025
eb1c22c
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Apr 1, 2025
a856496
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Apr 2, 2025
2726b3b
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Apr 4, 2025
0721a24
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Apr 8, 2025
bed0d92
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Apr 10, 2025
911fe62
fix test
flash1293 Apr 10, 2025
de047fe
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Apr 11, 2025
33e2202
stuff
flash1293 Apr 11, 2025
b3f6591
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Apr 14, 2025
ffb36cf
fix test
flash1293 Apr 14, 2025
14fd30a
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Apr 14, 2025
d871f3d
fix test
flash1293 Apr 14, 2025
bec2d9e
Merge branch 'flash1293/streams/otel-mode' of github.com:flash1293/ki…
flash1293 Apr 14, 2025
ac76c81
fix test
flash1293 Apr 14, 2025
00c2c3e
fix test
flash1293 Apr 15, 2025
6b0b58e
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 Apr 24, 2025
944c8d7
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 Apr 25, 2025
78f3e66
fix test
flash1293 Apr 25, 2025
dc81aa4
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 May 20, 2025
983b680
fix
flash1293 May 20, 2025
9541631
fix types
flash1293 May 20, 2025
5422652
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 May 20, 2025
8b6342d
fix
flash1293 May 20, 2025
6b39dba
fix type
flash1293 May 20, 2025
3579555
fix test
flash1293 May 20, 2025
2aab871
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 May 21, 2025
a9d54e2
fix some things
flash1293 May 21, 2025
d91a3df
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 May 21, 2025
f516471
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 May 23, 2025
ea7dc9e
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 May 26, 2025
811f39e
fix things
flash1293 May 26, 2025
981237e
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine May 26, 2025
a36ac62
fix typo
flash1293 May 26, 2025
06eff21
Merge branch 'flash1293/streams/otel-mode' of github.com:flash1293/ki…
flash1293 May 26, 2025
89f34fd
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine May 26, 2025
7e2c3d6
Merge branch 'main' into flash1293/streams/otel-mode
flash1293 May 26, 2025
f3097ae
Merge remote-tracking branch 'upstream/main' into flash1293/streams/o…
flash1293 May 27, 2025
3bbb6e5
fix test issues
flash1293 May 27, 2025
8230a44
Merge branch 'flash1293/streams/otel-mode' of github.com:flash1293/ki…
flash1293 May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions x-pack/platform/packages/shared/kbn-streams-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export { type RoutingDefinition, routingDefinitionListSchema } from './src/model
export { type ContentPack, contentPackSchema } from './src/content';

export { isRootStreamDefinition } from './src/helpers/is_root';
export {
keepFields,
namespacePrefixes,
isNamespacedEcsField,
getRegularEcsField,
} from './src/helpers/namespaced_ecs';
export { getAdvancedParameters } from './src/helpers/get_advanced_parameters';
export { getInheritedFieldsFromAncestors } from './src/helpers/get_inherited_fields_from_ancestors';

Expand All @@ -73,6 +79,7 @@ export {
type NamedFieldDefinitionConfig,
type FieldDefinitionConfig,
type InheritedFieldDefinitionConfig,
type InheritedFieldDefinition,
type FieldDefinitionConfigAdvancedParameters,
fieldDefinitionConfigSchema,
namedFieldDefinitionConfigSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const fieldDefinitionSchema: z.Schema<FieldDefinition> = z.record(

export type InheritedFieldDefinitionConfig = FieldDefinitionConfig & {
from: string;
alias_for?: string;
};

export interface InheritedFieldDefinition {
Expand All @@ -70,7 +71,10 @@ export interface InheritedFieldDefinition {

export const inheritedFieldDefinitionSchema: z.Schema<InheritedFieldDefinition> = z.record(
z.string(),
z.intersection(fieldDefinitionConfigSchema, z.object({ from: NonEmptyString }))
z.intersection(
fieldDefinitionConfigSchema,
z.object({ from: NonEmptyString, alias_for: z.optional(NonEmptyString) })
)
);

export type NamedFieldDefinitionConfig = FieldDefinitionConfig & {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.
*/

export const keepFields: string[] = [
'@timestamp',
'observed_timestamp',
'trace_id',
'span_id',
'severity_text',
'body',
'severity_number',
'event_name',
'dropped_attributes_count',
'scope',
'body.text',
'body.structured',
'resource.schema_url',
'resource.dropped_attributes_count',
];

export const aliases: Record<string, string> = {
trace_id: 'trace.id',
span_id: 'span.id',
severity_text: 'log.level',
'body.text': 'message',
};

export const namespacePrefixes = [
'body.structured.',
'attributes.',
'scope.attributes.',
'resource.attributes.',
];

export function getRegularEcsField(field: string): string {
// check whether it starts with a namespace prefix
for (const prefix of namespacePrefixes) {
if (field.startsWith(prefix)) {
return field.slice(prefix.length);
}
}
// check aliases
if (aliases[field]) {
return aliases[field];
}
return field;
}

export function isNamespacedEcsField(field: string): boolean {
return namespacePrefixes.some((prefix) => field.startsWith(prefix)) || keepFields.includes(field);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
* 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.
*/

import { Streams } from '@kbn/streams-schema';
import { generateLayer } from './generate_layer';

describe('generateLayer', () => {
const definition: Streams.WiredStream.Definition = {
name: 'logs.abc',
description: '',
ingest: {
processing: [],
wired: {
routing: [],
fields: {
'@timestamp': { type: 'date', format: 'strict_date_optional_time' },
message: { type: 'match_only_text' },
'attributes.myfield': { type: 'keyword' },
},
},
lifecycle: {
// simulate DSL lifecycle
dsl: { data_retention: '30d' },
},
},
};

it('should generate mappings with proper handling of fields and aliases', () => {
const result = generateLayer('logs.abc', definition, false);
expect(result).toMatchInlineSnapshot(`
Object {
"_meta": Object {
"description": "Default settings for the logs.abc stream",
"managed": true,
},
"name": "logs.abc@stream.layer",
"template": Object {
"lifecycle": Object {
"data_retention": "30d",
"enabled": true,
},
"mappings": Object {
"dynamic": false,
"properties": Object {
"@timestamp": Object {
"format": "strict_date_optional_time",
"ignore_malformed": false,
"type": "date",
},
"attributes.myfield": Object {
"type": "keyword",
},
"message": Object {
"type": "match_only_text",
},
"myfield": Object {
"path": "attributes.myfield",
"type": "alias",
},
},
},
"settings": Object {
"index.lifecycle.name": undefined,
"index.lifecycle.prefer_ilm": false,
},
},
"version": 1,
}
`);
});

it('should generate mappings for root stream', () => {
const result = generateLayer('logs', { ...definition, name: 'logs' }, true);
expect(result).toMatchInlineSnapshot(`
Object {
"_meta": Object {
"description": "Default settings for the logs stream",
"managed": true,
},
"name": "logs@stream.layer",
"template": Object {
"lifecycle": Object {
"data_retention": "30d",
},
"mappings": Object {
"dynamic": false,
"properties": Object {
"@timestamp": Object {
"format": "strict_date_optional_time",
"ignore_malformed": false,
"type": "date",
},
"attributes": Object {
"subobjects": false,
"type": "object",
},
"attributes.myfield": Object {
"type": "keyword",
},
"body": Object {
"properties": Object {
"structured": Object {
"type": "flattened",
},
"text": Object {
"type": "match_only_text",
},
},
"type": "object",
},
"log.level": Object {
"path": "severity_text",
"type": "alias",
},
"message": Object {
"type": "match_only_text",
},
"myfield": Object {
"path": "attributes.myfield",
"type": "alias",
},
"resource": Object {
"properties": Object {
"attributes": Object {
"subobjects": false,
"type": "object",
},
"dropped_attributes_count": Object {
"type": "long",
},
"schema_url": Object {
"ignore_above": 1024,
"type": "keyword",
},
},
"type": "object",
},
"scope": Object {
"properties": Object {
"attributes": Object {
"subobjects": false,
"type": "object",
},
},
"type": "object",
},
"span.id": Object {
"path": "span_id",
"type": "alias",
},
"trace.id": Object {
"path": "trace_id",
"type": "alias",
},
},
},
"settings": Object {
"index": Object {
"codec": "best_compression",
"mapping": Object {
"ignore_malformed": true,
"total_fields": Object {
"ignore_dynamic_beyond_limit": true,
},
},
"mode": "logsdb",
"sort": Object {
"field": Array [
"resource.attributes.host.name",
"@timestamp",
],
"order": Array [
"asc",
"desc",
],
},
},
},
},
"version": 1,
}
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import {
isDslLifecycle,
isIlmLifecycle,
isRoot,
namespacePrefixes,
} from '@kbn/streams-schema';
import { ASSET_VERSION } from '../../../../common/constants';
import { logsSettings } from './logs_layer';
import { getComponentTemplateName } from './name';
import { baseMappings } from './logs_layer';

export function generateLayer(
name: string,
Expand Down Expand Up @@ -50,6 +52,14 @@ export function generateLayer(
}

properties[field] = property;
const matchingPrefix = namespacePrefixes.find((prefix) => field.startsWith(prefix));
if (matchingPrefix) {
const aliasName = field.substring(matchingPrefix.length);
properties[aliasName] = {
type: 'alias',
path: field,
};
}
});

return {
Expand All @@ -58,9 +68,13 @@ export function generateLayer(
lifecycle: getTemplateLifecycle(definition, isServerless),
settings: getTemplateSettings(definition, isServerless),
mappings: {
subobjects: false,
dynamic: false,
properties,
properties: isRoot(name)
? {
...baseMappings,
...properties,
}
: properties,
},
},
version: ASSET_VERSION,
Expand Down
Loading