Преглед изворни кода

Add diagnostics endpoint for queue state.

Matt Bolt пре 4 година
родитељ
комит
027dfdfb7c
1 измењених фајлова са 15 додато и 2 уклоњено
  1. 15 2
      pkg/costmodel/router.go

+ 15 - 2
pkg/costmodel/router.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"context"
 	"flag"
 	"flag"
 	"fmt"
 	"fmt"
-	"github.com/kubecost/cost-model/pkg/util/timeutil"
 	"net/http"
 	"net/http"
 	"reflect"
 	"reflect"
 	"strconv"
 	"strconv"
@@ -12,6 +11,8 @@ import (
 	"sync"
 	"sync"
 	"time"
 	"time"
 
 
+	"github.com/kubecost/cost-model/pkg/util/timeutil"
+
 	"k8s.io/klog"
 	"k8s.io/klog"
 
 
 	"github.com/julienschmidt/httprouter"
 	"github.com/julienschmidt/httprouter"
@@ -401,7 +402,6 @@ func (a *Accesses) ClusterCosts(w http.ResponseWriter, r *http.Request, ps httpr
 		}
 		}
 	}
 	}
 
 
-
 	useThanos, _ := strconv.ParseBool(r.URL.Query().Get("multi"))
 	useThanos, _ := strconv.ParseBool(r.URL.Query().Get("multi"))
 
 
 	if useThanos && !thanos.IsEnabled() {
 	if useThanos && !thanos.IsEnabled() {
@@ -722,6 +722,16 @@ func (a *Accesses) GetPrometheusMetadata(w http.ResponseWriter, _ *http.Request,
 	w.Write(WrapData(prom.Validate(a.PrometheusClient)))
 	w.Write(WrapData(prom.Validate(a.PrometheusClient)))
 }
 }
 
 
+func (a *Accesses) GetPrometheusQueueState(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
+	w.Header().Set("Content-Type", "application/json")
+	w.Header().Set("Access-Control-Allow-Origin", "*")
+
+	promClient := a.GetPrometheusClient(true)
+	queueState, err := prom.GetPrometheusQueueState(promClient)
+
+	w.Write(WrapData(queueState, err))
+}
+
 // Creates a new ClusterManager instance using a boltdb storage. If that fails,
 // Creates a new ClusterManager instance using a boltdb storage. If that fails,
 // then we fall back to a memory-only storage.
 // then we fall back to a memory-only storage.
 func newClusterManager() *cm.ClusterManager {
 func newClusterManager() *cm.ClusterManager {
@@ -1073,6 +1083,9 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 	a.Router.GET("/pricingSourceStatus", a.GetPricingSourceStatus)
 	a.Router.GET("/pricingSourceStatus", a.GetPricingSourceStatus)
 	a.Router.GET("/pricingSourceCounts", a.GetPricingSourceCounts)
 	a.Router.GET("/pricingSourceCounts", a.GetPricingSourceCounts)
 
 
+	// diagnostics
+	a.Router.GET("/diagnostics/requestQueue", a.GetPrometheusQueueState)
+
 	// cluster manager endpoints
 	// cluster manager endpoints
 	a.Router.GET("/clusters", managerEndpoints.GetAllClusters)
 	a.Router.GET("/clusters", managerEndpoints.GetAllClusters)
 	a.Router.PUT("/clusters", managerEndpoints.PutCluster)
 	a.Router.PUT("/clusters", managerEndpoints.PutCluster)