Просмотр исходного кода

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 6 лет назад
Родитель
Сommit
a2838bdf35
2 измененных файлов с 13 добавлено и 1 удалено
  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)
 	}
 	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)
 	}
 	var toReturn interface{}

+ 9 - 1
costmodel/router.go

@@ -992,7 +992,15 @@ func init() {
 			}
 			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 {
 			klog.Infof("Error resolving environment variable: $%s", thanosQueryUrl)
 		}