mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2026-03-03 15:17:30 +01:00
Update to the error handling
This commit is contained in:
@@ -21,8 +21,7 @@ import (
|
|||||||
cclog "github.com/ClusterCockpit/cc-lib/v2/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-lib/v2/ccLogger"
|
||||||
"github.com/ClusterCockpit/cc-lib/v2/schema"
|
"github.com/ClusterCockpit/cc-lib/v2/schema"
|
||||||
"github.com/ClusterCockpit/cc-lib/v2/util"
|
"github.com/ClusterCockpit/cc-lib/v2/util"
|
||||||
|
"github.com/ClusterCockpit/cc-line-protocol/v2/lineprotocol"
|
||||||
"github.com/influxdata/line-protocol/v2/lineprotocol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrorResponse model
|
// ErrorResponse model
|
||||||
@@ -37,6 +36,8 @@ type DefaultAPIResponse struct {
|
|||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ErrNoHostOrMetric error = errors.New("[METRICSTORE]> metric or host not found")
|
||||||
|
|
||||||
// handleError writes a standardized JSON error response with the given status code.
|
// handleError writes a standardized JSON error response with the given status code.
|
||||||
// It logs the error at WARN level and ensures proper Content-Type headers are set.
|
// It logs the error at WARN level and ensures proper Content-Type headers are set.
|
||||||
func handleError(err error, statusCode int, rw http.ResponseWriter) {
|
func handleError(err error, statusCode int, rw http.ResponseWriter) {
|
||||||
@@ -249,15 +250,18 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
|
|||||||
res := make([]APIMetricData, 0, len(sels))
|
res := make([]APIMetricData, 0, len(sels))
|
||||||
for _, sel := range sels {
|
for _, sel := range sels {
|
||||||
data := APIMetricData{}
|
data := APIMetricData{}
|
||||||
if ver == "v1" {
|
|
||||||
data.Data, data.From, data.To, data.Resolution, err = ms.Read(sel, query.Metric, req.From, req.To, 0)
|
|
||||||
} else {
|
|
||||||
data.Data, data.From, data.To, data.Resolution, err = ms.Read(sel, query.Metric, req.From, req.To, query.Resolution)
|
data.Data, data.From, data.To, data.Resolution, err = ms.Read(sel, query.Metric, req.From, req.To, query.Resolution)
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Skip Error If Just Missing Host or Metric, Continue
|
||||||
|
// Empty Return For Metric Handled Gracefully By Frontend
|
||||||
|
if err != ErrNoHostOrMetric {
|
||||||
msg := err.Error()
|
msg := err.Error()
|
||||||
data.Error = &msg
|
data.Error = &msg
|
||||||
res = append(res, data)
|
res = append(res, data)
|
||||||
|
} else {
|
||||||
|
cclog.Warnf("failed to fetch '%s' from host '%s' (cluster: %s): %s", query.Metric, query.Hostname, req.Cluster, err.Error())
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user