mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2026-03-03 15:17:30 +01:00
Fix healthcheck api
This commit is contained in:
@@ -1,10 +1,38 @@
|
|||||||
{
|
{
|
||||||
"main": {
|
"main": {
|
||||||
"addr": "0.0.0.0:443",
|
"addr": "0.0.0.0:8082",
|
||||||
"https-cert-file": "/etc/letsencrypt/live/url/fullchain.pem",
|
"https-cert-file": "",
|
||||||
"https-key-file": "/etc/letsencrypt/live/url/privkey.pem",
|
"https-key-file": "",
|
||||||
"jwt-public-key": "kzfYrYy+TzpanWZHJ5qSdMj5uKUWgq74BWhQG6copP0="
|
"jwt-public-key": "kzfYrYy+TzpanWZHJ5qSdMj5uKUWgq74BWhQG6copP0="
|
||||||
},
|
},
|
||||||
|
"nats": {
|
||||||
|
"address": "nats://0.0.0.0:4222",
|
||||||
|
"username": "root",
|
||||||
|
"password": "root"
|
||||||
|
},
|
||||||
|
"metric-store": {
|
||||||
|
"checkpoints": {
|
||||||
|
"interval": "12h",
|
||||||
|
"directory": "./var/checkpoints"
|
||||||
|
},
|
||||||
|
"memory-cap": 100,
|
||||||
|
"retention-in-memory": "48h",
|
||||||
|
"cleanup": {
|
||||||
|
"mode": "archive",
|
||||||
|
"interval": "48h",
|
||||||
|
"directory": "./var/archive"
|
||||||
|
},
|
||||||
|
"nats-subscriptions": [
|
||||||
|
{
|
||||||
|
"subscribe-to": "hpc-nats",
|
||||||
|
"cluster-tag": "fritz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"subscribe-to": "hpc-nats",
|
||||||
|
"cluster-tag": "alex"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"metrics": {
|
"metrics": {
|
||||||
"debug_metric": {
|
"debug_metric": {
|
||||||
"frequency": 60,
|
"frequency": 60,
|
||||||
@@ -170,34 +198,5 @@
|
|||||||
"frequency": 60,
|
"frequency": 60,
|
||||||
"aggregation": "avg"
|
"aggregation": "avg"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"nats": {
|
|
||||||
"address": "nats://0.0.0.0:4222",
|
|
||||||
"username": "root",
|
|
||||||
"password": "root"
|
|
||||||
},
|
|
||||||
"metric-store": {
|
|
||||||
"checkpoints": {
|
|
||||||
"interval": "12h",
|
|
||||||
"directory": "./var/checkpoints"
|
|
||||||
},
|
|
||||||
"memory-cap": 100,
|
|
||||||
"retention-in-memory": "48h",
|
|
||||||
"cleanup": {
|
|
||||||
"mode": "archive",
|
|
||||||
"interval": "48h",
|
|
||||||
"directory": "./var/archive"
|
|
||||||
},
|
|
||||||
"nats-subscriptions": [
|
|
||||||
{
|
|
||||||
"subscribe-to": "hpc-nats",
|
|
||||||
"cluster-tag": "fritz"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"subscribe-to": "hpc-nats",
|
|
||||||
"cluster-tag": "alex"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,21 +416,31 @@ func debugMetrics(rw http.ResponseWriter, r *http.Request) {
|
|||||||
// @security ApiKeyAuth
|
// @security ApiKeyAuth
|
||||||
// @router /healthcheck/ [get]
|
// @router /healthcheck/ [get]
|
||||||
func metricsHealth(rw http.ResponseWriter, r *http.Request) {
|
func metricsHealth(rw http.ResponseWriter, r *http.Request) {
|
||||||
rawCluster := r.URL.Query().Get("cluster")
|
req := metricstore.HealthCheckReq{}
|
||||||
rawNode := r.URL.Query().Get("node")
|
|
||||||
|
|
||||||
if rawCluster == "" || rawNode == "" {
|
dec := json.NewDecoder(r.Body)
|
||||||
handleError(errors.New("'cluster' and 'node' are required query parameter"), http.StatusBadRequest, rw)
|
dec.DisallowUnknownFields()
|
||||||
|
|
||||||
|
if err := dec.Decode(&req); err != nil {
|
||||||
|
handleError(fmt.Errorf("parsing request body failed: %w", err),
|
||||||
|
http.StatusBadRequest, rw)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rw.Header().Add("Content-Type", "application/json")
|
rw.Header().Add("Content-Type", "application/json")
|
||||||
|
|
||||||
selector := []string{rawCluster, rawNode}
|
|
||||||
|
|
||||||
ms := metricstore.GetMemoryStore()
|
ms := metricstore.GetMemoryStore()
|
||||||
if err := ms.HealthCheck(bufio.NewWriter(rw), selector); err != nil {
|
results, err := ms.HealthCheck(req.Cluster, req.Nodes, req.MetricNames)
|
||||||
|
if err != nil {
|
||||||
handleError(err, http.StatusBadRequest, rw)
|
handleError(err, http.StatusBadRequest, rw)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
bw := bufio.NewWriter(rw)
|
||||||
|
defer bw.Flush()
|
||||||
|
if err := json.NewEncoder(bw).Encode(results); err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ var metricConfigSchema = `
|
|||||||
},
|
},
|
||||||
"aggregation": {
|
"aggregation": {
|
||||||
"description": "Aggregation strategy: 'sum', 'avg', or 'null'.",
|
"description": "Aggregation strategy: 'sum', 'avg', or 'null'.",
|
||||||
"type": "string"
|
"type": ["string", "null"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["frequency", "aggregation"]
|
"required": ["frequency", "aggregation"]
|
||||||
|
|||||||
Reference in New Issue
Block a user