Skip to content

Commit 51a6aed

Browse files
committed
full metric list with IDs for various tools
1 parent 82d7499 commit 51a6aed

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

internal/api/handler.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const (
115115
paramPriority = "priority"
116116
paramCompat = "compat"
117117
paramYL, paramYH = "yl", "yh" // Y scale range
118+
paramFull = "full"
118119

119120
Version1 = "1"
120121
Version2 = "2"
@@ -287,7 +288,9 @@ type (
287288
}
288289

289290
metricShortInfo struct {
290-
Name string `json:"name"`
291+
Name string `json:"name"`
292+
MetricID int32 `json:"metric_id,omitempty"` // we set to 0 to remove from JSON
293+
Disable bool `json:"disable,omitempty"` // we set to "false" to remove from JSON
291294
}
292295

293296
dashboardShortInfo struct {
@@ -1185,18 +1188,30 @@ func (h *Handler) HandleStatic(w http.ResponseWriter, r *http.Request) {
11851188
}
11861189

11871190
func HandleGetMetricsList(h *httpRequestHandler) {
1191+
full := h.FormValue(paramFull) == "1"
1192+
11881193
resp := &GetMetricsListResp{
11891194
Metrics: []metricShortInfo{},
11901195
}
1191-
for _, m := range format.BuiltinMetrics {
1192-
if !h.showInvisible && m.Disable { // we have invisible builtin metrics
1196+
for _, v := range format.BuiltinMetrics {
1197+
if !h.showInvisible && v.Disable && !full { // we have invisible builtin metrics
11931198
continue
11941199
}
1195-
resp.Metrics = append(resp.Metrics, metricShortInfo{Name: m.Name})
1200+
info := metricShortInfo{Name: v.Name}
1201+
if full {
1202+
info.MetricID = v.MetricID
1203+
info.Disable = v.Disable
1204+
}
1205+
resp.Metrics = append(resp.Metrics, info)
11961206
}
1197-
for _, v := range h.metricsStorage.GetMetaMetricList(h.showInvisible) {
1207+
for _, v := range h.metricsStorage.GetMetaMetricList(h.showInvisible || full) {
11981208
if h.accessInfo.CanViewMetric(*v) {
1199-
resp.Metrics = append(resp.Metrics, metricShortInfo{Name: v.Name})
1209+
info := metricShortInfo{Name: v.Name}
1210+
if full {
1211+
info.MetricID = v.MetricID
1212+
info.Disable = v.Disable
1213+
}
1214+
resp.Metrics = append(resp.Metrics, info)
12001215
}
12011216
}
12021217
sort.Slice(resp.Metrics, func(i int, j int) bool { return resp.Metrics[i].Name < resp.Metrics[j].Name })

internal/api/handler_easyjson.go

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

statshouse-ui/public/openapi/openapi.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@
136136
"/metrics-list": {
137137
"get": {
138138
"description": "Get metrics list",
139-
"parameters": [],
139+
"parameters": [
140+
{
141+
"$ref": "#/components/parameters/paramFull"
142+
}
143+
],
140144
"responses": {
141145
"200": {
142146
"description": "OK",
@@ -664,6 +668,16 @@
664668
]
665669
}
666670
},
671+
"paramFull": {
672+
"name": "full",
673+
"in": "query",
674+
"description": "Full list (with disabled metrics) and IDs) ",
675+
"required": false,
676+
"allowEmptyValue": false,
677+
"schema": {
678+
"type": "string"
679+
}
680+
},
667681
"paramRenderFormat": {
668682
"name": "df",
669683
"in": "query",
@@ -896,6 +910,12 @@
896910
"properties": {
897911
"name": {
898912
"type": "string"
913+
},
914+
"metric_id": {
915+
"type": "number"
916+
},
917+
"disable": {
918+
"type": "boolean"
899919
}
900920
},
901921
"required": [

0 commit comments

Comments
 (0)