AjayTripathy пре 6 година
родитељ
комит
5fe24a618f
2 измењених фајлова са 9 додато и 5 уклоњено
  1. 6 2
      costmodel/costmodel.go
  2. 3 3
      costmodel/router.go

+ 6 - 2
costmodel/costmodel.go

@@ -165,8 +165,12 @@ type PrometheusMetadata struct {
 }
 
 // ValidatePrometheus tells the model what data prometheus has on it.
-func ValidatePrometheus(cli prometheusClient.Client) (*PrometheusMetadata, error) {
-	data, err := Query(cli, "up offset 3h")
+func ValidatePrometheus(cli prometheusClient.Client, isThanos bool) (*PrometheusMetadata, error) {
+	q := "up"
+	if isThanos {
+		q += " offset 3h"
+	}
+	data, err := Query(cli, q)
 	if err != nil {
 		return &PrometheusMetadata{
 			Running:            false,

+ 3 - 3
costmodel/router.go

@@ -742,7 +742,7 @@ func Healthz(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
 func (p *Accesses) GetPrometheusMetadata(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Access-Control-Allow-Origin", "*")
-	w.Write(wrapData(ValidatePrometheus(p.PrometheusClient)))
+	w.Write(wrapData(ValidatePrometheus(p.PrometheusClient, false)))
 }
 
 func (p *Accesses) ContainerUptimes(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
@@ -955,7 +955,7 @@ func init() {
 	}
 	klog.V(1).Info("Success: retrieved a prometheus config file from: " + address)
 
-	_, err = ValidatePrometheus(promCli)
+	_, err = ValidatePrometheus(promCli, false)
 	if err != nil {
 		klog.Fatalf("Failed to query prometheus at %s. Error: %s . Troubleshooting help available at: %s", address, err.Error(), prometheusTroubleshootingEp)
 	}
@@ -1112,7 +1112,7 @@ func init() {
 			}
 			thanosCli, _ := prometheusClient.NewClient(thanosConfig)
 
-			_, err = ValidatePrometheus(thanosCli)
+			_, err = ValidatePrometheus(thanosCli, true)
 			if err != nil {
 				klog.Fatalf("Failed to query Thanos at %s. Error: %s.", thanosUrl, err.Error())
 			} else {