|
|
@@ -2,6 +2,7 @@
|
|
|
package billing
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"net/http"
|
|
|
|
|
|
"github.com/porter-dev/porter/api/server/handlers"
|
|
|
@@ -41,6 +42,7 @@ func (c *IngestEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|
|
telemetry.WithAttributes(span,
|
|
|
telemetry.AttributeKV{Key: "metronome-config-exists", Value: c.Config().BillingManager.MetronomeEnabled},
|
|
|
telemetry.AttributeKV{Key: "metronome-enabled", Value: proj.GetFeatureFlag(models.MetronomeEnabled, c.Config().LaunchDarklyClient)},
|
|
|
+ telemetry.AttributeKV{Key: "porter-cloud-enabled", Value: proj.EnableSandbox},
|
|
|
)
|
|
|
return
|
|
|
}
|
|
|
@@ -64,6 +66,13 @@ func (c *IngestEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|
|
telemetry.AttributeKV{Key: "usage-events-count", Value: len(ingestEventsRequest.Events)},
|
|
|
)
|
|
|
|
|
|
+ // For Porter Cloud events, we apend a prefix to avoid collisions
|
|
|
+ if proj.EnableSandbox {
|
|
|
+ for i := range ingestEventsRequest.Events {
|
|
|
+ ingestEventsRequest.Events[i].CustomerID = fmt.Sprintf("porter-cloud-%s", ingestEventsRequest.Events[i].CustomerID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
err := c.Config().BillingManager.MetronomeClient.IngestEvents(ctx, ingestEventsRequest.Events)
|
|
|
if err != nil {
|
|
|
err := telemetry.Error(ctx, span, err, "error ingesting events")
|