-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config: Handle null attributes as invalid #6645
base: main
Are you sure you want to change the base?
config: Handle null attributes as invalid #6645
Conversation
As written the I could see the matrix of property checks growing quite a bit as new properties get added over time - we'd need a check for each attribute or go down the |
@mikeblum, I think that you need to implement |
734f6ec
to
59e15db
Compare
config/testdata/invalid_empty.yaml
Outdated
|
||
resource: | ||
attributes: | ||
- name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attributes:
-
is never reaching (j *AttributeNameValue) UnmarshalYAML
but this diff trips the missing name value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking out loud I would expect something like this to get hit to mimic UnmarshalJSON
func (j *AttributeNameValue) UnmarshalYAML(b []byte) error {
var raw map[string]interface{}
if err := yaml.Unmarshal(b, &raw); err != nil {
return err
}
var name string
var ok bool
if _, ok = raw["name"]; raw != nil && !ok {
return errors.New("field name in AttributeNameValue: required")
}
if name, ok = raw["name"].(string); !ok {
return errors.New("yaml: cannot unmarshal field name in AttributeNameValue must be string")
}
if strings.TrimSpace(name) == "" {
return errors.New("field name in AttributeNameValue: required")
}
if _, ok := raw["value"]; raw != nil && !ok {
return errors.New("field value in AttributeNameValue: required")
}
type Plain AttributeNameValue
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
if plain.Type != nil && plain.Type.Value == "int" {
val, ok := plain.Value.(float64)
if ok {
plain.Value = int(val)
}
}
if plain.Type != nil && plain.Type.Value == "int_array" {
m, ok := plain.Value.([]interface{})
if ok {
var vals []interface{}
for _, v := range m {
val, ok := v.(float64)
if ok {
vals = append(vals, int(val))
} else {
vals = append(vals, val)
}
}
plain.Value = vals
}
}
*j = AttributeNameValue(plain)
return nil
}
config/v0.3.0/config_yaml.go
Outdated
Name: name, | ||
Value: value, | ||
} | ||
if plain.Type != nil && plain.Type.Value == "int" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is breaking the existing tests:
Name: (string) (len=16) "double_array_key",
- Type: (*config.AttributeNameValueType)({
- Value: (string) (len=12) "double_array"
- }),
+ Type: (*config.AttributeNameValueType)(<nil>),
Value: ([]interface {}) (len=2) {
Test: TestParseYAML/valid_v0.3_config
how should the type get resolved here?
59e15db
to
0453451
Compare
} | ||
|
||
// Check for an empty attributes list | ||
if len(aux.Resource.Attributes) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just to demo surfacing an error on an empty resource attributes list. This in effect makes resource attributes required so I don't think this will work.
Fixes #6629
prior art: https://github.com/open-telemetry/opentelemetry-go-contrib/pull/6425/files