From 98b77c43a7c60b400234d714c905895e19a48da1 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Tue, 9 Nov 2021 13:34:18 +0100 Subject: [PATCH 1/3] Allow defining an external field as dimension --- code/go/internal/validator/semantic/types.go | 1 + .../internal/validator/semantic/validate_dimensions.go | 5 +++++ .../validator/semantic/validate_dimensions_test.go | 9 +++++++++ .../time_series/data_stream/example/fields/ecs.yml | 3 +++ versions/1/changelog.yml | 3 +++ 5 files changed, 21 insertions(+) create mode 100644 test/packages/time_series/data_stream/example/fields/ecs.yml diff --git a/code/go/internal/validator/semantic/types.go b/code/go/internal/validator/semantic/types.go index 088355805..3f7f9decb 100644 --- a/code/go/internal/validator/semantic/types.go +++ b/code/go/internal/validator/semantic/types.go @@ -23,6 +23,7 @@ type field struct { Unit string `yaml:"unit"` MetricType string `yaml:"metric_type"` Dimension bool `yaml:"dimension"` + External string `yaml:"external"` Fields fields `yaml:"fields"` } diff --git a/code/go/internal/validator/semantic/validate_dimensions.go b/code/go/internal/validator/semantic/validate_dimensions.go index 7f1250030..04e41e56d 100644 --- a/code/go/internal/validator/semantic/validate_dimensions.go +++ b/code/go/internal/validator/semantic/validate_dimensions.go @@ -17,6 +17,11 @@ func ValidateDimensionFields(pkgRoot string) errors.ValidationErrors { } func validateDimensionField(fieldsFile string, f field) errors.ValidationErrors { + if f.External != "" { + // External fields can be used as dimensions, but we cannot resolve + // them at this point, so accept them as they are by now. + return nil + } if f.Dimension && !isAllowedDimensionType(f.Type) { return errors.ValidationErrors{fmt.Errorf(`file "%s" is invalid: field "%s" of type %s can't be a dimension, allowed types for dimensions: %s`, fieldsFile, f.Name, f.Type, strings.Join(allowedDimensionTypes, ", "))} } diff --git a/code/go/internal/validator/semantic/validate_dimensions_test.go b/code/go/internal/validator/semantic/validate_dimensions_test.go index 8bc349fe9..f0d9e6829 100644 --- a/code/go/internal/validator/semantic/validate_dimensions_test.go +++ b/code/go/internal/validator/semantic/validate_dimensions_test.go @@ -69,6 +69,15 @@ func TestValidateDimensionFields(t *testing.T) { }, valid: false, }, + { + title: "external field as dimension should be supported", + field: field{ + Name: "container.id", + External: "ecs", + Dimension: true, + }, + valid: true, + }, } for _, c := range cases { diff --git a/test/packages/time_series/data_stream/example/fields/ecs.yml b/test/packages/time_series/data_stream/example/fields/ecs.yml new file mode 100644 index 000000000..1706e98b6 --- /dev/null +++ b/test/packages/time_series/data_stream/example/fields/ecs.yml @@ -0,0 +1,3 @@ +- name: container.id + external: ecs + dimension: true diff --git a/versions/1/changelog.yml b/versions/1/changelog.yml index 6dc1ce85b..32803f8ff 100644 --- a/versions/1/changelog.yml +++ b/versions/1/changelog.yml @@ -10,6 +10,9 @@ - description: Add support for dimension fields. type: enhancement link: https://github.com/elastic/package-spec/pull/236 + - description: Add support for dimension fields from external sources. + type: enhancement + link: https://github.com/elastic/package-spec/pull/ - version: 1.2.0 changes: - description: Add tag support for elastic export From c95d6783b1a36404b3a81971d29adfe1ebb16c76 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Tue, 9 Nov 2021 13:42:36 +0100 Subject: [PATCH 2/3] Fix changelog --- versions/1/changelog.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions/1/changelog.yml b/versions/1/changelog.yml index 32803f8ff..960bbec21 100644 --- a/versions/1/changelog.yml +++ b/versions/1/changelog.yml @@ -12,7 +12,7 @@ link: https://github.com/elastic/package-spec/pull/236 - description: Add support for dimension fields from external sources. type: enhancement - link: https://github.com/elastic/package-spec/pull/ + link: https://github.com/elastic/package-spec/pull/248 - version: 1.2.0 changes: - description: Add tag support for elastic export From 4f8a8fdce21d2e48f0f998430c3c2241d3023e7f Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Tue, 9 Nov 2021 15:54:08 +0100 Subject: [PATCH 3/3] Mark validation of external dimensions as TODO --- code/go/internal/validator/semantic/validate_dimensions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/go/internal/validator/semantic/validate_dimensions.go b/code/go/internal/validator/semantic/validate_dimensions.go index 04e41e56d..6306d3c35 100644 --- a/code/go/internal/validator/semantic/validate_dimensions.go +++ b/code/go/internal/validator/semantic/validate_dimensions.go @@ -18,7 +18,7 @@ func ValidateDimensionFields(pkgRoot string) errors.ValidationErrors { func validateDimensionField(fieldsFile string, f field) errors.ValidationErrors { if f.External != "" { - // External fields can be used as dimensions, but we cannot resolve + // TODO: External fields can be used as dimensions, but we cannot resolve // them at this point, so accept them as they are by now. return nil }