Преглед на файлове

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 години
родител
ревизия
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)
 		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)
 		}
 		}