mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-30 21:20:04 +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:
parent
f78f72d66c
commit
de94fafd17
@ -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
|
||||
|
||||
|
@ -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
schema/v1.1/testdata/unknown-field.yaml
vendored
Normal file
15
schema/v1.1/testdata/unknown-field.yaml
vendored
Normal file
@ -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:
|
Loading…
Reference in New Issue
Block a user