Skip to content

Commit 3c31c86

Browse files
committed
.
Change-Id: Ieab1fa5f38cdfcb2e7f0de9934bf69f51463ded5
1 parent 2fa16c6 commit 3c31c86

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

pkg/telemetry/collector_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,31 @@ func TestGetMachineCategory(t *testing.T) {
30763076
},
30773077
want: "a100-40gb-1:GPU,v6e-4:TPU",
30783078
},
3079+
{
3080+
name: "Handles memory-optimized machine types correctly as CPU",
3081+
bp: config.Blueprint{
3082+
Groups: []config.Group{
3083+
{
3084+
Name: config.GroupName("primary"),
3085+
Modules: []config.Module{
3086+
{
3087+
ID: config.ModuleID("compute_mem_1"),
3088+
Settings: config.NewDict(map[string]cty.Value{
3089+
"machine_type": cty.StringVal("m1-megamem-96"),
3090+
}),
3091+
},
3092+
{
3093+
ID: config.ModuleID("compute_mem_2"),
3094+
Settings: config.NewDict(map[string]cty.Value{
3095+
"machine_type": cty.StringVal("m2-ultramem-208"),
3096+
}),
3097+
},
3098+
},
3099+
},
3100+
},
3101+
},
3102+
want: "m1-megamem-96:CPU,m2-ultramem-208:CPU",
3103+
},
30793104
{
30803105
name: "Handles unknown machine types mapped to Other",
30813106
bp: config.Blueprint{

pkg/telemetry/collector_util.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,23 @@ func detectMachineCategory(mType string) string {
11041104
}
11051105
}
11061106

1107-
if strings.Contains(mType, "-standard-") || strings.Contains(mType, "-highmem-") || strings.Contains(mType, "-highcpu-") || strings.Contains(mType, "-megamem-") || strings.Contains(mType, "-ultramem-") || strings.Contains(mType, "custom-") {
1107+
if isCPUFallback(mType) {
11081108
return "CPU"
11091109
}
11101110

11111111
return "Other"
11121112
}
1113+
1114+
// isCPUFallback checks if the machine type contains any of the standard CPU identifiers.
1115+
func isCPUFallback(mType string) bool {
1116+
cpuKeywords := []string{
1117+
"-standard-", "-highmem-", "-highcpu-",
1118+
"-megamem-", "-ultramem-", "custom-",
1119+
}
1120+
for _, kw := range cpuKeywords {
1121+
if strings.Contains(mType, kw) {
1122+
return true
1123+
}
1124+
}
1125+
return false
1126+
}

0 commit comments

Comments
 (0)