diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 2ee0bafb361..2340e511016 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -66,6 +66,7 @@ CHANGELOG* /licenses/ @elastic/elastic-agent-data-plane /metricbeat/ @elastic/elastic-agent-data-plane /metricbeat/docs/ # Listed without an owner to avoid maintaining doc ownership for each input and module. +/metricbeat/helper/kubernetes @elastic/obs-cloudnative-monitoring /metricbeat/module/ @elastic/integrations /metricbeat/module/apache @elastic/obs-infraobs-integrations /metricbeat/module/beat/ @elastic/infra-monitoring-ui diff --git a/metricbeat/helper/kubernetes/ktest/ktest.go b/metricbeat/helper/kubernetes/ktest/ktest.go index f5394ad0b7a..a8de05cbd05 100644 --- a/metricbeat/helper/kubernetes/ktest/ktest.go +++ b/metricbeat/helper/kubernetes/ktest/ktest.go @@ -47,14 +47,14 @@ func GetTestCases(files []string) ptest.TestCases { return cases } -// TestStateMetricsFamily +// TestMetricsFamily // This function reads the metric files and checks if the resource fetched metrics exist in it. // It only checks the family metric, because if the metric doesn't have any data, we don't have a way // to know the labels from the file. // The test fails if the metric does not exist in any of the files. // A warning is printed if the metric is not present in all of them. // Nothing happens, otherwise. -func TestStateMetricsFamily(t *testing.T, files []string, mapping *p.MetricsMapping) { +func TestMetricsFamily(t *testing.T, files []string, mapping *p.MetricsMapping) { metricsFiles := map[string][]string{} for i := 0; i < len(files); i++ { content, err := ioutil.ReadFile(files[i]) diff --git a/metricbeat/module/kubernetes/controllermanager/controllermanager_test.go b/metricbeat/module/kubernetes/controllermanager/controllermanager_test.go index 8f61e3ac892..48eecde2c3e 100644 --- a/metricbeat/module/kubernetes/controllermanager/controllermanager_test.go +++ b/metricbeat/module/kubernetes/controllermanager/controllermanager_test.go @@ -22,30 +22,33 @@ package controllermanager import ( "testing" + k "github.com/elastic/beats/v7/metricbeat/helper/kubernetes/ktest" "github.com/elastic/beats/v7/metricbeat/helper/prometheus/ptest" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" _ "github.com/elastic/beats/v7/metricbeat/module/kubernetes" ) +var files = []string{ + "./_meta/test/metrics.1.25", + "./_meta/test/metrics.1.26", + "./_meta/test/metrics.1.27", +} + func TestEventMapping(t *testing.T) { - ptest.TestMetricSet(t, "kubernetes", "controllermanager", - ptest.TestCases{ - ptest.TestCase{ - MetricsFile: "./_meta/test/metrics.1.25", - ExpectedFile: "./_meta/test/metrics.1.25.expected", - }, - ptest.TestCase{ - MetricsFile: "./_meta/test/metrics.1.26", - ExpectedFile: "./_meta/test/metrics.1.26.expected", - }, - ptest.TestCase{ - MetricsFile: "./_meta/test/metrics.1.27", - ExpectedFile: "./_meta/test/metrics.1.27.expected", - }, - }, - ) + var testCases ptest.TestCases + for _, file := range files { + testCases = append(testCases, ptest.TestCase{ + MetricsFile: file, + ExpectedFile: file + ".expected", + }) + } + ptest.TestMetricSet(t, "kubernetes", "controllermanager", testCases) } func TestData(t *testing.T) { mbtest.TestDataFiles(t, "kubernetes", "controllermanager") } + +func TestMetricsFamily(t *testing.T) { + k.TestMetricsFamily(t, files, mapping) +} diff --git a/metricbeat/module/kubernetes/proxy/proxy_test.go b/metricbeat/module/kubernetes/proxy/proxy_test.go index ccaaa504fc4..5c636cb9d79 100644 --- a/metricbeat/module/kubernetes/proxy/proxy_test.go +++ b/metricbeat/module/kubernetes/proxy/proxy_test.go @@ -23,31 +23,33 @@ package proxy import ( "testing" + k "github.com/elastic/beats/v7/metricbeat/helper/kubernetes/ktest" "github.com/elastic/beats/v7/metricbeat/helper/prometheus/ptest" - mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" _ "github.com/elastic/beats/v7/metricbeat/module/kubernetes" ) +var files = []string{ + "./_meta/test/metrics.1.25", + "./_meta/test/metrics.1.26", + "./_meta/test/metrics.1.27", +} + func TestEventMapping(t *testing.T) { - ptest.TestMetricSet(t, "kubernetes", "proxy", - ptest.TestCases{ - { - MetricsFile: "./_meta/test/metrics.1.25", - ExpectedFile: "./_meta/test/metrics.1.25.expected", - }, - { - MetricsFile: "./_meta/test/metrics.1.26", - ExpectedFile: "./_meta/test/metrics.1.26.expected", - }, - ptest.TestCase{ - MetricsFile: "./_meta/test/metrics.1.27", - ExpectedFile: "./_meta/test/metrics.1.27.expected", - }, - }, - ) + var testCases ptest.TestCases + for _, file := range files { + testCases = append(testCases, ptest.TestCase{ + MetricsFile: file, + ExpectedFile: file + ".expected", + }) + } + ptest.TestMetricSet(t, "kubernetes", "proxy", testCases) } func TestData(t *testing.T) { mbtest.TestDataFiles(t, "kubernetes", "proxy") } + +func TestMetricsFamily(t *testing.T) { + k.TestMetricsFamily(t, files, mapping) +} diff --git a/metricbeat/module/kubernetes/scheduler/scheduler_test.go b/metricbeat/module/kubernetes/scheduler/scheduler_test.go index 790cf7b17c9..4143a0b29eb 100644 --- a/metricbeat/module/kubernetes/scheduler/scheduler_test.go +++ b/metricbeat/module/kubernetes/scheduler/scheduler_test.go @@ -23,31 +23,33 @@ package scheduler import ( "testing" + k "github.com/elastic/beats/v7/metricbeat/helper/kubernetes/ktest" "github.com/elastic/beats/v7/metricbeat/helper/prometheus/ptest" - mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" _ "github.com/elastic/beats/v7/metricbeat/module/kubernetes" ) +var files = []string{ + "./_meta/test/metrics.1.25", + "./_meta/test/metrics.1.26", + "./_meta/test/metrics.1.27", +} + func TestEventMapping(t *testing.T) { - ptest.TestMetricSet(t, "kubernetes", "scheduler", - ptest.TestCases{ - { - MetricsFile: "./_meta/test/metrics.1.25", - ExpectedFile: "./_meta/test/metrics.1.25.expected", - }, - { - MetricsFile: "./_meta/test/metrics.1.26", - ExpectedFile: "./_meta/test/metrics.1.26.expected", - }, - ptest.TestCase{ - MetricsFile: "./_meta/test/metrics.1.27", - ExpectedFile: "./_meta/test/metrics.1.27.expected", - }, - }, - ) + var testCases ptest.TestCases + for _, file := range files { + testCases = append(testCases, ptest.TestCase{ + MetricsFile: file, + ExpectedFile: file + ".expected", + }) + } + ptest.TestMetricSet(t, "kubernetes", "scheduler", testCases) } func TestData(t *testing.T) { mbtest.TestDataFiles(t, "kubernetes", "scheduler") } + +func TestMetricsFamily(t *testing.T) { + k.TestMetricsFamily(t, files, mapping) +} diff --git a/metricbeat/module/kubernetes/state_container/state_container_test.go b/metricbeat/module/kubernetes/state_container/state_container_test.go index 34725b814bd..5d1361ed5b8 100644 --- a/metricbeat/module/kubernetes/state_container/state_container_test.go +++ b/metricbeat/module/kubernetes/state_container/state_container_test.go @@ -44,5 +44,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_cronjob/state_cronjob_test.go b/metricbeat/module/kubernetes/state_cronjob/state_cronjob_test.go index 95c303f690f..ad30355609f 100644 --- a/metricbeat/module/kubernetes/state_cronjob/state_cronjob_test.go +++ b/metricbeat/module/kubernetes/state_cronjob/state_cronjob_test.go @@ -45,5 +45,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_daemonset/state_daemonset_test.go b/metricbeat/module/kubernetes/state_daemonset/state_daemonset_test.go index dca57dae7e7..fa038b23aa8 100644 --- a/metricbeat/module/kubernetes/state_daemonset/state_daemonset_test.go +++ b/metricbeat/module/kubernetes/state_daemonset/state_daemonset_test.go @@ -47,5 +47,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_deployment/state_deployment_test.go b/metricbeat/module/kubernetes/state_deployment/state_deployment_test.go index 6b390df6f6e..e064a1e0c30 100644 --- a/metricbeat/module/kubernetes/state_deployment/state_deployment_test.go +++ b/metricbeat/module/kubernetes/state_deployment/state_deployment_test.go @@ -46,5 +46,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_job/state_job_test.go b/metricbeat/module/kubernetes/state_job/state_job_test.go index 5a089514ef1..914f2e8e1c8 100644 --- a/metricbeat/module/kubernetes/state_job/state_job_test.go +++ b/metricbeat/module/kubernetes/state_job/state_job_test.go @@ -46,5 +46,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_node/state_node_test.go b/metricbeat/module/kubernetes/state_node/state_node_test.go index d6fd95bf5bd..22a42644253 100644 --- a/metricbeat/module/kubernetes/state_node/state_node_test.go +++ b/metricbeat/module/kubernetes/state_node/state_node_test.go @@ -47,5 +47,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_persistentvolume/state_persistentvolume_test.go b/metricbeat/module/kubernetes/state_persistentvolume/state_persistentvolume_test.go index 2aed51e3a82..4a612271f31 100644 --- a/metricbeat/module/kubernetes/state_persistentvolume/state_persistentvolume_test.go +++ b/metricbeat/module/kubernetes/state_persistentvolume/state_persistentvolume_test.go @@ -45,5 +45,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_persistentvolumeclaim/state_persistentvolumeclaim_test.go b/metricbeat/module/kubernetes/state_persistentvolumeclaim/state_persistentvolumeclaim_test.go index a706918d6a7..2cc3326261c 100644 --- a/metricbeat/module/kubernetes/state_persistentvolumeclaim/state_persistentvolumeclaim_test.go +++ b/metricbeat/module/kubernetes/state_persistentvolumeclaim/state_persistentvolumeclaim_test.go @@ -45,5 +45,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_pod/state_pod_test.go b/metricbeat/module/kubernetes/state_pod/state_pod_test.go index 0d327087936..817c9e7f8d7 100644 --- a/metricbeat/module/kubernetes/state_pod/state_pod_test.go +++ b/metricbeat/module/kubernetes/state_pod/state_pod_test.go @@ -47,5 +47,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_replicaset/state_replicaset_test.go b/metricbeat/module/kubernetes/state_replicaset/state_replicaset_test.go index 340c7b79bc6..38e59cad464 100644 --- a/metricbeat/module/kubernetes/state_replicaset/state_replicaset_test.go +++ b/metricbeat/module/kubernetes/state_replicaset/state_replicaset_test.go @@ -47,5 +47,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_resourcequota/state_resourcequota_test.go b/metricbeat/module/kubernetes/state_resourcequota/state_resourcequota_test.go index 53350c9202d..fbbe3c5bece 100644 --- a/metricbeat/module/kubernetes/state_resourcequota/state_resourcequota_test.go +++ b/metricbeat/module/kubernetes/state_resourcequota/state_resourcequota_test.go @@ -45,5 +45,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_service/state_service_test.go b/metricbeat/module/kubernetes/state_service/state_service_test.go index ab0ba480db6..07d250a9903 100644 --- a/metricbeat/module/kubernetes/state_service/state_service_test.go +++ b/metricbeat/module/kubernetes/state_service/state_service_test.go @@ -46,5 +46,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_statefulset/state_statefulset_test.go b/metricbeat/module/kubernetes/state_statefulset/state_statefulset_test.go index 4d2652f767a..165d9cbbf9e 100644 --- a/metricbeat/module/kubernetes/state_statefulset/state_statefulset_test.go +++ b/metricbeat/module/kubernetes/state_statefulset/state_statefulset_test.go @@ -48,5 +48,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) } diff --git a/metricbeat/module/kubernetes/state_storageclass/state_storageclass_test.go b/metricbeat/module/kubernetes/state_storageclass/state_storageclass_test.go index 30f0f9accaf..1297b59c67b 100644 --- a/metricbeat/module/kubernetes/state_storageclass/state_storageclass_test.go +++ b/metricbeat/module/kubernetes/state_storageclass/state_storageclass_test.go @@ -45,5 +45,5 @@ func TestData(t *testing.T) { } func TestMetricsFamily(t *testing.T) { - k.TestStateMetricsFamily(t, files, mapping) + k.TestMetricsFamily(t, files, mapping) }