mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Metrics: Adds setting for turning off total stats metrics (#19142)
Don't update total stats metrics if reporting is disabled. New setting disable_total_stats for turning off update of total stats (stat_totals_*) metrics. Ref #19137
This commit is contained in:
parent
bf40849a2c
commit
80592e3361
@ -595,6 +595,8 @@ enabled = true
|
|||||||
[metrics]
|
[metrics]
|
||||||
enabled = true
|
enabled = true
|
||||||
interval_seconds = 10
|
interval_seconds = 10
|
||||||
|
# Disable total stats (stat_totals_*) metrics to be generated
|
||||||
|
disable_total_stats = false
|
||||||
|
|
||||||
#If both are set, basic auth will be required for the metrics endpoint.
|
#If both are set, basic auth will be required for the metrics endpoint.
|
||||||
basic_auth_username =
|
basic_auth_username =
|
||||||
|
@ -526,6 +526,8 @@
|
|||||||
[metrics]
|
[metrics]
|
||||||
# Disable / Enable internal metrics
|
# Disable / Enable internal metrics
|
||||||
;enabled = true
|
;enabled = true
|
||||||
|
# Disable total stats (stat_totals_*) metrics to be generated
|
||||||
|
;disable_total_stats = false
|
||||||
|
|
||||||
# Publish interval
|
# Publish interval
|
||||||
;interval_seconds = 10
|
;interval_seconds = 10
|
||||||
|
@ -548,6 +548,9 @@ If set configures the username to use for basic authentication on the metrics en
|
|||||||
### basic_auth_password
|
### basic_auth_password
|
||||||
If set configures the password to use for basic authentication on the metrics endpoint.
|
If set configures the password to use for basic authentication on the metrics endpoint.
|
||||||
|
|
||||||
|
### disable_total_stats
|
||||||
|
If set to `true`, then total stats generation (`stat_totals_*` metrics) is disabled. The default is `false`.
|
||||||
|
|
||||||
### interval_seconds
|
### interval_seconds
|
||||||
|
|
||||||
Flush/Write interval when sending metrics to external TSDB. Defaults to 10s.
|
Flush/Write interval when sending metrics to external TSDB. Defaults to 10s.
|
||||||
|
@ -155,6 +155,10 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (uss *UsageStatsService) updateTotalStats() {
|
func (uss *UsageStatsService) updateTotalStats() {
|
||||||
|
if !uss.Cfg.MetricsEndpointEnabled || uss.Cfg.MetricsEndpointDisableTotalStats {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
statsQuery := models.GetSystemStatsQuery{}
|
statsQuery := models.GetSystemStatsQuery{}
|
||||||
if err := uss.Bus.Dispatch(&statsQuery); err != nil {
|
if err := uss.Bus.Dispatch(&statsQuery); err != nil {
|
||||||
metricsLogger.Error("Failed to get system stats", "error", err)
|
metricsLogger.Error("Failed to get system stats", "error", err)
|
||||||
|
@ -264,6 +264,49 @@ func TestMetrics(t *testing.T) {
|
|||||||
ts.Close()
|
ts.Close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Test update total stats", t, func() {
|
||||||
|
uss := &UsageStatsService{
|
||||||
|
Bus: bus.New(),
|
||||||
|
Cfg: setting.NewCfg(),
|
||||||
|
}
|
||||||
|
uss.Cfg.MetricsEndpointEnabled = true
|
||||||
|
uss.Cfg.MetricsEndpointDisableTotalStats = false
|
||||||
|
getSystemStatsWasCalled := false
|
||||||
|
uss.Bus.AddHandler(func(query *models.GetSystemStatsQuery) error {
|
||||||
|
query.Result = &models.SystemStats{}
|
||||||
|
getSystemStatsWasCalled = true
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("should not update stats when metrics is disabled and total stats is disabled", func() {
|
||||||
|
uss.Cfg.MetricsEndpointEnabled = false
|
||||||
|
uss.Cfg.MetricsEndpointDisableTotalStats = true
|
||||||
|
uss.updateTotalStats()
|
||||||
|
So(getSystemStatsWasCalled, ShouldBeFalse)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("should not update stats when metrics is disabled and total stats enabled", func() {
|
||||||
|
uss.Cfg.MetricsEndpointEnabled = false
|
||||||
|
uss.Cfg.MetricsEndpointDisableTotalStats = false
|
||||||
|
uss.updateTotalStats()
|
||||||
|
So(getSystemStatsWasCalled, ShouldBeFalse)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("should not update stats when metrics is enabled and total stats disabled", func() {
|
||||||
|
uss.Cfg.MetricsEndpointEnabled = true
|
||||||
|
uss.Cfg.MetricsEndpointDisableTotalStats = true
|
||||||
|
uss.updateTotalStats()
|
||||||
|
So(getSystemStatsWasCalled, ShouldBeFalse)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("should update stats when metrics is enabled and total stats enabled", func() {
|
||||||
|
uss.Cfg.MetricsEndpointEnabled = true
|
||||||
|
uss.Cfg.MetricsEndpointDisableTotalStats = false
|
||||||
|
uss.updateTotalStats()
|
||||||
|
So(getSystemStatsWasCalled, ShouldBeTrue)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
|
func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
|
||||||
|
@ -243,6 +243,7 @@ type Cfg struct {
|
|||||||
MetricsEndpointEnabled bool
|
MetricsEndpointEnabled bool
|
||||||
MetricsEndpointBasicAuthUsername string
|
MetricsEndpointBasicAuthUsername string
|
||||||
MetricsEndpointBasicAuthPassword string
|
MetricsEndpointBasicAuthPassword string
|
||||||
|
MetricsEndpointDisableTotalStats bool
|
||||||
PluginsEnableAlpha bool
|
PluginsEnableAlpha bool
|
||||||
PluginsAppsSkipVerifyTLS bool
|
PluginsAppsSkipVerifyTLS bool
|
||||||
DisableSanitizeHtml bool
|
DisableSanitizeHtml bool
|
||||||
@ -907,6 +908,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
cfg.MetricsEndpointDisableTotalStats = iniFile.Section("metrics").Key("disable_total_stats").MustBool(false)
|
||||||
|
|
||||||
analytics := iniFile.Section("analytics")
|
analytics := iniFile.Section("analytics")
|
||||||
ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true)
|
ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user