Skip to content

Commit

Permalink
Require object_type for object fields (#628)
Browse files Browse the repository at this point in the history
A field of type object without object_type probably assumes that the type should be keyword,
but Fleet is producing invalid mappings (see #624). So better to disallow these mappings to
remove ambiguities.
  • Loading branch information
jsoriano authored Oct 2, 2023
1 parent f022063 commit 2ca9758
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions code/go/pkg/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions spec/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion spec/integration/data_stream/fields/fields.spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -521,11 +524,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
Expand Down
4 changes: 3 additions & 1 deletion test/packages/bad_fields/data_stream/foo/fields/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
type: array
- name: my_custom_date
type: keyword
date_format: yyyy-MM-dd
date_format: yyyy-MM-dd
- name: object_without_object_type.*
type: object
9 changes: 6 additions & 3 deletions test/packages/bad_fields/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
format_version: 2.7.0
format_version: 3.0.0
name: bad_fields
title: "Bad Fields"
version: 0.0.1
Expand All @@ -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
Expand All @@ -30,4 +32,5 @@ policy_templates:
title: Collect sample logs from instances
description: Collecting sample logs
owner:
type: elastic
github: elastic/ecosystem
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,5 @@
type: date
- name: user_provided_metadata
type: object
object_type: keyword
enabled: false

0 comments on commit 2ca9758

Please sign in to comment.