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