Skip to content

Commit 196c1d7

Browse files
committed
Merge branch 'aws-infra-detection' into 'master'
fix: return a successful billing status check response for AWS instances See merge request postgres-ai/database-lab!727
2 parents 3d17e33 + 7d5fee3 commit 196c1d7

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

engine/internal/billing/billing.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (b *Billing) resetSoftFailureCounter() {
7272

7373
// RegisterInstance registers instance on the Platform.
7474
func (b *Billing) RegisterInstance(ctx context.Context, systemMetrics models.System) error {
75-
if b.props.Infrastructure == global.AWSInfrastructure {
75+
if b.props.IsAWS() {
7676
// Because billing goes through AWS Marketplace.
7777
b.props.UpdateBilling(true)
7878
}
@@ -156,7 +156,7 @@ func (b *Billing) SendUsage(ctx context.Context, systemMetrics models.System) er
156156
}
157157

158158
func (b *Billing) shouldSendPlatformRequests() error {
159-
if b.props.Infrastructure == global.AWSInfrastructure {
159+
if b.props.IsAWS() {
160160
return errors.New("DLE infrastructure is AWS Marketplace")
161161
}
162162

engine/internal/srv/billing.go

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ import (
1515
)
1616

1717
func (s *Server) billingStatus(w http.ResponseWriter, r *http.Request) {
18+
if s.engProps.IsAWS() {
19+
if err := api.WriteJSON(w, http.StatusOK, platform.BillingResponse{
20+
Result: "OK",
21+
BillingActive: true,
22+
}); err != nil {
23+
api.SendError(w, r, err)
24+
return
25+
}
26+
27+
return
28+
}
29+
1830
usageResponse, err := s.billingUsage(r.Context())
1931
if err != nil {
2032
api.SendBadRequestError(w, r, err.Error())

engine/internal/srv/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (s *Server) instanceStatus() *models.InstanceStatus {
109109
Engine: models.Engine{
110110
Version: version.GetVersion(),
111111
Edition: s.engProps.GetEdition(),
112+
InstanceID: s.engProps.InstanceID,
112113
BillingActive: pointer.ToBool(s.engProps.BillingActive),
113114
StartedAt: s.startedAt,
114115
Telemetry: pointer.ToBool(s.Platform.IsTelemetryEnabled()),

engine/pkg/client/platform/telemetry.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type EditionResponse struct {
8585
type BillingResponse struct {
8686
Result string `json:"result"`
8787
BillingActive bool `json:"billing_active"`
88-
Org Org `json:"recognized_org"`
88+
Org *Org `json:"recognized_org,omitempty"`
8989
}
9090

9191
// Org contains organization details.

engine/pkg/config/global/config.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (p *EngineProps) UpdateBilling(activity bool) {
8484

8585
// CheckBilling checks the billing of the DLE instance is active.
8686
func (p *EngineProps) CheckBilling() error {
87-
if p.Infrastructure == AWSInfrastructure {
87+
if p.IsAWS() {
8888
return nil
8989
}
9090

@@ -94,3 +94,8 @@ func (p *EngineProps) CheckBilling() error {
9494

9595
return nil
9696
}
97+
98+
// IsAWS checks if the instance is running on AWS Marketplace.
99+
func (p *EngineProps) IsAWS() bool {
100+
return p.Infrastructure == AWSInfrastructure
101+
}

0 commit comments

Comments
 (0)