Skip to content

Commit

Permalink
Do no silently drop unknown schema data (#3743)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Feb 21, 2023
1 parent f78f72d commit de94faf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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)
- Multi-reader `MeterProvider`s now export metrics for all readers, instead of just the first reader. (#3720, #3724)
- 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:

0 comments on commit de94faf

Please sign in to comment.