Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 22 additions & 4 deletions code/go/internal/validator/semantic/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,32 @@ func validateFields(pkgRoot string, validate validateFunc) ve.ValidationErrors {
vErrs = append(vErrs, errors.Wrapf(err, `file "%s" is invalid: can't unmarshal fields`, fieldsFile))
}

for _, u := range unmarshaled {
errs := validate(fieldsFile, u)
errs := validateNestedFields("", fieldsFile, unmarshaled, validate)
if len(errs) > 0 {
vErrs = append(vErrs, errs...)
}
}
return vErrs
}

func validateNestedFields(parent string, fieldsFile string, fields fields, validate validateFunc) ve.ValidationErrors {
var result ve.ValidationErrors
for _, field := range fields {
if len(parent) > 0 {
field.Name = parent + "." + field.Name
}
errs := validate(fieldsFile, field)
if len(errs) > 0 {
result = append(result, errs...)
}
if len(field.Fields) > 0 {
errs := validateNestedFields(field.Name, fieldsFile, field.Fields, validate)
if len(errs) > 0 {
vErrs = append(vErrs, errs...)
result = append(result, errs...)
}
}
}
return vErrs
return result
}

func listFieldsFiles(pkgRoot string) ([]string, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,5 @@ func validateFieldUnit(fieldsFile string, f field) errors.ValidationErrors {
return errors.ValidationErrors{fmt.Errorf(`file "%s" is invalid: field "%s" can't have metric type property'`, fieldsFile, f.Name)}
}

var vErrs errors.ValidationErrors
for _, aField := range f.Fields {
errs := validateFieldUnit(fieldsFile, aField)
if len(errs) > 0 {
vErrs = append(vErrs, errs...)
}
}
return vErrs
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestValidateFieldGroups_Bad(t *testing.T) {

errs := ValidateFieldGroups(pkgRoot)
if assert.Len(t, errs, 3) {
assert.Equal(t, fileError("data_stream/bar/fields/hello-world.yml", `field "bbb" can't have unit property'`), errs[0].Error())
assert.Equal(t, fileError("data_stream/bar/fields/hello-world.yml", `field "eee" can't have unit property'`), errs[1].Error())
assert.Equal(t, fileError("data_stream/bar/fields/hello-world.yml", `field "aaa.bbb" can't have unit property'`), errs[0].Error())
assert.Equal(t, fileError("data_stream/bar/fields/hello-world.yml", `field "ddd.eee" can't have unit property'`), errs[1].Error())
assert.Equal(t, fileError("data_stream/foo/fields/bad-file.yml", `field "fff" can't have metric type property'`), errs[2].Error())
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
- name: example.agent.id
type: keyword
dimension: true
- name: example.agent.call_count
type: long
metric_type: counter
- name: example.agent.current_count
type: long
metric_type: gauge
- name: example.agent.call_duration
type: histogram
metric_type: gauge
dimension: true # This should fail, a histogram cannot be a dimension.
- name: example
type: group
fields:
- name: agent.id
type: keyword
dimension: true
- name: agent.call_count
type: long
metric_type: counter
- name: agent.current_count
type: long
metric_type: gauge
- name: agent.call_duration
type: histogram
metric_type: gauge
dimension: true # This should fail, a histogram cannot be a dimension.
3 changes: 3 additions & 0 deletions versions/1/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
- description: Add kibana/csp-rule-template asset
type: enhancement
link: https://github.com/elastic/package-spec/pull/276
- description: Fix validation of dimension fields inside objects
type: bugfix
link: https://github.com/elastic/package-spec/pull/279
- version: 1.4.1
changes:
- description: ML model file name now matches the id of the model.
Expand Down