Skip to content

Commit 7cea04c

Browse files
authored
feat(go server): Add 'string_list' to supported metric types (#825)
1 parent 3481712 commit 7cea04c

10 files changed

+87
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- New lint: Warn against event metrics on the `metrics` or `baseline` ping ([#823](https://github.com/mozilla/glean_parser/pull/823))
6+
- Go server: Add 'string_list' to supported metric types ([#825](https://github.com/mozilla/glean_parser/pull/825))
67

78
## 18.1.1
89

glean_parser/go_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
# Adding a metric here will require updating the `generate_metric_type` function
3434
# and require adjustments to `metrics` variables the the template.
35-
SUPPORTED_METRIC_TYPES = ["string", "quantity", "event", "datetime", "boolean"]
35+
SUPPORTED_METRIC_TYPES = ["string", "quantity", "event", "datetime", "boolean", "string_list"]
3636

3737

3838
def generate_ping_type_name(ping_name: str) -> str:
@@ -68,6 +68,8 @@ def generate_metric_type(metric_type: str) -> str:
6868
return "bool"
6969
elif metric_type == "datetime":
7070
return "time.Time"
71+
elif metric_type == "string_list":
72+
return "[]string"
7173
else:
7274
print("❌ Unable to generate Go type from metric type: " + metric_type)
7375
exit

tests/data/go_server_custom_ping_only_metrics.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ metric:
6666
- TBD
6767
expires: never
6868

69+
request_string_list:
70+
type: string_list
71+
description: >
72+
Test string_list metric
73+
lifetime: application
74+
send_in_pings:
75+
- server-telemetry-scenario-one
76+
notification_emails:
77+
78+
bugs:
79+
- TBD
80+
data_reviews:
81+
- TBD
82+
expires: never
83+
6984
backend:
7085
special_event:
7186
type: event

tests/data/go_server_events_and_custom_ping_metrics.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ metric:
7070
- TBD
7171
expires: never
7272

73+
request_string_list:
74+
type: string_list
75+
description: >
76+
Test string_list metric
77+
lifetime: application
78+
send_in_pings:
79+
- events
80+
- server-telemetry-scenario-one
81+
notification_emails:
82+
83+
bugs:
84+
- TBD
85+
data_reviews:
86+
- TBD
87+
expires: never
88+
7389
backend:
7490
test_event:
7591
type: event

tests/data/go_server_events_only_metrics.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ metric:
6666
- TBD
6767
expires: never
6868

69+
request_string_list:
70+
type: string_list
71+
description: >
72+
Test string_list metric
73+
lifetime: application
74+
send_in_pings:
75+
- events
76+
notification_emails:
77+
78+
bugs:
79+
- TBD
80+
data_reviews:
81+
- TBD
82+
expires: never
83+
6984
backend:
7085
test_event:
7186
type: event

tests/data/go_server_metrics_unsupported.yaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,6 @@ metric:
6060
attribute_two:
6161
type: number
6262

63-
string_list:
64-
type: string_list
65-
description: >
66-
string list
67-
bugs:
68-
- TBD
69-
data_reviews:
70-
- TBD
71-
notification_emails:
72-
73-
lifetime: application
74-
expires: never
75-
send_in_pings:
76-
- events
77-
7863
timespan:
7964
type: timespan
8065
description: >

tests/data/server_custom_ping_only_compare.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ type ServerTelemetryScenarioOnePing struct {
218218
MetricRequestBool bool // boolean
219219
MetricRequestCount int64 // Test quantity metric
220220
MetricRequestDatetime time.Time // Test datetime metric
221+
MetricRequestStringList []string // Test string_list metric
221222
Event ServerTelemetryScenarioOnePingEvent // valid event for this ping
222223
}
223224

@@ -239,6 +240,9 @@ func (g GleanEventsLogger) RecordServerTelemetryScenarioOnePing(
239240
"datetime": {
240241
"metric.request_datetime": params.MetricRequestDatetime.Format("2006-01-02T15:04:05.000Z"),
241242
},
243+
"string_list": {
244+
"metric.request_string_list": params.MetricRequestStringList,
245+
},
242246
}
243247

244248
events := []gleanEvent{}

tests/data/server_events_and_custom_ping_compare.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ type EventsPing struct {
218218
MetricRequestBool bool // boolean
219219
MetricRequestCount int64 // Test quantity metric
220220
MetricRequestDatetime time.Time // Test datetime metric
221+
MetricRequestStringList []string // Test string_list metric
221222
Event EventsPingEvent // valid event for this ping
222223
}
223224

@@ -239,6 +240,9 @@ func (g GleanEventsLogger) RecordEventsPing(
239240
"datetime": {
240241
"metric.request_datetime": params.MetricRequestDatetime.Format("2006-01-02T15:04:05.000Z"),
241242
},
243+
"string_list": {
244+
"metric.request_string_list": params.MetricRequestStringList,
245+
},
242246
}
243247

244248
events := []gleanEvent{}
@@ -260,6 +264,7 @@ type ServerTelemetryScenarioOnePing struct {
260264
MetricRequestBool bool // boolean
261265
MetricRequestCount int64 // Test quantity metric
262266
MetricRequestDatetime time.Time // Test datetime metric
267+
MetricRequestStringList []string // Test string_list metric
263268
}
264269

265270
// Record and submit `server-telemetry-scenario-one` ping
@@ -280,6 +285,9 @@ func (g GleanEventsLogger) RecordServerTelemetryScenarioOnePing(
280285
"datetime": {
281286
"metric.request_datetime": params.MetricRequestDatetime.Format("2006-01-02T15:04:05.000Z"),
282287
},
288+
"string_list": {
289+
"metric.request_string_list": params.MetricRequestStringList,
290+
},
283291
}
284292

285293
events := []gleanEvent{}

tests/data/server_events_only_compare.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ type EventsPing struct {
218218
MetricRequestBool bool // boolean
219219
MetricRequestCount int64 // Test quantity metric
220220
MetricRequestDatetime time.Time // Test datetime metric
221+
MetricRequestStringList []string // Test string_list metric
221222
Event EventsPingEvent // valid event for this ping
222223
}
223224

@@ -239,6 +240,9 @@ func (g GleanEventsLogger) RecordEventsPing(
239240
"datetime": {
240241
"metric.request_datetime": params.MetricRequestDatetime.Format("2006-01-02T15:04:05.000Z"),
241242
},
243+
"string_list": {
244+
"metric.request_string_list": params.MetricRequestStringList,
245+
},
242246
}
243247

244248
events := []gleanEvent{}

tests/test_go_server.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def test_parser_go_server_metrics_unsupported_type(tmp_path, capsys):
4242
"boolean",
4343
"labeled_boolean",
4444
"labeled_string",
45-
"string_list",
4645
"timespan",
4746
"uuid",
4847
"url",
@@ -102,7 +101,7 @@ def test_parser_go_server_events_and_custom_ping(tmp_path):
102101
assert content == compare
103102

104103

105-
def test_parser_go_server_custon_ping_only(tmp_path):
104+
def test_parser_go_server_custom_ping_only(tmp_path):
106105
"""Test that parser works for definitions that only use custom pings"""
107106
translate.translate(
108107
[
@@ -170,10 +169,11 @@ def test_run_logging_events_ping(tmp_path):
170169
IpAddress: "127.0.0.1",
171170
},
172171
glean.EventsPing{
173-
MetricName: "string value",
174-
MetricRequestBool: true,
175-
MetricRequestCount: 10,
176-
MetricRequestDatetime: time.Now(),
172+
MetricName: "string value",
173+
MetricRequestBool: true,
174+
MetricRequestCount: 10,
175+
MetricRequestDatetime: time.Now(),
176+
MetricRequestStringList: []string{"list", "of", "strings"},
177177
Event: glean.BackendTestEventEvent{
178178
EventFieldString: "event extra string value",
179179
EventFieldQuantity: 100,
@@ -227,10 +227,11 @@ def test_run_logging_custom_ping_without_event(tmp_path):
227227
IpAddress: "127.0.0.1",
228228
},
229229
glean.ServerTelemetryScenarioOnePing{
230-
MetricName: "string value",
231-
MetricRequestBool: true,
232-
MetricRequestCount: 20,
233-
MetricRequestDatetime: time.Now(),
230+
MetricName: "string value",
231+
MetricRequestBool: true,
232+
MetricRequestCount: 20,
233+
MetricRequestDatetime: time.Now(),
234+
MetricRequestStringList: []string{"list", "of", "strings"},
234235
},
235236
)
236237
"""
@@ -285,10 +286,11 @@ def test_run_logging_discard_writer(tmp_path):
285286
IpAddress: "127.0.0.1",
286287
},
287288
glean.ServerTelemetryScenarioOnePing{
288-
MetricName: "string value",
289-
MetricRequestBool: true,
290-
MetricRequestCount: 20,
291-
MetricRequestDatetime: time.Now(),
289+
MetricName: "string value",
290+
MetricRequestBool: true,
291+
MetricRequestCount: 20,
292+
MetricRequestDatetime: time.Now(),
293+
MetricRequestStringList: []string{"list", "of", "strings"},
292294
},
293295
)
294296
if err != nil {
@@ -362,10 +364,11 @@ def test_run_logging_custom_ping_with_event(tmp_path):
362364
IpAddress: "127.0.0.1",
363365
},
364366
glean.ServerTelemetryScenarioOnePing{
365-
MetricName: "string value",
366-
MetricRequestBool: true,
367-
MetricRequestCount: 20,
368-
MetricRequestDatetime: time.Now(),
367+
MetricName: "string value",
368+
MetricRequestBool: true,
369+
MetricRequestCount: 20,
370+
MetricRequestDatetime: time.Now(),
371+
MetricRequestStringList: []string{"list", "of", "strings"},
369372
Event: glean.BackendSpecialEventEvent{
370373
EventFieldString: "exta value string",
371374
EventFieldQuantity: 30,

0 commit comments

Comments
 (0)