Parcourir la source

Fix batch endpoint call

Mauricio Araujo il y a 2 ans
Parent
commit
3842a01ba3
3 fichiers modifiés avec 6 ajouts et 9 suppressions
  1. 0 1
      go.mod
  2. 0 2
      go.sum
  3. 6 6
      internal/billing/usage.go

+ 0 - 1
go.mod

@@ -151,7 +151,6 @@ require (
 	github.com/go-ole/go-ole v1.2.6 // indirect
 	github.com/go-resty/resty/v2 v2.11.0 // indirect
 	github.com/goccy/go-json v0.10.2 // indirect
-	github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
 	github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
 	github.com/google/gnostic v0.6.9 // indirect
 	github.com/google/s2a-go v0.1.4 // indirect

+ 0 - 2
go.sum

@@ -1570,8 +1570,6 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
-github.com/porter-dev/api-contracts v0.2.159 h1:Ze4K0rm8p6sRMxaFW4Nb3dJuzz4NEMQ+UMXMtOKKRQ4=
-github.com/porter-dev/api-contracts v0.2.159/go.mod h1:VV5BzXd02ZdbWIPLVP+PX3GKawJSGQnxorVT2sUZALU=
 github.com/porter-dev/api-contracts v0.2.161 h1:kf1ZcS1032eLabBzjwDs9SVcecXwUxJ2mJUkRl9C8jk=
 github.com/porter-dev/api-contracts v0.2.161/go.mod h1:VV5BzXd02ZdbWIPLVP+PX3GKawJSGQnxorVT2sUZALU=
 github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=

+ 6 - 6
internal/billing/usage.go

@@ -350,7 +350,7 @@ func (m LagoClient) IngestEvents(ctx context.Context, subscriptionID string, eve
 		}
 
 		batch := events[i:end]
-		batchInput := make([]lago.EventInput, len(batch))
+		var batchInput []lago.EventInput
 		for i := range batch {
 			externalSubscriptionID := subscriptionID
 			if enableSandbox {
@@ -367,7 +367,6 @@ func (m LagoClient) IngestEvents(ctx context.Context, subscriptionID string, eve
 				TransactionID:          batch[i].TransactionID,
 				ExternalSubscriptionID: externalSubscriptionID,
 				Code:                   batch[i].EventType,
-				Timestamp:              batch[i].Timestamp,
 				Properties:             batch[i].Properties,
 			}
 			batchInput = append(batchInput, event)
@@ -375,12 +374,13 @@ func (m LagoClient) IngestEvents(ctx context.Context, subscriptionID string, eve
 
 		// Retry each batch to make sure all events are ingested
 		var currentAttempts int
-		for currentAttempts < defaultMaxRetries {
+		for currentAttempts := 0; currentAttempts < defaultMaxRetries; currentAttempts++ {
 			_, lagoErr := m.client.Event().Batch(ctx, &batchInput)
-			if lagoErr == nil {
-				return telemetry.Error(ctx, span, fmt.Errorf(lagoErr.ErrorCode), "error sending ingest events to Lago")
+			if lagoErr != nil {
+				telemetry.Error(ctx, span, err, "failed to send ingest events")
+				continue
 			}
-			currentAttempts++
+			break
 		}
 
 		if currentAttempts == defaultMaxRetries {