@@ -48,6 +48,11 @@ func (m *mockMetadata) OSType() (string, error) {
48
48
return args .String (0 ), args .Error (1 )
49
49
}
50
50
51
+ func (m * mockMetadata ) OSVersion () (string , error ) {
52
+ args := m .MethodCalled ("OSVersion" )
53
+ return args .String (0 ), args .Error (1 )
54
+ }
55
+
51
56
func (m * mockMetadata ) HostID (_ context.Context ) (string , error ) {
52
57
args := m .MethodCalled ("HostID" )
53
58
return args .String (0 ), args .Error (1 )
@@ -147,6 +152,7 @@ func allEnabledConfig() metadata.ResourceAttributesConfig {
147
152
cfg .HostIP .Enabled = true
148
153
cfg .HostMac .Enabled = true
149
154
cfg .OsDescription .Enabled = true
155
+ cfg .OsVersion .Enabled = true
150
156
return cfg
151
157
}
152
158
@@ -155,6 +161,7 @@ func TestDetectFQDNAvailable(t *testing.T) {
155
161
md .On ("FQDN" ).Return ("fqdn" , nil )
156
162
md .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
157
163
md .On ("OSType" ).Return ("darwin" , nil )
164
+ md .On ("OSVersion" ).Return ("22.04.2 LTS (Jammy Jellyfish)" , nil )
158
165
md .On ("HostID" ).Return ("2" , nil )
159
166
md .On ("HostArch" ).Return ("amd64" , nil )
160
167
md .On ("HostIPs" ).Return (testIPsAddresses , nil )
@@ -171,6 +178,7 @@ func TestDetectFQDNAvailable(t *testing.T) {
171
178
conventions .AttributeHostName : "fqdn" ,
172
179
conventions .AttributeOSDescription : "Ubuntu 22.04.2 LTS (Jammy Jellyfish)" ,
173
180
conventions .AttributeOSType : "darwin" ,
181
+ conventions .AttributeOSVersion : "22.04.2 LTS (Jammy Jellyfish)" ,
174
182
conventions .AttributeHostID : "2" ,
175
183
conventions .AttributeHostArch : conventions .AttributeHostArchAMD64 ,
176
184
"host.ip" : testIPsAttribute ,
@@ -186,6 +194,7 @@ func TestFallbackHostname(t *testing.T) {
186
194
mdHostname .On ("FQDN" ).Return ("" , errors .New ("err" ))
187
195
mdHostname .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
188
196
mdHostname .On ("OSType" ).Return ("darwin" , nil )
197
+ mdHostname .On ("OSVersion" ).Return ("22.04.2 LTS (Jammy Jellyfish)" , nil )
189
198
mdHostname .On ("HostArch" ).Return ("amd64" , nil )
190
199
191
200
detector := newTestDetector (mdHostname , []string {"dns" , "os" }, metadata .DefaultResourceAttributesConfig ())
@@ -210,6 +219,7 @@ func TestEnableHostID(t *testing.T) {
210
219
mdHostname .On ("FQDN" ).Return ("" , errors .New ("err" ))
211
220
mdHostname .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
212
221
mdHostname .On ("OSType" ).Return ("darwin" , nil )
222
+ mdHostname .On ("OSVersion" ).Return ("22.04.2 LTS (Jammy Jellyfish)" , nil )
213
223
mdHostname .On ("HostID" ).Return ("3" , nil )
214
224
mdHostname .On ("HostArch" ).Return ("amd64" , nil )
215
225
mdHostname .On ("HostIPs" ).Return (testIPsAddresses , nil )
@@ -225,6 +235,7 @@ func TestEnableHostID(t *testing.T) {
225
235
conventions .AttributeHostName : "hostname" ,
226
236
conventions .AttributeOSDescription : "Ubuntu 22.04.2 LTS (Jammy Jellyfish)" ,
227
237
conventions .AttributeOSType : "darwin" ,
238
+ conventions .AttributeOSVersion : "22.04.2 LTS (Jammy Jellyfish)" ,
228
239
conventions .AttributeHostID : "3" ,
229
240
conventions .AttributeHostArch : conventions .AttributeHostArchAMD64 ,
230
241
"host.ip" : testIPsAttribute ,
@@ -239,6 +250,7 @@ func TestUseHostname(t *testing.T) {
239
250
mdHostname .On ("Hostname" ).Return ("hostname" , nil )
240
251
mdHostname .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
241
252
mdHostname .On ("OSType" ).Return ("darwin" , nil )
253
+ mdHostname .On ("OSVersion" ).Return ("22.04.2 LTS (Jammy Jellyfish)" , nil )
242
254
mdHostname .On ("HostID" ).Return ("1" , nil )
243
255
mdHostname .On ("HostArch" ).Return ("amd64" , nil )
244
256
mdHostname .On ("HostIPs" ).Return (testIPsAddresses , nil )
@@ -254,6 +266,7 @@ func TestUseHostname(t *testing.T) {
254
266
conventions .AttributeHostName : "hostname" ,
255
267
conventions .AttributeOSDescription : "Ubuntu 22.04.2 LTS (Jammy Jellyfish)" ,
256
268
conventions .AttributeOSType : "darwin" ,
269
+ conventions .AttributeOSVersion : "22.04.2 LTS (Jammy Jellyfish)" ,
257
270
conventions .AttributeHostID : "1" ,
258
271
conventions .AttributeHostArch : conventions .AttributeHostArchAMD64 ,
259
272
"host.ip" : testIPsAttribute ,
@@ -268,6 +281,7 @@ func TestDetectError(t *testing.T) {
268
281
mdFQDN := & mockMetadata {}
269
282
mdFQDN .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
270
283
mdFQDN .On ("OSType" ).Return ("windows" , nil )
284
+ mdFQDN .On ("OSVersion" ).Return ("22.04.2 LTS (Jammy Jellyfish)" , nil )
271
285
mdFQDN .On ("FQDN" ).Return ("" , errors .New ("err" ))
272
286
mdFQDN .On ("Hostname" ).Return ("" , errors .New ("err" ))
273
287
mdFQDN .On ("HostID" ).Return ("" , errors .New ("err" ))
@@ -285,6 +299,7 @@ func TestDetectError(t *testing.T) {
285
299
mdHostname := & mockMetadata {}
286
300
mdHostname .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
287
301
mdHostname .On ("OSType" ).Return ("windows" , nil )
302
+ mdHostname .On ("OSVersion" ).Return ("22.04.2 LTS (Jammy Jellyfish)" , nil )
288
303
mdHostname .On ("Hostname" ).Return ("" , errors .New ("err" ))
289
304
mdHostname .On ("HostID" ).Return ("" , errors .New ("err" ))
290
305
mdHostname .On ("HostArch" ).Return ("amd64" , nil )
@@ -302,6 +317,7 @@ func TestDetectError(t *testing.T) {
302
317
mdOSType .On ("FQDN" ).Return ("fqdn" , nil )
303
318
mdOSType .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
304
319
mdOSType .On ("OSType" ).Return ("" , errors .New ("err" ))
320
+ mdOSType .On ("OSVersion" ).Return ("" , "22.04.2 LTS (Jammy Jellyfish)" )
305
321
mdOSType .On ("HostID" ).Return ("1" , nil )
306
322
mdOSType .On ("HostArch" ).Return ("amd64" , nil )
307
323
mdOSType .On ("HostIPs" ).Return (testIPsAddresses , nil )
@@ -312,11 +328,28 @@ func TestDetectError(t *testing.T) {
312
328
assert .Equal (t , "" , schemaURL )
313
329
assert .True (t , internal .IsEmptyResource (res ))
314
330
331
+ // OS version fails
332
+ mdOSVersion := & mockMetadata {}
333
+ mdOSVersion .On ("FQDN" ).Return ("fqdn" , nil )
334
+ mdOSVersion .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
335
+ mdOSVersion .On ("OSType" ).Return ("windows" , nil )
336
+ mdOSVersion .On ("OSVersion" ).Return ("" , errors .New ("err" ))
337
+ mdOSVersion .On ("HostID" ).Return ("1" , nil )
338
+ mdOSVersion .On ("HostArch" ).Return ("amd64" , nil )
339
+ mdOSVersion .On ("HostIPs" ).Return (testIPsAddresses , nil )
340
+
341
+ detector = newTestDetector (mdOSVersion , []string {"os" }, allEnabledConfig ())
342
+ res , schemaURL , err = detector .Detect (context .Background ())
343
+ assert .Error (t , err )
344
+ assert .Equal (t , "" , schemaURL )
345
+ assert .True (t , internal .IsEmptyResource (res ))
346
+
315
347
// Host ID fails. All other attributes should be set.
316
348
mdHostID := & mockMetadata {}
317
349
mdHostID .On ("Hostname" ).Return ("hostname" , nil )
318
350
mdHostID .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
319
351
mdHostID .On ("OSType" ).Return ("linux" , nil )
352
+ mdHostID .On ("OSVersion" ).Return ("22.04.2 LTS (Jammy Jellyfish)" , nil )
320
353
mdHostID .On ("HostID" ).Return ("" , errors .New ("err" ))
321
354
mdHostID .On ("HostArch" ).Return ("arm64" , nil )
322
355
mdHostID .On ("HostIPs" ).Return (testIPsAddresses , nil )
@@ -330,6 +363,7 @@ func TestDetectError(t *testing.T) {
330
363
conventions .AttributeHostName : "hostname" ,
331
364
conventions .AttributeOSDescription : "Ubuntu 22.04.2 LTS (Jammy Jellyfish)" ,
332
365
conventions .AttributeOSType : "linux" ,
366
+ conventions .AttributeOSVersion : "22.04.2 LTS (Jammy Jellyfish)" ,
333
367
conventions .AttributeHostArch : conventions .AttributeHostArchARM64 ,
334
368
"host.ip" : testIPsAttribute ,
335
369
"host.mac" : testMACsAttribute ,
@@ -341,6 +375,7 @@ func TestDetectCPUInfo(t *testing.T) {
341
375
md .On ("FQDN" ).Return ("fqdn" , nil )
342
376
md .On ("OSDescription" ).Return ("Ubuntu 22.04.2 LTS (Jammy Jellyfish)" , nil )
343
377
md .On ("OSType" ).Return ("darwin" , nil )
378
+ md .On ("OSVersion" ).Return ("22.04.2 LTS (Jammy Jellyfish)" , nil )
344
379
md .On ("HostID" ).Return ("2" , nil )
345
380
md .On ("HostArch" ).Return ("amd64" , nil )
346
381
md .On ("HostIPs" ).Return (testIPsAddresses , nil )
@@ -359,6 +394,7 @@ func TestDetectCPUInfo(t *testing.T) {
359
394
conventions .AttributeHostName : "fqdn" ,
360
395
conventions .AttributeOSDescription : "Ubuntu 22.04.2 LTS (Jammy Jellyfish)" ,
361
396
conventions .AttributeOSType : "darwin" ,
397
+ conventions .AttributeOSVersion : "22.04.2 LTS (Jammy Jellyfish)" ,
362
398
conventions .AttributeHostID : "2" ,
363
399
conventions .AttributeHostArch : conventions .AttributeHostArchAMD64 ,
364
400
"host.ip" : testIPsAttribute ,
0 commit comments