Преглед на файлове

fix: handle processing of multi page athena query results (#3233)

Nishanth Reddy преди 10 месеца
родител
ревизия
a634a36298
променени са 1 файла, в които са добавени 11 реда и са изтрити 6 реда
  1. 11 6
      pkg/cloud/aws/provider.go

+ 11 - 6
pkg/cloud/aws/provider.go

@@ -2057,6 +2057,7 @@ func (aws *AWS) GetSavingsPlanDataFromAthena() error {
 	line_item_usage_start_date DESC`
 
 	page := 0
+	mostRecentDate := ""
 	processResults := func(op *athena.GetQueryResultsOutput) bool {
 		if op == nil {
 			log.Errorf("GetSavingsPlanDataFromAthena: Athena page is nil")
@@ -2066,8 +2067,11 @@ func (aws *AWS) GetSavingsPlanDataFromAthena() error {
 			return false
 		}
 		aws.SavingsPlanDataLock.Lock()
-		aws.SavingsPlanDataByInstanceID = make(map[string]*SavingsPlanData) // Clean out the old data and only report a savingsplan price if its in the most recent run.
-		mostRecentDate := ""
+		defer aws.SavingsPlanDataLock.Unlock()
+		if page == 0 {
+			aws.SavingsPlanDataByInstanceID = make(map[string]*SavingsPlanData) // Clean out the old data and only report a savingsplan price if its in the most recent run.
+		}
+
 		iter := op.ResultSet.Rows
 		if page == 0 && len(iter) > 0 {
 			iter = op.ResultSet.Rows[1:len(op.ResultSet.Rows)]
@@ -2096,7 +2100,6 @@ func (aws *AWS) GetSavingsPlanDataFromAthena() error {
 		for k, r := range aws.SavingsPlanDataByInstanceID {
 			log.DedupedInfof(5, "Savings Plan Instance Data found for node %s : %f at time %s", k, r.EffectiveCost, r.MostRecentDate)
 		}
-		aws.SavingsPlanDataLock.Unlock()
 		return true
 	}
 
@@ -2159,6 +2162,7 @@ func (aws *AWS) GetReservationDataFromAthena() error {
 	line_item_usage_start_date DESC`
 
 	page := 0
+	mostRecentDate := ""
 	processResults := func(op *athena.GetQueryResultsOutput) bool {
 		if op == nil {
 			log.Errorf("GetReservationDataFromAthena: Athena page is nil")
@@ -2168,8 +2172,10 @@ func (aws *AWS) GetReservationDataFromAthena() error {
 			return false
 		}
 		aws.RIDataLock.Lock()
-		aws.RIPricingByInstanceID = make(map[string]*RIData) // Clean out the old data and only report a RI price if its in the most recent run.
-		mostRecentDate := ""
+		defer aws.RIDataLock.Unlock()
+		if page == 0 {
+			aws.RIPricingByInstanceID = make(map[string]*RIData) // Clean out the old data and only report a RI price if its in the most recent run.
+		}
 		iter := op.ResultSet.Rows
 		if page == 0 && len(iter) > 0 {
 			iter = op.ResultSet.Rows[1:len(op.ResultSet.Rows)]
@@ -2198,7 +2204,6 @@ func (aws *AWS) GetReservationDataFromAthena() error {
 		for k, r := range aws.RIPricingByInstanceID {
 			log.DedupedInfof(5, "Reserved Instance Data found for node %s : %f at time %s", k, r.EffectiveCost, r.MostRecentDate)
 		}
-		aws.RIDataLock.Unlock()
 		return true
 	}