Skip to content

Commit f41bb17

Browse files
committed
fix tests
Signed-off-by: alex boten <[email protected]>
1 parent f497165 commit f41bb17

File tree

7 files changed

+124
-272
lines changed

7 files changed

+124
-272
lines changed

otelconf/config_json.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,70 @@ func (j *TraceContextPropagator) UnmarshalJSON(b []byte) error {
122122
return nil
123123
}
124124

125+
// UnmarshalJSON implements json.Unmarshaler.
126+
func (j *ExperimentalContainerResourceDetector) UnmarshalJSON(b []byte) error {
127+
type plain ExperimentalContainerResourceDetector
128+
var p plain
129+
if err := json.Unmarshal(b, &p); err != nil {
130+
return errors.Join(newErrUnmarshal(j), err)
131+
}
132+
// If key is present (even if empty object), ensure non-nil value.
133+
if p == nil {
134+
*j = ExperimentalContainerResourceDetector{}
135+
} else {
136+
*j = ExperimentalContainerResourceDetector(p)
137+
}
138+
return nil
139+
}
140+
141+
// UnmarshalJSON implements json.Unmarshaler.
142+
func (j *ExperimentalHostResourceDetector) UnmarshalJSON(b []byte) error {
143+
type plain ExperimentalHostResourceDetector
144+
var p plain
145+
if err := json.Unmarshal(b, &p); err != nil {
146+
return errors.Join(newErrUnmarshal(j), err)
147+
}
148+
// If key is present (even if empty object), ensure non-nil value.
149+
if p == nil {
150+
*j = ExperimentalHostResourceDetector{}
151+
} else {
152+
*j = ExperimentalHostResourceDetector(p)
153+
}
154+
return nil
155+
}
156+
157+
// UnmarshalJSON implements json.Unmarshaler.
158+
func (j *ExperimentalProcessResourceDetector) UnmarshalJSON(b []byte) error {
159+
type plain ExperimentalProcessResourceDetector
160+
var p plain
161+
if err := json.Unmarshal(b, &p); err != nil {
162+
return errors.Join(newErrUnmarshal(j), err)
163+
}
164+
// If key is present (even if empty object), ensure non-nil value.
165+
if p == nil {
166+
*j = ExperimentalProcessResourceDetector{}
167+
} else {
168+
*j = ExperimentalProcessResourceDetector(p)
169+
}
170+
return nil
171+
}
172+
173+
// UnmarshalJSON implements json.Unmarshaler.
174+
func (j *ExperimentalServiceResourceDetector) UnmarshalJSON(b []byte) error {
175+
type plain ExperimentalServiceResourceDetector
176+
var p plain
177+
if err := json.Unmarshal(b, &p); err != nil {
178+
return errors.Join(newErrUnmarshal(j), err)
179+
}
180+
// If key is present (even if empty object), ensure non-nil value.
181+
if p == nil {
182+
*j = ExperimentalServiceResourceDetector{}
183+
} else {
184+
*j = ExperimentalServiceResourceDetector(p)
185+
}
186+
return nil
187+
}
188+
125189
// UnmarshalJSON implements json.Unmarshaler.
126190
func (j *ExperimentalResourceDetector) UnmarshalJSON(b []byte) error {
127191
// Use a shadow struct with a RawMessage field to detect key presence.
@@ -169,6 +233,7 @@ func (j *ExperimentalResourceDetector) UnmarshalJSON(b []byte) error {
169233
}
170234
sh.Plain.Service = c
171235
}
236+
*j = ExperimentalResourceDetector(sh.Plain)
172237
return nil
173238
}
174239

