Sean Holcomb 4 سال پیش
والد
کامیت
a5b86b8c9f
6فایلهای تغییر یافته به همراه51 افزوده شده و 60 حذف شده
  1. 0 2
      pkg/costmodel/router.go
  2. 4 5
      pkg/prom/diagnostics.go
  3. 1 1
      pkg/prom/result.go
  4. 0 3
      pkg/util/mapper/mapper.go
  5. 1 1
      pkg/util/timeutil/timeutil.go
  6. 45 48
      pkg/util/timeutil/timeutil_test.go

+ 0 - 2
pkg/costmodel/router.go

@@ -908,8 +908,6 @@ func (a *Accesses) GetPrometheusMetrics(w http.ResponseWriter, _ *http.Request,
 		}
 	}
 
-
-
 	w.Write(WrapData(result, nil))
 }
 

+ 4 - 5
pkg/prom/diagnostics.go

@@ -128,13 +128,12 @@ func GetPrometheusMetrics(client prometheus.Client, offset string) ([]*Prometheu
 			Description: "Determine if prometheus has its own self-scraped metrics during the last 5 minutes.",
 		},
 		{
-			ID:          "cpuThrottling",
-			Query:       `avg(increase(container_cpu_cfs_throttled_periods_total{container="cost-model"}[10m])) by (container_name, pod_name, namespace)
+			ID: "cpuThrottling",
+			Query: `avg(increase(container_cpu_cfs_throttled_periods_total{container="cost-model"}[10m])) by (container_name, pod_name, namespace)
 		/ avg(increase(container_cpu_cfs_periods_total{container="cost-model"}[10m])) by (container_name, pod_name, namespace) > 0.2`,
 			Label:       "Kubecost is not CPU throttled",
 			Description: "Kubecost loading slowly? A kubecost component might be CPU throttled",
 		},
-
 	}
 
 	for _, pd := range result {
@@ -165,8 +164,8 @@ func (pd *PrometheusDiagnostic) executePrometheusDiagnosticQuery(ctx *Context) e
 	if err != nil {
 		return fmt.Errorf("prometheus diagnostic %s failed with error: %s", pd.ID, err)
 	}
-    if result == nil {
-    	result = []*QueryResult{}
+	if result == nil {
+		result = []*QueryResult{}
 	}
 	pd.Result = result
 	pd.Passed = len(result) == 0

+ 1 - 1
pkg/prom/result.go

@@ -91,7 +91,7 @@ type QueryResults struct {
 // to refer to query results as a slice of QueryResult
 type QueryResult struct {
 	Metric map[string]interface{} `json:"metric"`
-	Values []*util.Vector `json:"values"`
+	Values []*util.Vector         `json:"values"`
 }
 
 // NewQueryResults accepts the raw prometheus query result and returns an array of

+ 0 - 3
pkg/util/mapper/mapper.go

@@ -496,6 +496,3 @@ func (wom *writeOnlyMapper) SetDuration(key string, value time.Duration) error {
 func (wom *writeOnlyMapper) SetList(key string, values []string, delimiter string) error {
 	return wom.setter.Set(key, strings.Join(values, delimiter))
 }
-
-
-

+ 1 - 1
pkg/util/timeutil/timeutil.go

@@ -237,4 +237,4 @@ func (jt *JobTicker) TickIn(d time.Duration) {
 			jt.ch <- time.Now()
 		}
 	}(d)
-}
+}

+ 45 - 48
pkg/util/timeutil/timeutil_test.go

@@ -7,7 +7,7 @@ import (
 
 func Test_DurationString(t *testing.T) {
 	testCases := map[string]struct {
-		duration time.Duration
+		duration         time.Duration
 		expectedDuration string
 	}{
 		"1a": {
@@ -15,36 +15,36 @@ func Test_DurationString(t *testing.T) {
 			expectedDuration: "",
 		},
 		"1b": {
-			duration:         24*time.Hour,
+			duration:         24 * time.Hour,
 			expectedDuration: "1d",
 		},
 		"1c": {
-			duration:         24*time.Hour+5*time.Minute,
+			duration:         24*time.Hour + 5*time.Minute,
 			expectedDuration: "1445m",
 		},
 		"1d": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "25h",
 		},
 		"1e": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "25h",
 		},
 		"1f": {
-			duration:         72*time.Hour,
+			duration:         72 * time.Hour,
 			expectedDuration: "3d",
 		},
 		"1g": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "25h",
 		},
 		"1h": {
-			duration:         24*time.Hour+time.Second,
+			duration:         24*time.Hour + time.Second,
 			expectedDuration: "86401s",
 		},
 		// Expect empty strings if durations are negative
 		"1i": {
-			duration:         -25*time.Hour,
+			duration:         -25 * time.Hour,
 			expectedDuration: "",
 		},
 	}
@@ -61,7 +61,7 @@ func Test_DurationString(t *testing.T) {
 
 func Test_DurationToPromOffsetString(t *testing.T) {
 	testCases := map[string]struct {
-		duration time.Duration
+		duration         time.Duration
 		expectedDuration string
 	}{
 		"1a": {
@@ -69,36 +69,36 @@ func Test_DurationToPromOffsetString(t *testing.T) {
 			expectedDuration: "",
 		},
 		"1b": {
-			duration:         24*time.Hour,
+			duration:         24 * time.Hour,
 			expectedDuration: "offset 1d",
 		},
 		"1c": {
-			duration:         24*time.Hour+5*time.Minute,
+			duration:         24*time.Hour + 5*time.Minute,
 			expectedDuration: "offset 1445m",
 		},
 		"1d": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "offset 25h",
 		},
 		"1e": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "offset 25h",
 		},
 		"1f": {
-			duration:         72*time.Hour,
+			duration:         72 * time.Hour,
 			expectedDuration: "offset 3d",
 		},
 		"1g": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "offset 25h",
 		},
 		"1h": {
-			duration:         24*time.Hour+time.Second,
+			duration:         24*time.Hour + time.Second,
 			expectedDuration: "offset 86401s",
 		},
 		// Expect empty strings if durations are negative
 		"1i": {
-			duration:         -25*time.Hour,
+			duration:         -25 * time.Hour,
 			expectedDuration: "",
 		},
 	}
@@ -115,7 +115,7 @@ func Test_DurationToPromOffsetString(t *testing.T) {
 
 func Test_FormatStoreResolution(t *testing.T) {
 	testCases := map[string]struct {
-		duration time.Duration
+		duration         time.Duration
 		expectedDuration string
 	}{
 		"1a": {
@@ -123,36 +123,36 @@ func Test_FormatStoreResolution(t *testing.T) {
 			expectedDuration: "0s",
 		},
 		"1b": {
-			duration:         24*time.Hour,
+			duration:         24 * time.Hour,
 			expectedDuration: "1d",
 		},
 		"1c": {
-			duration:         24*time.Hour+5*time.Minute,
+			duration:         24*time.Hour + 5*time.Minute,
 			expectedDuration: "1d",
 		},
 		"1d": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "1d",
 		},
 		"1e": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "1d",
 		},
 		"1f": {
-			duration:         72*time.Hour,
+			duration:         72 * time.Hour,
 			expectedDuration: "3d",
 		},
 		"1g": {
-			duration:         25*time.Hour,
+			duration:         25 * time.Hour,
 			expectedDuration: "1d",
 		},
 		"1h": {
-			duration:         24*time.Hour+time.Second,
+			duration:         24*time.Hour + time.Second,
 			expectedDuration: "1d",
 		},
 		// Expect empty strings if durations are negative
 		"1i": {
-			duration:         -25*time.Hour,
+			duration:         -25 * time.Hour,
 			expectedDuration: "-25h0m0s",
 		},
 	}
@@ -169,10 +169,10 @@ func Test_FormatStoreResolution(t *testing.T) {
 
 func Test_DurationOffsetStrings(t *testing.T) {
 	testCases := map[string]struct {
-		duration time.Duration
-		offset time.Duration
+		duration         time.Duration
+		offset           time.Duration
 		expectedDuration string
-		expectedOffset string
+		expectedOffset   string
 	}{
 		"1a": {
 			duration:         0,
@@ -181,51 +181,51 @@ func Test_DurationOffsetStrings(t *testing.T) {
 			expectedOffset:   "",
 		},
 		"1b": {
-			duration:         24*time.Hour,
+			duration:         24 * time.Hour,
 			offset:           0,
 			expectedDuration: "1d",
 			expectedOffset:   "",
 		},
 		"1c": {
-			duration:         24*time.Hour+5*time.Minute,
+			duration:         24*time.Hour + 5*time.Minute,
 			offset:           0,
 			expectedDuration: "1445m",
 			expectedOffset:   "",
 		},
 		"1d": {
-			duration:         25*time.Hour,
-			offset:           5*time.Minute,
+			duration:         25 * time.Hour,
+			offset:           5 * time.Minute,
 			expectedDuration: "25h",
 			expectedOffset:   "5m",
 		},
 		"1e": {
-			duration:         25*time.Hour,
-			offset:           60*time.Minute,
+			duration:         25 * time.Hour,
+			offset:           60 * time.Minute,
 			expectedDuration: "25h",
 			expectedOffset:   "1h",
 		},
 		"1f": {
-			duration:         72*time.Hour,
-			offset:           1440*time.Minute,
+			duration:         72 * time.Hour,
+			offset:           1440 * time.Minute,
 			expectedDuration: "3d",
 			expectedOffset:   "1d",
 		},
 		"1g": {
-			duration:         25*time.Hour,
-			offset:           1*time.Second,
+			duration:         25 * time.Hour,
+			offset:           1 * time.Second,
 			expectedDuration: "25h",
 			expectedOffset:   "1s",
 		},
 		"1h": {
-			duration:         24*time.Hour+time.Second,
-			offset:           1*time.Second,
+			duration:         24*time.Hour + time.Second,
+			offset:           1 * time.Second,
 			expectedDuration: "86401s",
 			expectedOffset:   "1s",
 		},
 		// Expect empty strings if durations are negative
 		"1i": {
-			duration:         -25*time.Hour,
-			offset:           -1*time.Second,
+			duration:         -25 * time.Hour,
+			offset:           -1 * time.Second,
 			expectedDuration: "",
 			expectedOffset:   "",
 		},
@@ -233,7 +233,7 @@ func Test_DurationOffsetStrings(t *testing.T) {
 
 	for name, test := range testCases {
 		t.Run(name, func(t *testing.T) {
-			dur, off:= DurationOffsetStrings(test.duration, test.offset)
+			dur, off := DurationOffsetStrings(test.duration, test.offset)
 			if dur != test.expectedDuration || off != test.expectedOffset {
 				t.Fatalf("DurationOffsetStrings: exp (%s %s); act (%s, %s)", test.expectedDuration, test.expectedOffset, dur, off)
 			}
@@ -322,8 +322,6 @@ func Test_CleanDurationString(t *testing.T) {
 			input:    "oqwd3dk5hk",
 			expected: "oqwd3dk5hk",
 		},
-
-
 	}
 	for name, test := range testCases {
 		t.Run(name, func(t *testing.T) {
@@ -368,7 +366,6 @@ func Test_FormatDurationStringDaysToHours(t *testing.T) {
 			input:    "oqwd3dk5hk",
 			expected: "oqwd3dk5hk",
 		},
-
 	}
 	for name, test := range testCases {
 		t.Run(name, func(t *testing.T) {