Skip to content

Commit

Permalink
Metronome feature flag fixes (#4502)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauAraujo authored Apr 4, 2024
1 parent ef7e3fe commit d743b5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions api/server/handlers/billing/credits.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func (c *GetCreditsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

if !proj.GetFeatureFlag(models.MetronomeEnabled, c.Config().LaunchDarklyClient) {
c.WriteResult(w, r, "")

telemetry.WithAttributes(span,
telemetry.AttributeKV{Key: "metronome-enabled", Value: false},
)
return
}

credits, err := c.Config().BillingManager.MetronomeClient.GetCustomerCredits(proj.UsageID)
Expand All @@ -44,5 +49,11 @@ func (c *GetCreditsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

telemetry.WithAttributes(span,
telemetry.AttributeKV{Key: "metronome-enabled", Value: true},
telemetry.AttributeKV{Key: "project-id", Value: proj.ID},
telemetry.AttributeKV{Key: "usage-id", Value: proj.UsageID},
)

c.WriteResult(w, r, credits)
}
3 changes: 2 additions & 1 deletion api/server/handlers/billing/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func (c *CheckPaymentEnabledHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
)
}

if proj.UsageID == uuid.Nil {
if c.Config().ServerConf.MetronomeAPIKey != "" && c.Config().ServerConf.PorterCloudPlanID != "" &&
proj.GetFeatureFlag(models.MetronomeEnabled, c.Config().LaunchDarklyClient) && proj.UsageID == uuid.Nil {
customerID, customerPlanID, err := c.Config().BillingManager.MetronomeClient.CreateCustomerWithPlan(user.CompanyName, proj.Name, proj.ID, proj.BillingID, c.Config().ServerConf.PorterCloudPlanID)
if err != nil {
err = telemetry.Error(ctx, span, err, "error creating Metronome customer")
Expand Down

0 comments on commit d743b5a

Please sign in to comment.