Prechádzať zdrojové kódy

Merge pull request #391 from kubecost/develop

Merge develop into master
Ajay Tripathy 6 rokov pred
rodič
commit
81a274cad4
3 zmenil súbory, kde vykonal 45 pridanie a 4 odobranie
  1. 2 1
      pkg/cloud/gcpprovider.go
  2. 3 3
      pkg/costmodel/cluster.go
  3. 40 0
      pkg/log/log.go

+ 2 - 1
pkg/cloud/gcpprovider.go

@@ -371,7 +371,8 @@ func (gcp *GCP) ExternalAllocations(start string, end string, aggregators []stri
 		if filterType == "kubernetes_labels" {
 			fvs := strings.Split(filterValue, "=")
 			if len(fvs) == 2 {
-				filterType = fvs[0]
+				// if we are given "app=myapp" then look for label "kubernetes_label_app=myapp"
+				filterType = fmt.Sprintf("kubernetes_label_%s", fvs[0])
 				filterValue = fvs[1]
 			} else {
 				klog.V(2).Infof("[Warning] illegal kubernetes_labels filterValue: %s", filterValue)

+ 3 - 3
pkg/costmodel/cluster.go

@@ -140,17 +140,17 @@ func ComputeClusterCosts(client prometheus.Client, provider cloud.Provider, wind
 	) by (cluster_id)`
 
 	const fmtQueryTotalCPU = `sum(
-		sum(sum_over_time(kube_node_status_capacity_cpu_cores[%s:1m]%s)) by (node, cluster_id) *
+		sum_over_time(avg(kube_node_status_capacity_cpu_cores) by (node, cluster_id)[%s:1m]%s) *
 		avg(avg_over_time(node_cpu_hourly_cost[%s:1m]%s)) by (node, cluster_id) / 60
 	) by (cluster_id)`
 
 	const fmtQueryTotalRAM = `sum(
-		sum(sum_over_time(kube_node_status_capacity_memory_bytes[%s:1m]%s) / 1024 / 1024 / 1024) by (node, cluster_id) *
+		sum_over_time(avg(kube_node_status_capacity_memory_bytes) by (node, cluster_id)[%s:1m]%s) / 1024 / 1024 / 1024 *
 		avg(avg_over_time(node_ram_hourly_cost[%s:1m]%s)) by (node, cluster_id) / 60
 	) by (cluster_id)`
 
 	const fmtQueryTotalStorage = `sum(
-		sum(sum_over_time(kube_persistentvolume_capacity_bytes[%s:1m]%s)) by (persistentvolume, cluster_id) / 1024 / 1024 / 1024 *
+		sum_over_time(avg(kube_persistentvolume_capacity_bytes) by (persistentvolume, cluster_id)[%s:1m]%s) / 1024 / 1024 / 1024 *
 		avg(avg_over_time(pv_hourly_cost[%s:1m]%s)) by (persistentvolume, cluster_id) / 60
 	) by (cluster_id) %s`
 

+ 40 - 0
pkg/log/log.go

@@ -0,0 +1,40 @@
+package log
+
+import (
+	"fmt"
+	"time"
+
+	"k8s.io/klog"
+)
+
+func Errorf(format string, a ...interface{}) {
+	klog.Errorf(fmt.Sprintf("[Error] %s", format), a...)
+}
+
+func Warningf(format string, a ...interface{}) {
+	klog.V(2).Infof(fmt.Sprintf("[Warning] %s", format), a...)
+}
+
+func Infof(format string, a ...interface{}) {
+	klog.V(3).Infof(fmt.Sprintf("[Info] %s", format), a...)
+}
+
+func Profilef(format string, a ...interface{}) {
+	klog.V(3).Infof(fmt.Sprintf("[Profiler] %s", format), a...)
+}
+
+func Debugf(format string, a ...interface{}) {
+	klog.V(4).Infof(fmt.Sprintf("[Debug] %s", format), a...)
+}
+
+func Profile(start time.Time, name string) {
+	elapsed := time.Since(start)
+	Profilef("%s: %s", elapsed, name)
+}
+
+func ProfileWithThreshold(start time.Time, threshold time.Duration, name string) {
+	elapsed := time.Since(start)
+	if elapsed > threshold {
+		Profilef("%s: %s", elapsed, name)
+	}
+}