Просмотр исходного кода

Merge pull request #2659 from nik-kc/nik/plugins_to_kcm

Cliff Colvin 2 лет назад
Родитель
Сommit
6f36f3fd5d
2 измененных файлов с 8 добавлено и 8 удалено
  1. 5 5
      pkg/customcost/repositoryquerier.go
  2. 3 3
      pkg/customcost/repositoryquerier_test.go

+ 5 - 5
pkg/customcost/repositoryquerier.go

@@ -104,7 +104,7 @@ func hasDaily(opts []opencost.AccumulateOption) bool {
 }
 
 // GetCustomCostAccumulateOption determines defaults in a way that matches options presented in the UI
-func getCustomCostAccumulateOption(window opencost.Window, from []opencost.AccumulateOption) (opencost.AccumulateOption, error) {
+func GetCustomCostAccumulateOption(window opencost.Window, from []opencost.AccumulateOption) (opencost.AccumulateOption, error) {
 	if window.IsOpen() || window.IsNegative() {
 		return opencost.AccumulateOptionNone, fmt.Errorf("invalid window '%s'", window.String())
 	}
@@ -129,9 +129,9 @@ func getCustomCostAccumulateOption(window opencost.Window, from []opencost.Accum
 	dailySteps := time.Duration(dailyStoreDays) * timeutil.Day
 	oldestDaily := time.Now().Add(-1 * dailySteps)
 	// Use daily if...
-	//  (1) daily is an option; and
-	//  (2) we have daily store coverage
-	if hasDaily(from) && oldestDaily.Before(*window.Start()) {
+	//  (1) daily is an option
+	// It is acceptable to query a range for which we only have partial data
+	if hasDaily(from) {
 		return opencost.AccumulateOptionDay, nil
 	}
 
@@ -146,7 +146,7 @@ func (rq *RepositoryQuerier) QueryTimeseries(ctx context.Context, request CostTi
 	window, _ := opencost.NewClosedWindow(request.Start, request.End).GetAccumulateWindow(request.Accumulate)
 	var err error
 	if request.Accumulate == opencost.AccumulateOptionNone {
-		request.Accumulate, err = getCustomCostAccumulateOption(window, nil)
+		request.Accumulate, err = GetCustomCostAccumulateOption(window, nil)
 		if err != nil {
 			return nil, fmt.Errorf("error determining accumulation option: %v", err)
 		}

+ 3 - 3
pkg/customcost/repositoryquerier_test.go

@@ -52,8 +52,8 @@ func TestGetCustomCostAccumulateOption(t *testing.T) {
 		"out of range": {
 			window:  opencost.NewClosedWindow(midnight.Add(-timeutil.Day*120), midnight.Add(-timeutil.Day*30)),
 			from:    nil,
-			want:    opencost.AccumulateOptionNone,
-			wantErr: true,
+			want:    opencost.AccumulateOptionDay,
+			wantErr: false,
 		},
 		"daily from daily, monthly": {
 			window: opencost.NewClosedWindow(nextHour.Add(-time.Hour*24), nextHour),
@@ -67,7 +67,7 @@ func TestGetCustomCostAccumulateOption(t *testing.T) {
 	}
 	for name, tt := range tests {
 		t.Run(name, func(t *testing.T) {
-			got, err := getCustomCostAccumulateOption(tt.window, tt.from)
+			got, err := GetCustomCostAccumulateOption(tt.window, tt.from)
 			if (err != nil) != tt.wantErr {
 				t.Errorf("GetAccumulateOption() error = %v, wantErr %v", err, tt.wantErr)
 				return