Skip to content
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

Do no silently drop unknown schema data #3743

Merged
merged 6 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Ensure `go.opentelemetry.io/otel` does not use generics. (#3723, #3725)
- Remove use of deprecated `"math/rand".Seed` in `go.opentelemetry.io/otel/example/prometheus`. (#3733)
- Do not silently drop unknown schema data with `Parse` in `go.opentelemetry.io/otel/schema/v1.1`. (#3743)

## [1.13.0/0.36.0] 2023-02-07

Expand Down
1 change: 1 addition & 0 deletions schema/v1.1/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions schema/v1.1/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 15 additions & 0 deletions schema/v1.1/testdata/unknown-field.yaml
Original file line number Diff line number Diff line change
@@ -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: