Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align usage report config with Grafana #5406

Merged
merged 6 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/sources/configuration/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Pass the `-config.expand-env` flag at the command line to enable this way of set
[common: <common>]

# Configuration for usage report
[usage_report: <usage_report>]
[analytics: <analytics>]
```

## server
Expand Down Expand Up @@ -2499,14 +2499,14 @@ This way, one doesn't have to replicate configuration in multiple places.
[ring: <ring>]
```

## usage_report
## analytics

This block allow to configure usage report of Loki to grafana.com
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved

```yaml
# Whether or not usage report should be disabled.
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved
# CLI flag: -usage-report.disabled
[disabled: <boolean>: default = false]
# CLI flag: -reporting.enabled
[reporting_enabled: <boolean>: default = true]
```

### storage
Expand Down
4 changes: 2 additions & 2 deletions pkg/loki/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type Config struct {
Tracing tracing.Config `yaml:"tracing"`
CompactorConfig compactor.Config `yaml:"compactor,omitempty"`
QueryScheduler scheduler.Config `yaml:"query_scheduler"`
UsageReport usagestats.Config `yaml:"usage_report"`
UsageReport usagestats.Config `yaml:"analytics"`
}

// RegisterFlags registers flag.
Expand Down Expand Up @@ -261,7 +261,7 @@ func New(cfg Config) (*Loki, error) {
Cfg: cfg,
clientMetrics: chunk_storage.NewClientMetrics(),
}

usagestats.Edition("oss")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I feel this would be better in RegisterFlags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to overrides this in enterprise and I need a way to know when it happens hence why I move it inside the New here. So I can override after New.

loki.setupAuthMiddleware()
loki.setupGRPCRecoveryMiddleware()
if err := loki.setupModuleManager(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,14 +754,14 @@ func (t *Loki) initQueryScheduler() (services.Service, error) {
}

func (t *Loki) initUsageReport() (services.Service, error) {
if t.Cfg.UsageReport.Disabled {
if !t.Cfg.UsageReport.Enabled {
return nil, nil
}
t.Cfg.UsageReport.Leader = false
if t.isModuleActive(Ingester) {
t.Cfg.UsageReport.Leader = true
}
usagestats.Edition("oss")

usagestats.Target(t.Cfg.Target.String())
period, err := t.Cfg.SchemaConfig.SchemaForTime(model.Now())
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/usagestats/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ var (
)

type Config struct {
Disabled bool `yaml:"disabled"`
Leader bool `yaml:"-"`
Enabled bool `yaml:"reporting_enabled"`
Leader bool `yaml:"-"`
}

// RegisterFlags adds the flags required to config this to the given FlagSet
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.Disabled, "usage-report.disabled", false, "Disable anonymous usage reporting.")
f.BoolVar(&cfg.Enabled, "reporting.enabled", true, "Enabled anonymous usage reporting.")
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved
}

type Reporter struct {
Expand All @@ -62,7 +62,7 @@ type Reporter struct {
}

func NewReporter(config Config, kvConfig kv.Config, objectClient chunk.ObjectClient, logger log.Logger, reg prometheus.Registerer) (*Reporter, error) {
if config.Disabled {
if !config.Enabled {
return nil, nil
}
r := &Reporter{
Expand Down
8 changes: 4 additions & 4 deletions pkg/usagestats/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_LeaderElection(t *testing.T) {
require.NoError(t, err)
for i := 0; i < 3; i++ {
go func() {
r, err := NewReporter(Config{Leader: true}, kv.Config{
r, err := NewReporter(Config{Leader: true, Enabled: true}, kv.Config{
Store: "inmemory",
}, objectClient, log.NewLogfmtLogger(os.Stdout), prometheus.NewPedanticRegistry())
require.NoError(t, err)
Expand All @@ -42,7 +42,7 @@ func Test_LeaderElection(t *testing.T) {
}
for i := 0; i < 7; i++ {
go func() {
r, err := NewReporter(Config{Leader: false}, kv.Config{
r, err := NewReporter(Config{Leader: false, Enabled: true}, kv.Config{
Store: "inmemory",
}, objectClient, log.NewLogfmtLogger(os.Stdout), prometheus.NewPedanticRegistry())
require.NoError(t, err)
Expand Down Expand Up @@ -93,7 +93,7 @@ func Test_ReportLoop(t *testing.T) {
}, metrics)
require.NoError(t, err)

r, err := NewReporter(Config{Leader: true}, kv.Config{
r, err := NewReporter(Config{Leader: true, Enabled: true}, kv.Config{
Store: "inmemory",
}, objectClient, log.NewLogfmtLogger(os.Stdout), prometheus.NewPedanticRegistry())
require.NoError(t, err)
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestWrongKV(t *testing.T) {
}, metrics)
require.NoError(t, err)

r, err := NewReporter(Config{Leader: true}, kv.Config{
r, err := NewReporter(Config{Leader: true, Enabled: true}, kv.Config{
Store: "",
}, objectClient, log.NewLogfmtLogger(os.Stdout), prometheus.NewPedanticRegistry())
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/usagestats/seed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func Test_Memberlist(t *testing.T) {
for i := 0; i < 10; i++ {
go func(i int) {
leader, err := NewReporter(Config{
Leader: true,
Leader: true,
Enabled: true,
}, kv.Config{
Store: "memberlist",
StoreConfig: kv.StoreConfig{
Expand Down