Explorar el Código

Run validation against the thanos prometheus client. We want to ensure that we fall back to local prometheus on failure to connect to thanos query.

Matt Bolt hace 6 años
padre
commit
a2838bdf35
Se han modificado 2 ficheros con 13 adiciones y 1 borrados
  1. 4 0
      costmodel/costmodel.go
  2. 9 1
      costmodel/router.go

+ 4 - 0
costmodel/costmodel.go

@@ -1882,6 +1882,10 @@ func Query(cli prometheusClient.Client, query string) (interface{}, error) {
 		klog.V(3).Infof("%s", w)
 		klog.V(3).Infof("%s", w)
 	}
 	}
 	if err != nil {
 	if err != nil {
+		if resp == nil {
+			return nil, fmt.Errorf("Error %s fetching query %s", err.Error(), query)
+		}
+
 		return nil, fmt.Errorf("%s Error %s fetching query %s", resp.StatusCode, err.Error(), query)
 		return nil, fmt.Errorf("%s Error %s fetching query %s", resp.StatusCode, err.Error(), query)
 	}
 	}
 	var toReturn interface{}
 	var toReturn interface{}

+ 9 - 1
costmodel/router.go

@@ -992,7 +992,15 @@ func init() {
 			}
 			}
 			thanosCli, _ := prometheusClient.NewClient(thanosConfig)
 			thanosCli, _ := prometheusClient.NewClient(thanosConfig)
 
 
-			A.ThanosClient = thanosCli
+			_, err = ValidatePrometheus(thanosCli)
+			if err != nil {
+				klog.Fatalf("Failed to query Thanos at %s. Error: %s.", thanosUrl, err.Error())
+			} else {
+				klog.V(1).Info("Success: retrieved the 'up' query against Thanos at: " + thanosUrl)
+
+				A.ThanosClient = thanosCli
+			}
+
 		} else {
 		} else {
 			klog.Infof("Error resolving environment variable: $%s", thanosQueryUrl)
 			klog.Infof("Error resolving environment variable: $%s", thanosQueryUrl)
 		}
 		}