You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
Do no silently drop unknown schema data (#3743)
* Do no silently drop unknown schema data * Add entry to changelog * Add PR number to changelog --------- Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com> Co-authored-by: Aaron Clawson <3766680+MadVikingGod@users.noreply.github.com>
This commit is contained in:
@@ -43,6 +43,7 @@ func ParseFile(schemaFilePath string) (*ast.Schema, error) {
|
||||
func Parse(schemaFileContent io.Reader) (*ast.Schema, error) {
|
||||
var ts ast.Schema
|
||||
d := yaml.NewDecoder(schemaFileContent)
|
||||
d.SetStrict(true) // Do not silently drop unknown fields.
|
||||
err := d.Decode(&ts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -167,8 +167,14 @@ func TestParseSchemaFile(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
func TestFailParseSchemaFile(t *testing.T) {
|
||||
func TestFailParseFileUnsupportedFileFormat(t *testing.T) {
|
||||
ts, err := ParseFile("testdata/unsupported-file-format.yaml")
|
||||
assert.Error(t, err)
|
||||
assert.ErrorContains(t, err, "unsupported schema file format minor version number")
|
||||
assert.Nil(t, ts)
|
||||
}
|
||||
|
||||
func TestFailParseFileUnknownField(t *testing.T) {
|
||||
ts, err := ParseFile("testdata/unknown-field.yaml")
|
||||
assert.ErrorContains(t, err, "field Resources not found in type ast.VersionDef")
|
||||
assert.Nil(t, ts)
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
file_format: 1.1.0
|
||||
schema_url: https://opentelemetry.io/schemas/1.1.0
|
||||
|
||||
versions:
|
||||
1.1.0:
|
||||
all: # Valid entry.
|
||||
changes:
|
||||
- rename_attributes:
|
||||
k8s.cluster.name: kubernetes.cluster.name
|
||||
Resources: # Invalid uppercase.
|
||||
changes:
|
||||
- rename_attributes:
|
||||
attribute_map:
|
||||
browser.user_agent: user_agent.original
|
||||
1.0.0:
|
||||
Reference in New Issue
Block a user