From d743b5a274f4f8966a5eb3a0d6c0bc8f344c032f Mon Sep 17 00:00:00 2001 From: Mauricio Araujo Date: Thu, 4 Apr 2024 15:31:13 -0400 Subject: [PATCH] Metronome feature flag fixes (#4502) --- api/server/handlers/billing/credits.go | 11 +++++++++++ api/server/handlers/billing/list.go | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api/server/handlers/billing/credits.go b/api/server/handlers/billing/credits.go index dcbeb6e7e2..033370971f 100644 --- a/api/server/handlers/billing/credits.go +++ b/api/server/handlers/billing/credits.go @@ -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) @@ -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) } diff --git a/api/server/handlers/billing/list.go b/api/server/handlers/billing/list.go index 4cb47807df..ac386fc0f4 100644 --- a/api/server/handlers/billing/list.go +++ b/api/server/handlers/billing/list.go @@ -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")