Skip to content

Commit 8552292

Browse files
authored
fix: enabling metronome and usage reporting by default (#1259)
1 parent d7b7b91 commit 8552292

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

server/config/options.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ type Billing struct {
290290
}
291291

292292
type Metronome struct {
293-
Enabled bool `json:"enabled" mapstructure:"enabled" yaml:"enabled"`
293+
Disabled bool `json:"disabled" mapstructure:"disabled" yaml:"disabled"`
294294
URL string `json:"url" mapstructure:"url" yaml:"url"`
295295
ApiKey string `json:"api_key" mapstructure:"api_key" yaml:"api_key"`
296296
DefaultPlan string `json:"default_plan" mapstructure:"default_plan" yaml:"default_plan"`
@@ -300,7 +300,7 @@ type Metronome struct {
300300
type BilledMetrics = map[string]string
301301

302302
type BillingReporter struct {
303-
Enabled bool `json:"enabled" mapstructure:"enabled" yaml:"enabled"`
303+
Disabled bool `json:"disabled" mapstructure:"disabled" yaml:"disabled"`
304304
RefreshInterval time.Duration `json:"refresh_interval" mapstructure:"refresh_interval" yaml:"refresh_interval"`
305305
}
306306

@@ -354,14 +354,12 @@ var DefaultConfig = Config{
354354
},
355355
Billing: Billing{
356356
Metronome: Metronome{
357-
Enabled: false,
358-
URL: "https://api.metronome.com/v1",
359-
ApiKey: "replace_me",
357+
URL: "https://api.metronome.com/v1",
358+
ApiKey: "replace_me",
360359
// random placeholder UUID and not an actual plan
361360
DefaultPlan: "47eda90f-d2e8-4184-8955-cb3a6467782b",
362361
},
363362
Reporter: BillingReporter{
364-
Enabled: false,
365363
RefreshInterval: time.Second * 60, // 60 seconds
366364
},
367365
},

server/services/v1/billing/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (w WindowSize) String() string {
6464
}
6565

6666
func NewProvider() Provider {
67-
if config.DefaultConfig.Billing.Metronome.Enabled {
67+
if !config.DefaultConfig.Billing.Metronome.Disabled {
6868
svc, err := NewMetronomeProvider(config.DefaultConfig.Billing.Metronome)
6969
if !ulog.E(err) {
7070
return svc

server/services/v1/billing/provider_test.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@ import (
2222
)
2323

2424
func TestNewProvider(t *testing.T) {
25-
t.Run("billing is disabled", func(t *testing.T) {
25+
t.Run("billing is enabled by default", func(t *testing.T) {
26+
require.False(t, config.DefaultConfig.Billing.Metronome.Disabled)
2627
provider := NewProvider()
2728

2829
_, ok := provider.(*noop)
29-
require.True(t, ok)
30+
require.False(t, ok)
3031

3132
_, ok = provider.(*Metronome)
32-
require.False(t, ok)
33+
require.True(t, ok)
3334
})
3435

35-
t.Run("billing is enabled", func(t *testing.T) {
36-
config.DefaultConfig.Billing.Metronome.Enabled = true
36+
t.Run("billing is disabled", func(t *testing.T) {
37+
config.DefaultConfig.Billing.Metronome.Disabled = true
3738
provider := NewProvider()
3839

3940
_, ok := provider.(*noop)
40-
require.False(t, ok)
41+
require.True(t, ok)
4142

4243
_, ok = provider.(*Metronome)
43-
require.True(t, ok)
44+
require.False(t, ok)
45+
// reset
46+
config.DefaultConfig.Billing.Metronome.Disabled = false
4447
})
4548
}

server/services/v1/billing/reporter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewUsageReporter(
6262
}
6363

6464
func (r *UsageReporter) Start() {
65-
if config.DefaultConfig.Billing.Reporter.Enabled {
65+
if !config.DefaultConfig.Billing.Reporter.Disabled {
6666
go r.refreshLoop()
6767
}
6868
}

0 commit comments

Comments
 (0)