Explorar el Código

fix(prometheus): update validation logic to not require every series to have "job" label (#3242)

Signed-off-by: Michael Parker <michael@parker.gg>
Michael Parker hace 9 meses
padre
commit
02135c99e8
Se han modificado 1 ficheros con 15 adiciones y 4 borrados
  1. 15 4
      modules/prometheus-source/pkg/prom/validate.go

+ 15 - 4
modules/prometheus-source/pkg/prom/validate.go

@@ -47,15 +47,19 @@ func validate(cli prometheus.Client, q string, config *OpenCostPrometheusConfig)
 		}, fmt.Errorf("no running jobs on Prometheus at %s", ctx.QueryURL().Path)
 	}
 
+	running := false
+
 	for _, result := range resUp {
 		job, err := result.GetString("job")
 		if err != nil {
-			return &PrometheusMetadata{
-				Running:            false,
-				KubecostDataExists: false,
-			}, fmt.Errorf("up query does not have job names")
+			// Stop evaluating result if it does not have a job label (continue to next result)
+			// We don't error here because not every result from `up` will necessarily have a job label.
+			continue
 		}
 
+		// At least one job is running, so we can set running to true
+		running = true
+
 		if job == config.JobName {
 			return &PrometheusMetadata{
 				Running:            true,
@@ -64,6 +68,13 @@ func validate(cli prometheus.Client, q string, config *OpenCostPrometheusConfig)
 		}
 	}
 
+	if !running {
+		return &PrometheusMetadata{
+			Running:            false,
+			KubecostDataExists: false,
+		}, fmt.Errorf("up query does not have job names")
+	}
+
 	return &PrometheusMetadata{
 		Running:            true,
 		KubecostDataExists: false,