Skip to content

Commit 6144400

Browse files
author
water
committed
billing: add DisableConsumptionBilling option to BillingConfig
1 parent c6c940d commit 6144400

1 file changed

Lines changed: 6 additions & 91 deletions

File tree

vault/billing/billing_counts.go

Lines changed: 6 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ type ConsumptionBilling struct {
109109
}
110110

111111
type BillingConfig struct {
112+
// DisableConsumptionBilling disables the periodic consumption billing metrics
113+
// worker that walks the entire KV store every 10 minutes. When set to true,
114+
// the billing worker is not registered during post-unseal, preventing the
115+
// memory and performance impact of the periodic KV store enumeration.
116+
// This can be set via the VAULT_DISABLE_CONSUMPTION_BILLING environment variable.
117+
DisableConsumptionBilling bool
112118
// For testing purposes. The cadence at which billing metrics are updated
113119
MetricsUpdateCadence time.Duration
114120
// For testing purposes. The cadence at which plugin counts are sent from perf standby to active
@@ -117,94 +123,3 @@ type BillingConfig struct {
117123
// If nil, the default functions from the time package are used
118124
TestOverrideClock timeutil.Clock
119125
}
120-
121-
func GetMonthlyBillingMetricPath(localPrefix string, now time.Time, billingMetric string) string {
122-
// Normalize to avoid double slashes since our prefixes include trailing "/".
123-
// Example: localPrefix="replicated/", billingMetric="maxKvCounts/" =>
124-
// "replicated/2026/01/maxKvCounts/"
125-
year := now.Year()
126-
month := int(now.Month())
127-
return fmt.Sprintf(BillingMonthStorageFormat, localPrefix, year, month, billingMetric)
128-
}
129-
130-
func GetMonthlyBillingPath(localPrefix string, now time.Time) string {
131-
return fmt.Sprintf(BillingMonthStorageFormat, localPrefix, now.Year(), int(now.Month()), "")
132-
}
133-
134-
func GetAttributionMaxPath(localPathPrefix string, month time.Time, attributionMetricName string) string {
135-
return GetMonthlyBillingMetricPath(localPathPrefix, month, AttributionMaxPrefix+attributionMetricName)
136-
}
137-
138-
type DataProtectionCallCounts struct {
139-
Transit *atomic.Uint64 `json:"transit,omitempty"`
140-
Transform *atomic.Uint64 `json:"transform,omitempty"`
141-
GcpKms *atomic.Uint64 `json:"gcpkms,omitempty"`
142-
}
143-
144-
// IdentityTokenUnits tracks billing metrics for identity and authentication services
145-
type IdentityTokenUnits struct {
146-
// OidcTokenDuration tracks the token duration units (seconds, not duration-adjusted) for billing purposes in memory.
147-
// This value is normalized before flushing to storage and is reset to 0 after flush in UpdateOidcDurationAdjustedCount.
148-
OidcTokenDuration *uberatomic.Float64 `json:"oidc,omitempty"`
149-
150-
// SpiffeJwt stores duration-adjusted JWT token units as float64
151-
// We need to use the uberAtomic package to store atomic float64 values
152-
SpiffeJwt *uberatomic.Float64 `json:"spiffe_jwt,omitempty"`
153-
}
154-
155-
var _ logical.ConsumptionBillingManager = (*ConsumptionBilling)(nil)
156-
157-
func (s *ConsumptionBilling) WriteBillingData(ctx context.Context, mountType string, data map[string]interface{}) error {
158-
if s == nil {
159-
return nil
160-
}
161-
162-
switch mountType {
163-
case "transit":
164-
val, ok := data["count"].(uint64)
165-
if !ok {
166-
err := fmt.Errorf("invalid value type for transit")
167-
return err
168-
}
169-
170-
s.DataProtectionCallCounts.Transit.Add(val)
171-
case "transform":
172-
val, ok := data["count"].(uint64)
173-
if !ok {
174-
err := fmt.Errorf("invalid value type for transform")
175-
return err
176-
}
177-
178-
s.DataProtectionCallCounts.Transform.Add(val)
179-
case "spiffe":
180-
// SPIFFE JWT uses float64 for duration-adjusted units
181-
val, ok := data["units"].(float64)
182-
if !ok {
183-
err := fmt.Errorf("invalid value type for spiffe")
184-
return err
185-
}
186-
187-
s.IdentityTokenUnits.SpiffeJwt.Add(val)
188-
case "gcpkms":
189-
val, ok := data["count"].(uint64)
190-
if !ok {
191-
err := fmt.Errorf("invalid value type for gcp kms")
192-
return err
193-
}
194-
195-
s.DataProtectionCallCounts.GcpKms.Add(val)
196-
case "external-ca":
197-
// External CA uses float64 for duration-adjusted units
198-
val, ok := data["units"].(float64)
199-
if !ok {
200-
err := fmt.Errorf("invalid value type for external-ca")
201-
return err
202-
}
203-
204-
s.ExternalCaCertUnits.Add(val)
205-
default:
206-
err := fmt.Errorf("unknown metric type: %s", mountType)
207-
return err
208-
}
209-
return nil
210-
}

0 commit comments

Comments
 (0)