Skip to content

Commit

Permalink
Align usage report config with Grafana (#5406)
Browse files Browse the repository at this point in the history
* Align usage report config with Grafana

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* fixes tests

* Update pkg/usagestats/reporter.go

Co-authored-by: Christian Haudum <christian.haudum@gmail.com>

* Update docs/sources/configuration/_index.md

Co-authored-by: Christian Haudum <christian.haudum@gmail.com>

* Update docs/sources/configuration/_index.md

Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>

* Update docs/sources/configuration/_index.md

Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>

Co-authored-by: Christian Haudum <christian.haudum@gmail.com>
Co-authored-by: Karen Miller <84039272+KMiller-Grafana@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 2, 2022
1 parent ae39676 commit 95fefa6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
12 changes: 6 additions & 6 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 @@ -2508,14 +2508,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
The `analytics` block configures the reporting of Loki analytics to grafana.com

```yaml
# Whether or not usage report should be disabled.
# CLI flag: -usage-report.disabled
[disabled: <boolean>: default = false]
# When true, enables usage reporting.
# 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 @@ -262,7 +262,7 @@ func New(cfg Config) (*Loki, error) {
Cfg: cfg,
clientMetrics: chunk_storage.NewClientMetrics(),
}

usagestats.Edition("oss")
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 @@ -763,14 +763,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, "Enable anonymous usage reporting.")
}

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 @@ -27,7 +27,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), nil)
require.NoError(t, err)
Expand All @@ -37,7 +37,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), nil)
require.NoError(t, err)
Expand Down Expand Up @@ -86,7 +86,7 @@ func Test_ReportLoop(t *testing.T) {
})
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 @@ -147,7 +147,7 @@ func TestWrongKV(t *testing.T) {
})
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 @@ -72,7 +72,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

0 comments on commit 95fefa6

Please sign in to comment.