Skip to content

Commit

Permalink
Small fixes to ingest endpoint (#4537)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauAraujo authored Apr 15, 2024
1 parent 900f3d7 commit c29aa33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions api/server/handlers/billing/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ func (c *IngestEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
telemetry.AttributeKV{Key: "usage-id", Value: proj.UsageID},
)

request := []types.BillingEvent{}
ingestEventsRequest := struct {
Events []types.BillingEvent `json:"billing_events"`
}{}

if ok := c.DecodeAndValidate(w, r, &request); !ok {
if ok := c.DecodeAndValidate(w, r, &ingestEventsRequest); !ok {
err := telemetry.Error(ctx, span, nil, "error decoding ingest events request")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
return
}

err := c.Config().BillingManager.MetronomeClient.IngestEvents(ctx, request)
telemetry.WithAttributes(span,
telemetry.AttributeKV{Key: "usage-events-count", Value: len(ingestEventsRequest.Events)},
)

err := c.Config().BillingManager.MetronomeClient.IngestEvents(ctx, ingestEventsRequest.Events)
if err != nil {
err := telemetry.Error(ctx, span, err, "error ingesting events")
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
Expand Down
4 changes: 4 additions & 0 deletions internal/billing/metronome.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func (m MetronomeClient) GetCustomerDashboard(ctx context.Context, customerID uu

// IngestEvents sends a list of billing events to Metronome's ingest endpoint
func (m MetronomeClient) IngestEvents(ctx context.Context, events []types.BillingEvent) (err error) {
if len(events) == 0 {
return nil
}

path := "ingest"

var currentAttempts int
Expand Down

0 comments on commit c29aa33

Please sign in to comment.