8
8
"errors"
9
9
"fmt"
10
10
"net"
11
- "strconv"
12
11
"strings"
13
12
14
13
"github.com/shirou/gopsutil/v3/cpu"
@@ -24,12 +23,12 @@ import (
24
23
)
25
24
26
25
var (
27
- hostCPUModelAndFamilyAsStringID = "processor.resourcedetection.hostCPUModelAndFamilyAsString"
28
- hostCPUModelAndFamilyAsStringFeatureGate = featuregate .GlobalRegistry ().MustRegister (
29
- hostCPUModelAndFamilyAsStringID ,
30
- featuregate .StageBeta ,
26
+ _ = featuregate .GlobalRegistry ().MustRegister (
27
+ "processor.resourcedetection.hostCPUModelAndFamilyAsString" ,
28
+ featuregate .StageStable ,
31
29
featuregate .WithRegisterDescription ("Change type of host.cpu.model.id and host.cpu.model.family to string." ),
32
30
featuregate .WithRegisterFromVersion ("v0.89.0" ),
31
+ featuregate .WithRegisterToVersion ("v0.101.0" ),
33
32
featuregate .WithRegisterReferenceURL ("https://github.com/open-telemetry/semantic-conventions/issues/495" ),
34
33
)
35
34
hostCPUSteppingAsStringID = "processor.resourcedetection.hostCPUSteppingAsString"
@@ -154,10 +153,7 @@ func (d *Detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
154
153
d .rb .SetHostMac (hostMACAttribute )
155
154
d .rb .SetOsDescription (osDescription )
156
155
if len (cpuInfo ) > 0 {
157
- err = setHostCPUInfo (d , cpuInfo [0 ])
158
- if err != nil {
159
- d .logger .Warn ("failed to get host cpuinfo" , zap .Error (err ))
160
- }
156
+ setHostCPUInfo (d , cpuInfo [0 ])
161
157
}
162
158
return d .rb .Emit (), conventions .SchemaURL , nil
163
159
}
@@ -201,42 +197,16 @@ func reverseLookupHost(d *Detector) (string, error) {
201
197
return hostname , nil
202
198
}
203
199
204
- func setHostCPUInfo (d * Detector , cpuInfo cpu.InfoStat ) error {
200
+ func setHostCPUInfo (d * Detector , cpuInfo cpu.InfoStat ) {
205
201
d .logger .Debug ("getting host's cpuinfo" , zap .String ("coreID" , cpuInfo .CoreID ))
206
202
d .rb .SetHostCPUVendorID (cpuInfo .VendorID )
207
- if hostCPUModelAndFamilyAsStringFeatureGate .IsEnabled () {
208
- // https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/29025
209
- d .logger .Info ("This attribute changed from int to string. Temporarily switch back to int using the feature gate." ,
210
- zap .String ("attribute" , "host.cpu.family" ),
211
- zap .String ("feature gate" , hostCPUModelAndFamilyAsStringID ),
212
- )
213
- d .rb .SetHostCPUFamily (cpuInfo .Family )
214
- } else {
215
- family , err := strconv .ParseInt (cpuInfo .Family , 10 , 64 )
216
- if err != nil {
217
- return fmt .Errorf ("failed to convert cpuinfo family to integer: %w" , err )
218
- }
219
- d .rb .SetHostCPUFamilyAsInt (family )
220
- }
203
+ d .rb .SetHostCPUFamily (cpuInfo .Family )
221
204
222
205
// For windows, this field is left blank. See https://github.com/shirou/gopsutil/blob/v3.23.9/cpu/cpu_windows.go#L113
223
206
// Skip setting modelId if the field is blank.
224
207
// ISSUE: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27675
225
208
if cpuInfo .Model != "" {
226
- if hostCPUModelAndFamilyAsStringFeatureGate .IsEnabled () {
227
- // https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/29025
228
- d .logger .Info ("This attribute changed from int to string. Temporarily switch back to int using the feature gate." ,
229
- zap .String ("attribute" , "host.cpu.model.id" ),
230
- zap .String ("feature gate" , hostCPUModelAndFamilyAsStringID ),
231
- )
232
- d .rb .SetHostCPUModelID (cpuInfo .Model )
233
- } else {
234
- model , err := strconv .ParseInt (cpuInfo .Model , 10 , 64 )
235
- if err != nil {
236
- return fmt .Errorf ("failed to convert cpuinfo model to integer: %w" , err )
237
- }
238
- d .rb .SetHostCPUModelIDAsInt (model )
239
- }
209
+ d .rb .SetHostCPUModelID (cpuInfo .Model )
240
210
}
241
211
242
212
d .rb .SetHostCPUModelName (cpuInfo .ModelName )
@@ -251,5 +221,4 @@ func setHostCPUInfo(d *Detector, cpuInfo cpu.InfoStat) error {
251
221
d .rb .SetHostCPUSteppingAsInt (int64 (cpuInfo .Stepping ))
252
222
}
253
223
d .rb .SetHostCPUCacheL2Size (int64 (cpuInfo .CacheSize ))
254
- return nil
255
224
}
0 commit comments