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

[Metricbeat/Kibana/stats] exclude_usage=true by default #22654

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ same journal. {pull}18467[18467]

*Metricbeat*

- `kibana` module: `stats` metricset now skips usage collection by default. Set `stats.exclude_usage: false` in the config flag to revert these changes. {pull}22654[22654]
- Move the windows pdh implementation from perfmon to a shared location in order for future modules/metricsets to make use of. {pull}15503[15503]
- Add DynamoDB AWS Metricbeat light module {pull}15097[15097]
- Release elb module as GA. {pull}15485[15485]
Expand Down
6 changes: 4 additions & 2 deletions metricbeat/module/kibana/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package kibana

// Config defines the structure for the Kibana module configuration options
type Config struct {
XPackEnabled bool `config:"xpack.enabled"`
XPackEnabled bool `config:"xpack.enabled"`
StatsExcludeUsage bool `config:"stats.exclude_usage"`
}

// DefaultConfig returns the default configuration for the Kibana module
func DefaultConfig() Config {
return Config{
XPackEnabled: false,
XPackEnabled: false,
StatsExcludeUsage: true,
}
}
4 changes: 3 additions & 1 deletion metricbeat/module/kibana/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
// MetricSet can be used to build other metricsets within the Kibana module.
type MetricSet struct {
mb.BaseMetricSet
XPackEnabled bool
XPackEnabled bool
StatsExcludeUsage bool
}

// NewMetricSet creates a metricset that can be used to build other metricsets
Expand All @@ -38,5 +39,6 @@ func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) {
return &MetricSet{
base,
config.XPackEnabled,
config.StatsExcludeUsage,
}, nil
}
5 changes: 4 additions & 1 deletion metricbeat/module/kibana/mtest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package mtest

// GetConfig returns config for kibana module
func GetConfig(metricset string, host string, xpackEnabled bool) map[string]interface{} {
func GetConfig(metricset string, host string, xpackEnabled bool, statsExcludeUsage bool) map[string]interface{} {
config := map[string]interface{}{
"module": "kibana",
"metricsets": []string{metricset},
Expand All @@ -27,6 +27,9 @@ func GetConfig(metricset string, host string, xpackEnabled bool) map[string]inte
if xpackEnabled {
config["xpack.enabled"] = true
}
if !statsExcludeUsage {
config["stats.exclude_usage"] = false
}

return config
}
6 changes: 5 additions & 1 deletion metricbeat/module/kibana/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type MetricSet struct {
usageLastCollectedOn time.Time
usageNextCollectOn time.Time
isUsageExcludable bool
statsExcludeUsage bool
}

// New create a new instance of the MetricSet
Expand Down Expand Up @@ -148,6 +149,8 @@ func (m *MetricSet) init() error {
m.statsHTTP = statsHTTP
m.settingsHTTP = settingsHTTP
m.isUsageExcludable = kibana.IsUsageExcludable(kibanaVersion)
// Copying the config to an internal property to make tests easier to implement
m.statsExcludeUsage = m.StatsExcludeUsage

return nil
}
Expand Down Expand Up @@ -221,5 +224,6 @@ func (m *MetricSet) calculateIntervalMs() int64 {
}

func (m *MetricSet) shouldCollectUsage(now time.Time) bool {
return now.Sub(m.usageLastCollectedOn) > usageCollectionPeriod && now.Sub(m.usageNextCollectOn) > 0
return !m.statsExcludeUsage && // If the config claims we should exclude the usage, there is no need to check for the time
now.Sub(m.usageLastCollectedOn) > usageCollectionPeriod && now.Sub(m.usageNextCollectOn) > 0
}
4 changes: 2 additions & 2 deletions metricbeat/module/kibana/stats/stats_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
func TestFetch(t *testing.T) {
service := compose.EnsureUpWithTimeout(t, 570, "kibana")

config := mtest.GetConfig("stats", service.Host(), false)
config := mtest.GetConfig("stats", service.Host(), false, true)
host := config["hosts"].([]string)[0]
version, err := getKibanaVersion(t, host)
require.NoError(t, err)
Expand All @@ -63,7 +63,7 @@ func TestFetch(t *testing.T) {
func TestData(t *testing.T) {
service := compose.EnsureUp(t, "kibana")

config := mtest.GetConfig("stats", service.Host(), false)
config := mtest.GetConfig("stats", service.Host(), false, true)
host := config["hosts"].([]string)[0]
version, err := getKibanaVersion(t, host)
require.NoError(t, err)
Expand Down
13 changes: 12 additions & 1 deletion metricbeat/module/kibana/stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestFetchUsage(t *testing.T) {
}))
defer kib.Close()

config := mtest.GetConfig("stats", kib.URL, true)
config := mtest.GetConfig("stats", kib.URL, true, false)

f := mbtest.NewReportingMetricSetV2Error(t, config)

Expand All @@ -84,29 +84,40 @@ func TestShouldCollectUsage(t *testing.T) {
cases := map[string]struct {
usageLastCollectedOn time.Time
usageNextCollectOn time.Time
statsExcludeUsage bool
expectedResult bool
}{
"within_usage_collection_period": {
usageLastCollectedOn: now.Add(-1 * usageCollectionPeriod),
statsExcludeUsage: false,
expectedResult: false,
},
"after_usage_collection_period_but_before_next_scheduled_collection": {
usageLastCollectedOn: now.Add(-2 * usageCollectionPeriod),
usageNextCollectOn: now.Add(3 * time.Hour),
statsExcludeUsage: false,
expectedResult: false,
},
"after_usage_collection_period_and_after_next_scheduled_collection": {
usageLastCollectedOn: now.Add(-2 * usageCollectionPeriod),
usageNextCollectOn: now.Add(-1 * time.Hour),
statsExcludeUsage: false,
expectedResult: true,
},
"any_time_when_exclude_usage_is_true": {
usageLastCollectedOn: now.Add(-2 * usageCollectionPeriod),
usageNextCollectOn: now.Add(-1 * time.Hour),
statsExcludeUsage: true,
expectedResult: false,
},
}

for name, test := range cases {
t.Run(name, func(t *testing.T) {
m := MetricSet{
usageLastCollectedOn: test.usageLastCollectedOn,
usageNextCollectOn: test.usageNextCollectOn,
statsExcludeUsage: test.statsExcludeUsage,
}

actualResult := m.shouldCollectUsage(now)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
func TestFetch(t *testing.T) {
service := compose.EnsureUpWithTimeout(t, 570, "kibana")

f := mbtest.NewReportingMetricSetV2Error(t, mtest.GetConfig("status", service.Host(), false))
f := mbtest.NewReportingMetricSetV2Error(t, mtest.GetConfig("status", service.Host(), false, true))
events, errs := mbtest.ReportingFetchV2Error(f)

require.Empty(t, errs)
Expand Down