no append if ErrNoHostOrMetric fired

This commit is contained in:
Christoph Kluge
2026-01-29 15:18:50 +01:00
parent f26cabbdf1
commit 4deec9a170
2 changed files with 31 additions and 12 deletions

View File

@@ -13,6 +13,7 @@ import (
"fmt" "fmt"
"math" "math"
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"
) )
@@ -280,20 +281,16 @@ func FetchData(req APIQueryRequest) (*APIQueryResponse, error) {
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 {
// Check a special case where only the metric or host. // Skip Error If Just Missing Host or Metric, Continue
// Dont send errors, instead just send empty array // Empty Return For Metric Handled Gracefully By Frontend
// where frontend already renders error for empty array. if err != ErrNoHostOrMetric {
if err == ErrNoHostOrMetric {
data.Data = make([]schema.Float, 0)
data.From = req.From
data.To = req.To
data.Resolution = query.Resolution
} else {
msg := err.Error() msg := err.Error()
data.Error = &msg data.Error = &msg
res = append(res, data) res = append(res, data)
continue } else {
cclog.Warnf("failed to fetch '%s' from host '%s' (cluster: %s): %s", query.Metric, query.Hostname, req.Cluster, err.Error())
} }
continue
} }
if req.WithStats { if req.WithStats {

View File

@@ -104,6 +104,11 @@ func (ccms *InternalMetricStore) LoadData(
var errors []string var errors []string
jobData := make(schema.JobData) jobData := make(schema.JobData)
for i, row := range resBody.Results { for i, row := range resBody.Results {
if len(row) == 0 {
// No Data Found For Metric, Logged in FetchData to Warn
continue
}
query := req.Queries[i] query := req.Queries[i]
metric := query.Metric metric := query.Metric
scope := assignedScope[i] scope := assignedScope[i]
@@ -229,7 +234,7 @@ func buildQueries(
for _, metric := range metrics { for _, metric := range metrics {
mc := archive.GetMetricConfig(job.Cluster, metric) mc := archive.GetMetricConfig(job.Cluster, metric)
if mc == nil { if mc == nil {
cclog.Infof("metric '%s' is not specified for cluster '%s'", metric, job.Cluster) cclog.Warnf("metric '%s' is not specified for cluster '%s'", metric, job.Cluster)
continue continue
} }
@@ -535,11 +540,15 @@ func (ccms *InternalMetricStore) LoadStats(
stats := make(map[string]map[string]schema.MetricStatistics, len(metrics)) stats := make(map[string]map[string]schema.MetricStatistics, len(metrics))
for i, res := range resBody.Results { for i, res := range resBody.Results {
if len(res) == 0 {
// No Data Found For Metric, Logged in FetchData to Warn
continue
}
query := req.Queries[i] query := req.Queries[i]
metric := query.Metric metric := query.Metric
data := res[0] data := res[0]
if data.Error != nil { if data.Error != nil {
cclog.Errorf("fetching %s for node %s failed: %s", metric, query.Hostname, *data.Error) cclog.Warnf("fetching %s for node %s failed: %s", metric, query.Hostname, *data.Error)
continue continue
} }
@@ -609,6 +618,10 @@ func (ccms *InternalMetricStore) LoadScopedStats(
scopedJobStats := make(schema.ScopedJobStats) scopedJobStats := make(schema.ScopedJobStats)
for i, row := range resBody.Results { for i, row := range resBody.Results {
if len(row) == 0 {
// No Data Found For Metric, Logged in FetchData to Warn
continue
}
query := req.Queries[i] query := req.Queries[i]
metric := query.Metric metric := query.Metric
scope := assignedScope[i] scope := assignedScope[i]
@@ -717,6 +730,11 @@ func (ccms *InternalMetricStore) LoadNodeData(
var errors []string var errors []string
data := make(map[string]map[string][]*schema.JobMetric) data := make(map[string]map[string][]*schema.JobMetric)
for i, res := range resBody.Results { for i, res := range resBody.Results {
if len(res) == 0 {
// No Data Found For Metric, Logged in FetchData to Warn
continue
}
var query APIQuery var query APIQuery
if resBody.Queries != nil { if resBody.Queries != nil {
query = resBody.Queries[i] query = resBody.Queries[i]
@@ -816,6 +834,10 @@ func (ccms *InternalMetricStore) LoadNodeListData(
var errors []string var errors []string
data := make(map[string]schema.JobData) data := make(map[string]schema.JobData)
for i, row := range resBody.Results { for i, row := range resBody.Results {
if len(row) == 0 {
// No Data Found For Metric, Logged in FetchData to Warn
continue
}
var query APIQuery var query APIQuery
if resBody.Queries != nil { if resBody.Queries != nil {
query = resBody.Queries[i] query = resBody.Queries[i]