Skip to content

Commit 5deee3c

Browse files
authored
Fix(Telemetry): remove extra double quotes from machine_type in static_node_count metric (#5947)
1 parent 4270bc2 commit 5deee3c

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

pkg/telemetry/collector.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,10 @@ func getStaticNodeCounts(bp config.Blueprint) string {
289289
return ""
290290
}
291291

292-
// Trimming the curly braces safely extracts our exact format `"g4-standard-48":3,"a3-ultragpu-8g":2`
293-
return strings.Trim(string(counts), "{}")
292+
// Trim the curly braces and remove the double quotes for a cleaner metric.
293+
// Expected return format: "g4-standard-48:3,a3-ultragpu-8g:2"
294+
return strings.ReplaceAll(strings.Trim(string(counts), "{}"), `"`, "")
295+
294296
}
295297

296298
func getOSName() string {

pkg/telemetry/collector_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestCollectMetrics_Extensible(t *testing.T) {
123123
REGION: "us-central1",
124124
ZONE: "us-central1-a",
125125
MACHINE_TYPE: "c2-standard-8",
126-
STATIC_NODE_COUNTS: `"c2-standard-8":1`,
126+
STATIC_NODE_COUNTS: "c2-standard-8:1",
127127
OS_NAME: getOSName(), // Dynamically expect the current OS name
128128
OS_VERSION: getOSVersion(), // Dynamically expect the current OS version
129129
TERRAFORM_VERSION: getTerraformVersion(), // Dynamically expect the current Terraform version
@@ -1857,7 +1857,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
18571857
}},
18581858
}},
18591859
},
1860-
want: `"g4":3`,
1860+
want: "g4:3",
18611861
},
18621862
{
18631863
// 2. Multiple Modules Sharing a Machine Type
@@ -1884,7 +1884,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
18841884
},
18851885
}},
18861886
},
1887-
want: `"c2-standard-8":6`,
1887+
want: "c2-standard-8:6",
18881888
},
18891889
{
18901890
// 3. Multiple Modules with Varying Machine Types
@@ -1911,7 +1911,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
19111911
},
19121912
}},
19131913
},
1914-
want: `"a3u":2,"g4":3`,
1914+
want: "a3u:2,g4:3",
19151915
},
19161916
{
19171917
// 4. Explicit Zero Override
@@ -1929,7 +1929,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
19291929
}},
19301930
}},
19311931
},
1932-
want: ``,
1932+
want: "",
19331933
},
19341934
{
19351935
// 5. Autoscaling Parameters Co-Existing
@@ -1948,7 +1948,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
19481948
}},
19491949
}},
19501950
},
1951-
want: `"n2-standard-2":2`,
1951+
want: "n2-standard-2:2",
19521952
},
19531953
{
19541954
// 6. Inline Slurm Partitions with Inherited Machine Types
@@ -1970,7 +1970,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
19701970
}},
19711971
}},
19721972
},
1973-
want: `"c2-standard-8":5`,
1973+
want: "c2-standard-8:5",
19741974
},
19751975
{
19761976
// 7. Heterogeneous Inline Slurm Partitions
@@ -1997,7 +1997,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
19971997
}},
19981998
}},
19991999
},
2000-
want: `"a2-highgpu-1g":2,"a3-ultragpu-8g":4`,
2000+
want: "a2-highgpu-1g:2,a3-ultragpu-8g:4",
20012001
},
20022002
{
20032003
// 8. Module Missing a Machine Type Definition
@@ -2014,7 +2014,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
20142014
}},
20152015
}},
20162016
},
2017-
want: ``,
2017+
want: "",
20182018
},
20192019
{
20202020
// 9. Unknown or Computed Variables
@@ -2032,7 +2032,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
20322032
}},
20332033
}},
20342034
},
2035-
want: ``,
2035+
want: "",
20362036
},
20372037
{
20382038
// 10. Blueprints with No Compute Instances
@@ -2044,7 +2044,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
20442044
Modules: []config.Module{},
20452045
}},
20462046
},
2047-
want: ``,
2047+
want: "",
20482048
},
20492049
{
20502050
// 11. (Additional) Extraneous Non-Numeric Nested Data
@@ -2069,7 +2069,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
20692069
}},
20702070
}},
20712071
},
2072-
want: `"c2-standard-8":3`,
2072+
want: "c2-standard-8:3",
20732073
},
20742074
{
20752075
// 12. TPU Topology calculation
@@ -2087,7 +2087,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
20872087
}},
20882088
}},
20892089
},
2090-
want: `"ct5lp-hightpu-8t":16`,
2090+
want: "ct5lp-hightpu-8t:16",
20912091
},
20922092
{
20932093
// 13. Multiplier properties (num_node_pools, num_slices)
@@ -2107,7 +2107,7 @@ func TestGetStaticNodeCounts(t *testing.T) {
21072107
}},
21082108
}},
21092109
},
2110-
want: `"n2-standard-4":8`, // 2 * max(3, 4) = 8
2110+
want: "n2-standard-4:8", // 2 * max(3, 4) = 8
21112111
},
21122112
}
21132113

0 commit comments

Comments
 (0)