Parcourir la source

Diagnose window/storage issue

Niko Kovacevic il y a 2 mois
Parent
commit
381a0a26ce

+ 4 - 0
modules/collector-source/pkg/collector/collectorprovider.go

@@ -53,6 +53,10 @@ func (r *repoStoreProvider) GetStore(start, end time.Time) metric.MetricStore {
 // between the interval generated times, with the lowest
 func (r *repoStoreProvider) getStoreKeys(start, end time.Time) (string, time.Time) {
 	windowDuration := int64(end.Sub(start))
+
+	fmt.Println(start)
+	fmt.Println(end)
+
 	var minDiff *int64
 	var minKey string
 	var minStart time.Time

+ 43 - 33
modules/collector-source/pkg/collector/collectorprovider_test.go

@@ -5,6 +5,7 @@ import (
 	"testing"
 	"time"
 
+	"github.com/opencost/opencost/core/pkg/opencost"
 	"github.com/opencost/opencost/modules/collector-source/pkg/util"
 )
 
@@ -21,6 +22,8 @@ func Test_repoStoreProvider_getStoreKeys(t *testing.T) {
 		},
 	}
 
+	win24h, _ := opencost.ParseWindowUTC("24h")
+
 	tests := map[string]struct {
 		configs    []util.ResolutionConfiguration
 		start      time.Time
@@ -28,40 +31,47 @@ func Test_repoStoreProvider_getStoreKeys(t *testing.T) {
 		intevalKey string
 		startKey   time.Time
 	}{
-		"10m": {
-			configs:    defaultResConfigs,
-			start:      time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
-			end:        time.Date(2025, time.May, 3, 0, 10, 0, 0, time.UTC),
-			intevalKey: "10m",
-			startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
-		},
-		"1h": {
+		// "10m": {
+		// 	configs:    defaultResConfigs,
+		// 	start:      time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// 	end:        time.Date(2025, time.May, 3, 0, 10, 0, 0, time.UTC),
+		// 	intevalKey: "10m",
+		// 	startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// },
+		// "1h": {
+		// 	configs:    defaultResConfigs,
+		// 	start:      time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// 	end:        time.Date(2025, time.May, 3, 1, 0, 0, 0, time.UTC),
+		// 	intevalKey: "1h",
+		// 	startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// },
+		// "1d": {
+		// 	configs:    defaultResConfigs,
+		// 	start:      time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// 	end:        time.Date(2025, time.May, 4, 0, 10, 0, 0, time.UTC),
+		// 	intevalKey: "1d",
+		// 	startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// },
+		// "2m": {
+		// 	configs:    defaultResConfigs,
+		// 	start:      time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// 	end:        time.Date(2025, time.May, 3, 0, 2, 0, 0, time.UTC),
+		// 	intevalKey: "10m",
+		// 	startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// },
+		// "2m offset": {
+		// 	configs:    defaultResConfigs,
+		// 	start:      time.Date(2025, time.May, 3, 0, 9, 0, 0, time.UTC),
+		// 	end:        time.Date(2025, time.May, 3, 0, 11, 0, 0, time.UTC),
+		// 	intevalKey: "10m",
+		// 	startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+		// },
+		"24h": {
 			configs:    defaultResConfigs,
-			start:      time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
-			end:        time.Date(2025, time.May, 3, 1, 0, 0, 0, time.UTC),
+			start:      *win24h.Start(),
+			end:        *win24h.End(),
 			intevalKey: "1h",
-			startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
-		},
-		"1d": {
-			configs:    defaultResConfigs,
-			start:      time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
-			end:        time.Date(2025, time.May, 4, 0, 10, 0, 0, time.UTC),
-			intevalKey: "1d",
-			startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
-		},
-		"2m": {
-			configs:    defaultResConfigs,
-			start:      time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
-			end:        time.Date(2025, time.May, 3, 0, 2, 0, 0, time.UTC),
-			intevalKey: "10m",
-			startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
-		},
-		"2m offset": {
-			configs:    defaultResConfigs,
-			start:      time.Date(2025, time.May, 3, 0, 9, 0, 0, time.UTC),
-			end:        time.Date(2025, time.May, 3, 0, 11, 0, 0, time.UTC),
-			intevalKey: "10m",
-			startKey:   time.Date(2025, time.May, 3, 0, 0, 0, 0, time.UTC),
+			startKey:   *win24h.Start(),
 		},
 	}
 	for name, tt := range tests {
@@ -72,7 +82,7 @@ func Test_repoStoreProvider_getStoreKeys(t *testing.T) {
 				t.Errorf("getStoreKeys() got = %v, want %v", intevalKey, tt.intevalKey)
 			}
 			if !reflect.DeepEqual(startKey, tt.startKey) {
-				t.Errorf("getStoreKeys() got1 = %v, want %v", startKey, tt.startKey)
+				t.Errorf("getStoreKeys() got = %v, want %v", startKey, tt.startKey)
 			}
 		})
 	}