From d4b42808e57e82993af2fb5060254231a9222e8b Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Mon, 2 Oct 2023 14:07:00 +0200 Subject: [PATCH 1/3] Require object_type for object fields --- code/go/pkg/validator/validator_test.go | 1 + spec/changelog.yml | 3 +++ .../integration/data_stream/fields/fields.spec.yml | 14 ++++++++++++++ .../bad_fields/data_stream/foo/fields/fields.yml | 4 +++- test/packages/bad_fields/manifest.yml | 9 ++++++--- .../transform/metadata_united/fields/fields.yml | 1 + 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/code/go/pkg/validator/validator_test.go b/code/go/pkg/validator/validator_test.go index a1507b896..1607f08e7 100644 --- a/code/go/pkg/validator/validator_test.go +++ b/code/go/pkg/validator/validator_test.go @@ -136,6 +136,7 @@ func TestValidateFile(t *testing.T) { []string{ `field 0.type: 0.type must be one of the following: "aggregate_metric_double", "alias", "histogram", "constant_keyword", "text", "match_only_text", "keyword", "long", "integer", "short", "byte", "double", "float", "half_float", "scaled_float", "date", "date_nanos", "boolean", "binary", "integer_range", "float_range", "long_range", "double_range", "date_range", "ip_range", "group", "geo_point", "object", "ip", "nested", "flattened", "wildcard", "version", "unsigned_long"`, `field "my_custom_date" of type keyword can't set date_format. date_format is allowed for date field type only`, + `field 2: object_type is required`, }, }, "deploy_custom_agent_invalid_property": { diff --git a/spec/changelog.yml b/spec/changelog.yml index 2a571fb09..8c723f24b 100644 --- a/spec/changelog.yml +++ b/spec/changelog.yml @@ -28,6 +28,9 @@ - description: Make exception for legacy input controls type: enhancement link: https://github.com/elastic/package-spec/pull/619 + - description: `object_type` is mandatory when `object: type` is used. + type: bugfix + link: https://github.com/elastic/package-spec/pull/628 - version: 2.13.1-next changes: - description: Prepare for next version diff --git a/spec/integration/data_stream/fields/fields.spec.yml b/spec/integration/data_stream/fields/fields.spec.yml index 3c3a2e02e..7dea99bff 100644 --- a/spec/integration/data_stream/fields/fields.spec.yml +++ b/spec/integration/data_stream/fields/fields.spec.yml @@ -521,11 +521,25 @@ spec: required: - type - object_type + - if: + properties: + type: + const: object + required: + - type + then: + required: + - object_type + required: - name # JSON patches for newer versions should be placed on top versions: + - before: 3.0.0 + patch: + - op: remove + path: "/items/allOf/6" # removing requirement of object_type when type is object - before: 2.10.0 patch: - op: remove diff --git a/test/packages/bad_fields/data_stream/foo/fields/fields.yml b/test/packages/bad_fields/data_stream/foo/fields/fields.yml index 375b25c18..c4351bec7 100644 --- a/test/packages/bad_fields/data_stream/foo/fields/fields.yml +++ b/test/packages/bad_fields/data_stream/foo/fields/fields.yml @@ -2,4 +2,6 @@ type: array - name: my_custom_date type: keyword - date_format: yyyy-MM-dd \ No newline at end of file + date_format: yyyy-MM-dd +- name: object_without_object_type.* + type: object diff --git a/test/packages/bad_fields/manifest.yml b/test/packages/bad_fields/manifest.yml index b7cea1738..030c2e1a3 100644 --- a/test/packages/bad_fields/manifest.yml +++ b/test/packages/bad_fields/manifest.yml @@ -1,4 +1,4 @@ -format_version: 2.7.0 +format_version: 3.0.0 name: bad_fields title: "Bad Fields" version: 0.0.1 @@ -9,8 +9,10 @@ type: integration categories: - custom conditions: - kibana.version: "^8.4.1" - elastic.subscription: "basic" + kibana: + version: "^8.4.1" + elastic: + subscription: "basic" screenshots: - src: /img/sample-screenshot.png title: Sample screenshot @@ -30,4 +32,5 @@ policy_templates: title: Collect sample logs from instances description: Collecting sample logs owner: + type: elastic github: elastic/ecosystem diff --git a/test/packages/good_v3/elasticsearch/transform/metadata_united/fields/fields.yml b/test/packages/good_v3/elasticsearch/transform/metadata_united/fields/fields.yml index df1ad9e80..c54d2ff36 100644 --- a/test/packages/good_v3/elasticsearch/transform/metadata_united/fields/fields.yml +++ b/test/packages/good_v3/elasticsearch/transform/metadata_united/fields/fields.yml @@ -356,4 +356,5 @@ type: date - name: user_provided_metadata type: object + object_type: keyword enabled: false From 78248351f3a4e501f3d0196b615e3df4b307bc54 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Mon, 2 Oct 2023 14:25:13 +0200 Subject: [PATCH 2/3] Fix changelog format --- spec/changelog.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/changelog.yml b/spec/changelog.yml index 8c723f24b..57b8b7c65 100644 --- a/spec/changelog.yml +++ b/spec/changelog.yml @@ -28,7 +28,7 @@ - description: Make exception for legacy input controls type: enhancement link: https://github.com/elastic/package-spec/pull/619 - - description: `object_type` is mandatory when `object: type` is used. + - description: object_type is mandatory when object type is used type: bugfix link: https://github.com/elastic/package-spec/pull/628 - version: 2.13.1-next From 8b5ab453b0ba6dd7967ed24ab922cee29061512b Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Mon, 2 Oct 2023 14:27:43 +0200 Subject: [PATCH 3/3] Update docs --- spec/integration/data_stream/fields/fields.spec.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/integration/data_stream/fields/fields.spec.yml b/spec/integration/data_stream/fields/fields.spec.yml index 7dea99bff..385fa3796 100644 --- a/spec/integration/data_stream/fields/fields.spec.yml +++ b/spec/integration/data_stream/fields/fields.spec.yml @@ -46,11 +46,14 @@ spec: description: > Name of field. Names containing dots are automatically split into sub-fields. + Names with wildcards generate dynamic mappings. type: string pattern: '^[\-*_\/@A-Za-z0-9]+(\.[\-*_\/@A-Za-z0-9]+)*$' type: - description: Datatype of field + description: > + Datatype of field. If the type is set to object, a dynamic mapping is created. In this case, if the name doesn't + contain any wildcard, the wildcard is added as the last segment of the path. type: string enum: - aggregate_metric_double