@@ -17,6 +17,7 @@ import (
17
17
collectorcontribimpl "github.com/DataDog/datadog-agent/comp/otelcol/collector-contrib/impl"
18
18
configstore "github.com/DataDog/datadog-agent/comp/otelcol/configstore/impl"
19
19
converter "github.com/DataDog/datadog-agent/comp/otelcol/converter/impl"
20
+ "github.com/DataDog/datadog-agent/pkg/config/setup"
20
21
"github.com/stretchr/testify/assert"
21
22
"go.opentelemetry.io/collector/confmap/confmaptest"
22
23
"gopkg.in/yaml.v3"
@@ -46,8 +47,11 @@ func TestGetConfDump(t *testing.T) {
46
47
provider , err := converter .NewConverter ()
47
48
assert .NoError (t , err )
48
49
50
+ conf := setup .Datadog ()
51
+
49
52
reqs := Requires {
50
53
CollectorContrib : collectorcontribimpl .NewComponent (),
54
+ Config : conf ,
51
55
URIs : uriFromFile ("simple-dd/config.yaml" ),
52
56
ConfigStore : configstore ,
53
57
Lc : & lifecycle {},
@@ -112,3 +116,81 @@ func TestGetConfDump(t *testing.T) {
112
116
assert .Equal (t , expectedStringMap , actualStringMap )
113
117
})
114
118
}
119
+
120
+ func TestGetConfDumpConverterDisabled (t * testing.T ) {
121
+ configstore , err := configstore .NewConfigStore ()
122
+ assert .NoError (t , err )
123
+
124
+ provider , err := converter .NewConverter ()
125
+ assert .NoError (t , err )
126
+
127
+ conf := setup .Datadog ()
128
+ conf .SetWithoutSource ("otelcollector.converter.enabled" , false )
129
+
130
+ reqs := Requires {
131
+ CollectorContrib : collectorcontribimpl .NewComponent (),
132
+ Config : conf ,
133
+ URIs : uriFromFile ("simple-dd/config.yaml" ),
134
+ ConfigStore : configstore ,
135
+ Lc : & lifecycle {},
136
+ Provider : provider ,
137
+ }
138
+ _ , err = NewComponent (reqs )
139
+ assert .NoError (t , err )
140
+
141
+ t .Run ("provided-string" , func (t * testing.T ) {
142
+ actualString , _ := configstore .GetProvidedConfAsString ()
143
+ actualStringMap , err := yamlBytesToMap ([]byte (actualString ))
144
+ assert .NoError (t , err )
145
+
146
+ expectedBytes , err := os .ReadFile (filepath .Join ("testdata" , "simple-dd" , "config-provided-result.yaml" ))
147
+ assert .NoError (t , err )
148
+ expectedMap , err := yamlBytesToMap (expectedBytes )
149
+ assert .NoError (t , err )
150
+
151
+ assert .Equal (t , expectedMap , actualStringMap )
152
+ })
153
+
154
+ t .Run ("provided-confmap" , func (t * testing.T ) {
155
+ actualConfmap , _ := configstore .GetProvidedConf ()
156
+ // marshal to yaml and then to map to drop the types for comparison
157
+ bytesConf , err := yaml .Marshal (actualConfmap .ToStringMap ())
158
+ assert .NoError (t , err )
159
+ actualStringMap , err := yamlBytesToMap (bytesConf )
160
+ assert .NoError (t , err )
161
+
162
+ expectedMap , err := confmaptest .LoadConf ("testdata/simple-dd/config-provided-result.yaml" )
163
+ expectedStringMap := expectedMap .ToStringMap ()
164
+ assert .NoError (t , err )
165
+
166
+ assert .Equal (t , expectedStringMap , actualStringMap )
167
+ })
168
+
169
+ t .Run ("enhanced-string" , func (t * testing.T ) {
170
+ actualString , _ := configstore .GetEnhancedConfAsString ()
171
+ actualStringMap , err := yamlBytesToMap ([]byte (actualString ))
172
+ assert .NoError (t , err )
173
+
174
+ expectedBytes , err := os .ReadFile (filepath .Join ("testdata" , "simple-dd" , "config-provided-result.yaml" ))
175
+ assert .NoError (t , err )
176
+ expectedMap , err := yamlBytesToMap (expectedBytes )
177
+ assert .NoError (t , err )
178
+
179
+ assert .Equal (t , expectedMap , actualStringMap )
180
+ })
181
+
182
+ t .Run ("enhance-confmap" , func (t * testing.T ) {
183
+ actualConfmap , _ := configstore .GetEnhancedConf ()
184
+ // marshal to yaml and then to map to drop the types for comparison
185
+ bytesConf , err := yaml .Marshal (actualConfmap .ToStringMap ())
186
+ assert .NoError (t , err )
187
+ actualStringMap , err := yamlBytesToMap (bytesConf )
188
+ assert .NoError (t , err )
189
+
190
+ expectedMap , err := confmaptest .LoadConf ("testdata/simple-dd/config-provided-result.yaml" )
191
+ expectedStringMap := expectedMap .ToStringMap ()
192
+ assert .NoError (t , err )
193
+
194
+ assert .Equal (t , expectedStringMap , actualStringMap )
195
+ })
196
+ }
0 commit comments