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

Add -usage-stats.installation-mode configuration to track the installation mode #3244

Merged
merged 11 commits into from
Oct 20, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [ENHANCEMENT] Query-frontend: truncate queries based on the configured creation grace period (`--validation.create-grace-period`) to avoid querying too far into the future. #3172
* [ENHANCEMENT] Ingester: Reduce activity tracker memory allocation. #3203
* [ENHANCEMENT] Query-frontend: Log more detailed information in the case of a failed query. #3190
* [ENHANCEMENT] Added `-usage-stats.installation-mode` configuration to track the installation mode via the anonymous usage statistics. #3244
* [ENHANCEMENT] Compactor: Add new `cortex_compactor_block_max_time_delta_seconds` histogram for detecting if compaction of blocks is lagging behind. #3240
* [BUGFIX] Flusher: Add `Overrides` as a dependency to prevent panics when starting with `-target=flusher`. #3151

Expand Down
11 changes: 11 additions & 0 deletions cmd/mimir/config-descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -11287,6 +11287,17 @@
"fieldFlag": "usage-stats.enabled",
"fieldType": "boolean",
"fieldCategory": "experimental"
},
{
"kind": "field",
"name": "installation_mode",
"required": false,
"desc": "Installation mode. Supported values: custom, helm, jsonnet.",
"fieldValue": null,
"fieldDefaultValue": "custom",
"fieldFlag": "usage-stats.installation-mode",
"fieldType": "string",
"fieldCategory": "experimental"
}
],
"fieldValue": null,
Expand Down
2 changes: 2 additions & 0 deletions cmd/mimir/help-all.txt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,8 @@ Usage of ./cmd/mimir/mimir:
If enabled on all services, queries can be federated across multiple tenants. The tenant IDs involved need to be specified separated by a '|' character in the 'X-Scope-OrgID' header.
-usage-stats.enabled
[experimental] Enable anonymous usage reporting. (default true)
-usage-stats.installation-mode string
[experimental] Installation mode. Supported values: custom, helm, jsonnet. (default "custom")
-validation.create-grace-period duration
Controls how far into the future incoming samples are accepted compared to the wall clock. Any sample with timestamp `t` will be rejected if `t > (now + validation.create-grace-period)`. Also used by query-frontend to avoid querying too far into the future. 0 to disable. (default 10m)
-validation.enforce-metadata-metric-name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ When the usage statistics reporting is enabled, Grafana Mimir collects the follo
- The timestamp when the anonymous usage statistics reporting was enabled for the first time, and the cluster identifier was created.
- The Mimir version, such as `2.3.0`.
- The Mimir branch, revision, and Golang version that was used to build the binary.
- The installation mode used to deploy Mimir, such as `helm`.
- Information about the **environment** where Mimir is running:
- The operating system, such as `linux`.
- The architecture, such as `amd64`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ usage_stats:
# CLI flag: -usage-stats.enabled
[enabled: <boolean> | default = true]

# (experimental) Installation mode. Supported values: custom, helm, jsonnet.
# CLI flag: -usage-stats.installation-mode
[installation_mode: <string> | default = "custom"]

# The common block holds configurations that configure multiple components at a
# time.
[common: <common>]
Expand Down
3 changes: 3 additions & 0 deletions pkg/mimir/mimir.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func (c *Config) Validate(log log.Logger) error {
if err := c.QueryScheduler.Validate(); err != nil {
return errors.Wrap(err, "invalid query-scheduler config")
}
if err := c.UsageStats.Validate(); err != nil {
return errors.Wrap(err, "invalid usage stats config")
}
if c.isAnyModuleEnabled(AlertManager, Backend) {
if err := c.Alertmanager.Validate(); err != nil {
return errors.Wrap(err, "invalid alertmanager config")
Expand Down
1 change: 1 addition & 0 deletions pkg/mimir/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ func (t *Mimir) initUsageStats() (services.Service, error) {

// Track anonymous usage statistics.
usagestats.GetString("blocks_storage_backend").Set(t.Cfg.BlocksStorage.Bucket.Backend)
usagestats.GetString("installation_mode").Set(t.Cfg.UsageStats.InstallationMode)

t.UsageStatsReporter = usagestats.NewReporter(bucketClient, util_log.Logger, t.Registerer)
return t.UsageStatsReporter, nil
Expand Down
25 changes: 24 additions & 1 deletion pkg/usagestats/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"math"
"net/http"
"strings"
"time"

"github.com/go-kit/log"
Expand All @@ -23,6 +24,7 @@ import (
"github.com/grafana/dskit/services"

"github.com/grafana/mimir/pkg/storage/bucket"
"github.com/grafana/mimir/pkg/util"
)

const (
Expand All @@ -33,13 +35,34 @@ const (
defaultStatsServerURL = "https://stats.grafana.org/mimir-usage-report"
)

const (
installationModeCustom = "custom"
installationModeHelm = "helm"
installationModeJsonnet = "jsonnet"
)

var (
supportedInstallationModes = []string{installationModeCustom, installationModeHelm, installationModeJsonnet}
)

type Config struct {
Enabled bool `yaml:"enabled" category:"experimental"`
Enabled bool `yaml:"enabled" category:"experimental"`
InstallationMode string `yaml:"installation_mode" category:"experimental"`
}

// RegisterFlags adds the flags required to config this to the given FlagSet
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.Enabled, "usage-stats.enabled", true, "Enable anonymous usage reporting.")
f.StringVar(&cfg.InstallationMode, "usage-stats.installation-mode", installationModeCustom, fmt.Sprintf("Installation mode. Supported values: %s.", strings.Join(supportedInstallationModes, ", ")))
}

func (cfg *Config) Validate() error {
if !util.StringsContain(supportedInstallationModes, cfg.InstallationMode) {
return errors.Errorf("unsupported installation mode: %q", cfg.InstallationMode)

}

return nil
}

type Reporter struct {
Expand Down
50 changes: 50 additions & 0 deletions pkg/usagestats/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,56 @@ import (
"github.com/grafana/mimir/pkg/storage/bucket/filesystem"
)

func TestConfigValidation(t *testing.T) {
for _, tc := range []struct {
name string
cfg *Config
expectedError string
}{
{
name: "valid config",
cfg: &Config{
Enabled: true,
InstallationMode: "custom",
},
expectedError: "",
},
{
name: "valid config with helm installation mode",
cfg: &Config{
Enabled: true,
InstallationMode: "helm",
},
expectedError: "",
},
{
name: "valid config with jsonnet installation mode",
cfg: &Config{
Enabled: true,
InstallationMode: "jsonnet",
},
expectedError: "",
},
{
name: "invalid config with unknown installation mode",
cfg: &Config{
Enabled: true,
InstallationMode: "unknown",
},
expectedError: "unsupported installation mode: \"unknown\"",
},
} {
t.Run(tc.name, func(t *testing.T) {
err := tc.cfg.Validate()
if tc.expectedError != "" {
require.ErrorContains(t, err, tc.expectedError)
} else {
require.NoError(t, err)
}
})
}
}

func TestGetNextReportAt(t *testing.T) {
fixtures := map[string]struct {
interval time.Duration
Expand Down