otelconf/config_test.go

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,6 @@ var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
861861
{Service: ExperimentalServiceResourceDetector{}},
862862
},
863863
},
864-
SchemaUrl: ptr("https://opentelemetry.io/schemas/1.16.0"),
865864
},
866865
TracerProvider: &TracerProviderJson{
867866
TracerConfiguratorDevelopment: &ExperimentalTracerConfigurator{
@@ -2356,26 +2355,47 @@ func TestUnmarshalPullMetricReader(t *testing.T) {
23562355
}
23572356

23582357
func TestUnmarshalResourceJson(t *testing.T) {
2359-
r := ResourceJson{}
2360-
2361-
err := yaml.Unmarshal([]byte("detection/development:\n detectors:\n - container:\n - host:\n - process:\n - service:"), &r)
2362-
require.NoError(t, err)
2363-
require.Equal(t, ResourceJson{
2364-
DetectionDevelopment: &ExperimentalResourceDetection{
2365-
Detectors: []ExperimentalResourceDetector{
2366-
{
2367-
Container: ExperimentalContainerResourceDetector{},
2368-
},
2369-
{
2370-
Host: ExperimentalHostResourceDetector{},
2371-
},
2372-
{
2373-
Process: ExperimentalProcessResourceDetector{},
2374-
},
2375-
{
2376-
Service: ExperimentalServiceResourceDetector{},
2358+
for _, tt := range []struct {
2359+
name string
2360+
yamlConfig []byte
2361+
jsonConfig []byte
2362+
wantErrT error
2363+
wantResource ResourceJson
2364+
}{
2365+
{
2366+
name: "valid with all detectors",
2367+
jsonConfig: []byte(`{"detection/development": {"detectors": [{"container": null},{"host": null},{"process": null},{"service": null}]}}`),
2368+
yamlConfig: []byte("detection/development:\n detectors:\n - container:\n - host:\n - process:\n - service:"),
2369+
wantResource: ResourceJson{
2370+
DetectionDevelopment: &ExperimentalResourceDetection{
2371+
Detectors: []ExperimentalResourceDetector{
2372+
{
2373+
Container: ExperimentalContainerResourceDetector{},
2374+
},
2375+
{
2376+
Host: ExperimentalHostResourceDetector{},
2377+
},
2378+
{
2379+
Process: ExperimentalProcessResourceDetector{},
2380+
},
2381+
{
2382+
Service: ExperimentalServiceResourceDetector{},
2383+
},
2384+
},
23772385
},
23782386
},
23792387
},
2380-
}, r)
2388+
} {
2389+
t.Run(tt.name, func(t *testing.T) {
2390+
r := ResourceJson{}
2391+
err := json.Unmarshal(tt.jsonConfig, &r)
2392+
assert.ErrorIs(t, err, tt.wantErrT)
2393+
assert.Equal(t, tt.wantResource, r)
2394+
2395+
r = ResourceJson{}
2396+
err = yaml.Unmarshal(tt.yamlConfig, &r)
2397+
assert.ErrorIs(t, err, tt.wantErrT)
2398+
assert.Equal(t, tt.wantResource, r)
2399+
})
2400+
}
23812401
}

otelconf/go.mod

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/prometheus/client_golang v1.23.2
77
github.com/prometheus/otlptranslator v1.0.0
88
github.com/stretchr/testify v1.11.1
9-
go.opentelemetry.io/contrib/detectors/autodetect v0.10.0
109
go.opentelemetry.io/otel v1.38.0
1110
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.14.0
1211
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.14.0
@@ -31,80 +30,27 @@ require (
3130
)
3231

3332
require (
34-
cloud.google.com/go/compute/metadata v0.9.0 // indirect
35-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.30.0 // indirect
36-
github.com/aws/aws-sdk-go-v2 v1.38.3 // indirect
37-
github.com/aws/aws-sdk-go-v2/config v1.31.6 // indirect
38-
github.com/aws/aws-sdk-go-v2/credentials v1.18.10 // indirect
39-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.6 // indirect
40-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.6 // indirect
41-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.6 // indirect
42-
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
43-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1 // indirect
44-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.6 // indirect
45-
github.com/aws/aws-sdk-go-v2/service/sso v1.29.1 // indirect
46-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.34.2 // indirect
47-
github.com/aws/aws-sdk-go-v2/service/sts v1.38.2 // indirect
48-
github.com/aws/smithy-go v1.23.0 // indirect
4933
github.com/beorn7/perks v1.0.1 // indirect
50-
github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20221221133751-67e37ae746cd // indirect
5134
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
5235
github.com/cespare/xxhash/v2 v2.3.0 // indirect
5336
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
54-
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
55-
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
5637
github.com/go-logr/logr v1.4.3 // indirect
5738
github.com/go-logr/stdr v1.2.2 // indirect
58-
github.com/go-openapi/jsonpointer v0.21.2 // indirect
59-
github.com/go-openapi/jsonreference v0.21.0 // indirect
60-
github.com/go-openapi/swag v0.23.1 // indirect
61-
github.com/gogo/protobuf v1.3.2 // indirect
62-
github.com/golang/protobuf v1.5.4 // indirect
63-
github.com/google/gnostic-models v0.7.0 // indirect
64-
github.com/google/go-cmp v0.7.0 // indirect
65-
github.com/google/gofuzz v1.2.0 // indirect
6639
github.com/google/uuid v1.6.0 // indirect
6740
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
68-
github.com/josharian/intern v1.0.0 // indirect
69-
github.com/json-iterator/go v1.1.12 // indirect
70-
github.com/mailru/easyjson v0.9.0 // indirect
71-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
72-
github.com/modern-go/reflect2 v1.0.2 // indirect
7341
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
7442
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7543
github.com/prometheus/client_model v0.6.2 // indirect
7644
github.com/prometheus/common v0.67.4 // indirect
7745
github.com/prometheus/procfs v0.19.2 // indirect
78-
github.com/x448/float16 v0.8.4 // indirect
7946
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
80-
go.opentelemetry.io/contrib/detectors/aws/ec2/v2 v2.0.0 // indirect
81-
go.opentelemetry.io/contrib/detectors/aws/ecs v1.38.0 // indirect
82-
go.opentelemetry.io/contrib/detectors/aws/eks v1.38.0 // indirect
83-
go.opentelemetry.io/contrib/detectors/aws/lambda v0.63.0 // indirect
84-
go.opentelemetry.io/contrib/detectors/azure/azurevm v0.10.0 // indirect
85-
go.opentelemetry.io/contrib/detectors/gcp v1.38.0 // indirect
8647
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
8748
go.yaml.in/yaml/v2 v2.4.3 // indirect
8849
golang.org/x/net v0.47.0 // indirect
89-
golang.org/x/oauth2 v0.32.0 // indirect
9050
golang.org/x/sys v0.38.0 // indirect
91-
golang.org/x/term v0.37.0 // indirect
9251
golang.org/x/text v0.31.0 // indirect
93-
golang.org/x/time v0.12.0 // indirect
9452
google.golang.org/genproto/googleapis/api v0.0.0-20251124214823-79d6a2a48846 // indirect
9553
google.golang.org/genproto/googleapis/rpc v0.0.0-20251124214823-79d6a2a48846 // indirect
9654
google.golang.org/protobuf v1.36.10 // indirect
97-
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
98-
gopkg.in/inf.v0 v0.9.1 // indirect
9955
gopkg.in/yaml.v3 v3.0.1 // indirect
100-
k8s.io/api v0.32.4 // indirect
101-
k8s.io/apimachinery v0.32.4 // indirect
102-
k8s.io/client-go v0.32.4 // indirect
103-
k8s.io/klog/v2 v2.130.1 // indirect
104-
k8s.io/kube-openapi v0.0.0-20250701173324-9bd5c66d9911 // indirect
105-
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d // indirect
106-
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
107-
sigs.k8s.io/randfill v1.0.0 // indirect
108-
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
109-
sigs.k8s.io/yaml v1.6.0 // indirect
11056
)

0 commit comments

Comments
 (0)