فهرست منبع

Metronome feature flag fixes (#4502)

Mauricio Araujo 2 سال پیش
والد
کامیت
d743b5a274
2فایلهای تغییر یافته به همراه13 افزوده شده و 1 حذف شده
  1. 11 0
      api/server/handlers/billing/credits.go
  2. 2 1
      api/server/handlers/billing/list.go

+ 11 - 0
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)
 }

+ 2 - 1
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")