mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2024-12-27 01:09:05 +01:00
api: return errors via JSON, not status codes
This commit is contained in:
parent
024f66f49c
commit
1c12c655f1
32
api.go
32
api.go
@ -30,18 +30,20 @@ type ApiRequestBody struct {
|
||||
}
|
||||
|
||||
type ApiMetricData struct {
|
||||
From int64 `json:"from"`
|
||||
To int64 `json:"to"`
|
||||
Data []Float `json:"data"`
|
||||
Error *string `json:"error"`
|
||||
From int64 `json:"from"`
|
||||
To int64 `json:"to"`
|
||||
Data []Float `json:"data"`
|
||||
}
|
||||
|
||||
type ApiStatsData struct {
|
||||
From int64 `json:"from"`
|
||||
To int64 `json:"to"`
|
||||
Samples int `json:"samples"`
|
||||
Avg Float `json:"avg"`
|
||||
Min Float `json:"min"`
|
||||
Max Float `json:"max"`
|
||||
Error *string `json:"error"`
|
||||
From int64 `json:"from"`
|
||||
To int64 `json:"to"`
|
||||
Samples int `json:"samples"`
|
||||
Avg Float `json:"avg"`
|
||||
Min Float `json:"min"`
|
||||
Max Float `json:"max"`
|
||||
}
|
||||
|
||||
func handleTimeseries(rw http.ResponseWriter, r *http.Request) {
|
||||
@ -76,8 +78,10 @@ func handleTimeseries(rw http.ResponseWriter, r *http.Request) {
|
||||
for _, metric := range reqBody.Metrics {
|
||||
data, f, t, err := memoryStore.Read(selector, metric, from, to)
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
// http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
msg := err.Error()
|
||||
metrics[metric] = ApiMetricData{ Error: &msg }
|
||||
continue
|
||||
}
|
||||
|
||||
metrics[metric] = ApiMetricData{
|
||||
@ -128,8 +132,10 @@ func handleStats(rw http.ResponseWriter, r *http.Request) {
|
||||
for _, metric := range reqBody.Metrics {
|
||||
stats, f, t, err := memoryStore.Stats(selector, metric, from, to)
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
// http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
msg := err.Error()
|
||||
metrics[metric] = ApiStatsData{ Error: &msg }
|
||||
continue
|
||||
}
|
||||
|
||||
metrics[metric] = ApiStatsData{
|
||||
|
29
config.json
29
config.json
@ -1,17 +1,19 @@
|
||||
{
|
||||
"metrics": {
|
||||
"load_one": { "frequency": 3, "aggregation": null, "scope": "node" },
|
||||
"load_five": { "frequency": 3, "aggregation": null, "scope": "node" },
|
||||
"load_fifteen": { "frequency": 3, "aggregation": null, "scope": "node" },
|
||||
"proc_run": { "frequency": 3, "aggregation": null, "scope": "node" },
|
||||
"proc_total": { "frequency": 3, "aggregation": null, "scope": "node" },
|
||||
"power": { "frequency": 3, "aggregation": "sum", "scope": "socket" },
|
||||
"mem_bw": { "frequency": 3, "aggregation": "sum", "scope": "socket" },
|
||||
"flops_sp": { "frequency": 3, "aggregation": "sum", "scope": "cpu" },
|
||||
"flops_dp": { "frequency": 3, "aggregation": "sum", "scope": "cpu" },
|
||||
"flops_any": { "frequency": 3, "aggregation": "sum", "scope": "cpu" },
|
||||
"clock": { "frequency": 3, "aggregation": "avg", "scope": "cpu" },
|
||||
"cpi": { "frequency": 3, "aggregation": "avg", "scope": "cpu" }
|
||||
"load_one": { "frequency": 10, "aggregation": null, "scope": "node" },
|
||||
"load_five": { "frequency": 10, "aggregation": null, "scope": "node" },
|
||||
"load_fifteen": { "frequency": 10, "aggregation": null, "scope": "node" },
|
||||
"proc_run": { "frequency": 10, "aggregation": null, "scope": "node" },
|
||||
"proc_total": { "frequency": 10, "aggregation": null, "scope": "node" },
|
||||
"mem_free": { "frequency": 10, "aggregation": null, "scope": "node" },
|
||||
"mem_used": { "frequency": 10, "aggregation": null, "scope": "node" },
|
||||
"power": { "frequency": 10, "aggregation": "sum", "scope": "socket" },
|
||||
"mem_bw": { "frequency": 10, "aggregation": "sum", "scope": "socket" },
|
||||
"flops_sp": { "frequency": 10, "aggregation": "sum", "scope": "cpu" },
|
||||
"flops_dp": { "frequency": 10, "aggregation": "sum", "scope": "cpu" },
|
||||
"flops_any": { "frequency": 10, "aggregation": "sum", "scope": "cpu" },
|
||||
"clock": { "frequency": 10, "aggregation": "avg", "scope": "cpu" },
|
||||
"cpi": { "frequency": 10, "aggregation": "avg", "scope": "cpu" }
|
||||
},
|
||||
"checkpoints": {
|
||||
"interval": 21600,
|
||||
@ -23,6 +25,7 @@
|
||||
"directory": "./var/archive"
|
||||
},
|
||||
"retention-in-memory": 86400,
|
||||
"nats": "nats://localhost:4222",
|
||||
"http-api-address": "0.0.0.0:8081",
|
||||
"nats": null,
|
||||
"jwt-public-key": "kzfYrYy+TzpanWZHJ5qSdMj5uKUWgq74BWhQG6copP0="
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user