Ver código fonte

WIP

Signed-off-by: pokom <mark.poko@grafana.com>
pokom 3 anos atrás
pai
commit
19d6f5c245

+ 6 - 1
pkg/cloud/awsprovider.go

@@ -114,7 +114,7 @@ func (aws *AWS) PricingSourceStatus() map[string]*PricingSource {
 
 }
 
-// How often spot data is refreshed
+// SpotRefreshDuration represents how much time must pass before we refresh
 const SpotRefreshDuration = 15 * time.Minute
 
 var awsRegions = []string{
@@ -2299,3 +2299,8 @@ func (aws *AWS) CombinedDiscountForNode(instanceType string, isPreemptible bool,
 func (aws *AWS) Regions() []string {
 	return awsRegions
 }
+
+func (aws *AWS) PricingSourceSummary() (interface{}, error) {
+	// encode the pricing source summary as a JSON string
+	return aws.Pricing, nil
+}

+ 5 - 0
pkg/cloud/azureprovider.go

@@ -404,6 +404,11 @@ type Azure struct {
 	azureStorageConfig             *AzureStorageConfig
 }
 
+func (az *Azure) PricingSourceSummary() (interface{}, error) {
+	//TODO implement me
+	panic("implement me")
+}
+
 type azureKey struct {
 	Labels        map[string]string
 	GPULabel      string

+ 5 - 0
pkg/cloud/customprovider.go

@@ -33,6 +33,11 @@ type CustomProvider struct {
 	Config                  *ProviderConfig
 }
 
+func (cp *CustomProvider) PricingSourceSummary() (interface{}, error) {
+	//TODO implement me
+	panic("implement me")
+}
+
 type customProviderKey struct {
 	SpotLabel      string
 	SpotLabelValue string

+ 1 - 0
pkg/cloud/provider.go

@@ -338,6 +338,7 @@ type Provider interface {
 	ClusterManagementPricing() (string, float64, error)
 	CombinedDiscountForNode(string, bool, float64, float64) float64
 	Regions() []string
+	PricingSourceSummary() (interface{}, error)
 }
 
 // ClusterName returns the name defined in cluster info, defaulting to the

+ 5 - 0
pkg/cloud/scalewayprovider.go

@@ -38,6 +38,11 @@ type Scaleway struct {
 	DownloadPricingDataLock sync.RWMutex
 }
 
+func (c *Scaleway) PricingSourceSummary() (interface{}, error) {
+	//TODO implement me
+	panic("implement me")
+}
+
 func (c *Scaleway) DownloadPricingData() error {
 	c.DownloadPricingDataLock.Lock()
 	defer c.DownloadPricingDataLock.Unlock()

+ 13 - 0
pkg/costmodel/router.go

@@ -692,6 +692,18 @@ func (a *Accesses) GetPricingSourceCounts(w http.ResponseWriter, _ *http.Request
 	w.Write(WrapData(a.Model.GetPricingSourceCounts()))
 }
 
+func (a *Accesses) GetPricingSourceSummary(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
+	w.Header().Set("Content-Type", "application/json")
+	w.Header().Set("Access-Control-Allow-Origin", "*")
+
+	data, err := a.CloudProvider.PricingSourceSummary()
+	if err != nil {
+		w.WriteHeader(http.StatusInternalServerError)
+		w.Write(WrapData(nil, err))
+	}
+	w.Write(WrapData(data, nil))
+}
+
 func (a *Accesses) GetPrometheusMetadata(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Access-Control-Allow-Origin", "*")
@@ -1757,6 +1769,7 @@ func Initialize(additionalConfigWatchers ...*watcher.ConfigMapWatcher) *Accesses
 	a.Router.GET("/clusterInfoMap", a.GetClusterInfoMap)
 	a.Router.GET("/serviceAccountStatus", a.GetServiceAccountStatus)
 	a.Router.GET("/pricingSourceStatus", a.GetPricingSourceStatus)
+	a.Router.GET("/pricingSourceSummary", a.GetPricingSourceSummary)
 	a.Router.GET("/pricingSourceCounts", a.GetPricingSourceCounts)
 
 	// endpoints migrated from server