From 0d52ea4f0c0ade03b0902bb11aeb3090fc4012fa Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 10 Mar 2020 12:35:19 +0000 Subject: [PATCH 1/6] working monitoring tests --- .../agent/pkg/agent/operation/common_test.go | 103 ++++++++++++++++++ .../pkg/agent/operation/monitoring_test.go | 2 - .../pkg/agent/operation/operator_test.go | 80 -------------- 3 files changed, 103 insertions(+), 82 deletions(-) create mode 100644 x-pack/agent/pkg/agent/operation/common_test.go diff --git a/x-pack/agent/pkg/agent/operation/common_test.go b/x-pack/agent/pkg/agent/operation/common_test.go new file mode 100644 index 000000000000..3985f296173c --- /dev/null +++ b/x-pack/agent/pkg/agent/operation/common_test.go @@ -0,0 +1,103 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package operation + +import ( + "context" + "testing" + "time" + + operatorCfg "github.com/elastic/beats/v7/x-pack/agent/pkg/agent/operation/config" + "github.com/elastic/beats/v7/x-pack/agent/pkg/agent/stateresolver" + "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact" + "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact/download" + "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact/install" + "github.com/elastic/beats/v7/x-pack/agent/pkg/config" + "github.com/elastic/beats/v7/x-pack/agent/pkg/core/logger" + "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/app" + "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/app/monitoring" + "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/process" + "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/retry" +) + +var installPath = "tests/scripts" + +func getTestOperator(t *testing.T, installPath string) (*Operator, *operatorCfg.Config) { + operatorConfig := &operatorCfg.Config{ + RetryConfig: &retry.Config{ + Enabled: true, + RetriesCount: 2, + Delay: 3 * time.Second, + MaxDelay: 10 * time.Second, + }, + ProcessConfig: &process.Config{}, + DownloadConfig: &artifact.Config{ + InstallPath: installPath, + }, + MonitoringConfig: &monitoring.Config{ + MonitorMetrics: false, + }, + } + + cfg, err := config.NewConfigFrom(operatorConfig) + if err != nil { + t.Fatal(err) + } + + l := getLogger() + + fetcher := &DummyDownloader{} + installer := &DummyInstaller{} + + stateResolver, err := stateresolver.NewStateResolver(l) + if err != nil { + t.Fatal(err) + } + + operator, err := NewOperator(context.Background(), l, "p1", cfg, fetcher, installer, stateResolver, nil) + if err != nil { + t.Fatal(err) + } + + operator.config.DownloadConfig.OperatingSystem = "darwin" + operator.config.DownloadConfig.Architecture = "32" + + return operator, operatorConfig +} + +func getLogger() *logger.Logger { + l, _ := logger.New() + return l +} + +func getProgram(binary, version string) *app.Descriptor { + downloadCfg := &artifact.Config{ + InstallPath: installPath, + OperatingSystem: "darwin", + } + return app.NewDescriptor(binary, version, downloadCfg, nil) +} + +type TestConfig struct { + TestFile string +} + +type DummyDownloader struct { +} + +func (*DummyDownloader) Download(_ context.Context, p, v string) (string, error) { + return "", nil +} + +var _ download.Downloader = &DummyDownloader{} + +type DummyInstaller struct { +} + +func (*DummyInstaller) Install(p, v, _ string) error { + return nil +} + +var _ install.Installer = &DummyInstaller{} diff --git a/x-pack/agent/pkg/agent/operation/monitoring_test.go b/x-pack/agent/pkg/agent/operation/monitoring_test.go index 8ceabd6220a5..4b2ae2b444ef 100644 --- a/x-pack/agent/pkg/agent/operation/monitoring_test.go +++ b/x-pack/agent/pkg/agent/operation/monitoring_test.go @@ -2,8 +2,6 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -// +build linux darwin - package operation import ( diff --git a/x-pack/agent/pkg/agent/operation/operator_test.go b/x-pack/agent/pkg/agent/operation/operator_test.go index 608250098741..de095e06225d 100644 --- a/x-pack/agent/pkg/agent/operation/operator_test.go +++ b/x-pack/agent/pkg/agent/operation/operator_test.go @@ -30,8 +30,6 @@ import ( "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/state" ) -var installPath = "tests/scripts" - func TestMain(m *testing.M) { // init supported with test cases shortSpec := program.Spec{ @@ -374,81 +372,3 @@ func TestConfigurableByFileRun(t *testing.T) { t.Fatal("Process found") } } - -func getTestOperator(t *testing.T, installPath string) (*Operator, *operatorCfg.Config) { - operatorConfig := &operatorCfg.Config{ - RetryConfig: &retry.Config{ - Enabled: true, - RetriesCount: 2, - Delay: 3 * time.Second, - MaxDelay: 10 * time.Second, - }, - ProcessConfig: &process.Config{}, - DownloadConfig: &artifact.Config{ - InstallPath: installPath, - }, - MonitoringConfig: &monitoring.Config{ - MonitorMetrics: false, - }, - } - - cfg, err := config.NewConfigFrom(operatorConfig) - if err != nil { - t.Fatal(err) - } - - l := getLogger() - - fetcher := &DummyDownloader{} - installer := &DummyInstaller{} - - stateResolver, err := stateresolver.NewStateResolver(l) - if err != nil { - t.Fatal(err) - } - - operator, err := NewOperator(context.Background(), l, "p1", cfg, fetcher, installer, stateResolver, nil) - if err != nil { - t.Fatal(err) - } - - operator.config.DownloadConfig.OperatingSystem = "darwin" - operator.config.DownloadConfig.Architecture = "32" - - return operator, operatorConfig -} - -func getLogger() *logger.Logger { - l, _ := logger.New() - return l -} - -func getProgram(binary, version string) *app.Descriptor { - downloadCfg := &artifact.Config{ - InstallPath: installPath, - OperatingSystem: "darwin", - } - return app.NewDescriptor(binary, version, downloadCfg, nil) -} - -type TestConfig struct { - TestFile string -} - -type DummyDownloader struct { -} - -func (*DummyDownloader) Download(_ context.Context, p, v string) (string, error) { - return "", nil -} - -var _ download.Downloader = &DummyDownloader{} - -type DummyInstaller struct { -} - -func (*DummyInstaller) Install(p, v, _ string) error { - return nil -} - -var _ install.Installer = &DummyInstaller{} From 119faf489eed374b787588d33bb209dfff865f0a Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 10 Mar 2020 12:53:46 +0000 Subject: [PATCH 2/6] fix monitoring drop tests --- .../app/monitoring/beats/beats_monitor.go | 5 ++- .../plugin/app/monitoring/beats/drop_test.go | 44 +++++++++---------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/x-pack/agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go b/x-pack/agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go index 146ab6c447f8..d749fbc02d32 100644 --- a/x-pack/agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go +++ b/x-pack/agent/pkg/core/plugin/app/monitoring/beats/beats_monitor.go @@ -150,7 +150,10 @@ func (b *Monitor) monitoringDrop() string { func monitoringDrop(path string) (drop string) { defer func() { if drop != "" { - drop = filepath.Dir(drop) + // Dir call changes separator to the one used in OS + // '/var/lib' -> '\var\lib\' on windows + baseLen := len(filepath.Dir(drop)) + drop = drop[:baseLen] } }() diff --git a/x-pack/agent/pkg/core/plugin/app/monitoring/beats/drop_test.go b/x-pack/agent/pkg/core/plugin/app/monitoring/beats/drop_test.go index 6478dda5225b..0f1d42a1ceda 100644 --- a/x-pack/agent/pkg/core/plugin/app/monitoring/beats/drop_test.go +++ b/x-pack/agent/pkg/core/plugin/app/monitoring/beats/drop_test.go @@ -5,41 +5,39 @@ package beats import ( - "runtime" "testing" ) type testCase struct { - Endpoint string - Drop string - SkipWindows bool + Endpoint string + Drop string } func TestMonitoringDrops(t *testing.T) { cases := []testCase{ - testCase{`/var/lib/drop/abc.sock`, "/var/lib/drop", true}, - testCase{`npipe://drop`, "", false}, - testCase{`http+npipe://drop`, "", false}, - testCase{`\\.\pipe\drop`, "", false}, - testCase{`unix:///var/lib/drop/abc.sock`, "/var/lib/drop", true}, - testCase{`http+unix:///var/lib/drop/abc.sock`, "/var/lib/drop", true}, - testCase{`file:///var/lib/drop/abc.sock`, "/var/lib/drop", true}, - testCase{`http://localhost/stats`, "", false}, - testCase{`localhost/stats`, "", false}, - testCase{`http://localhost:8080/stats`, "", false}, - testCase{`localhost:8080/stats`, "", false}, - testCase{`http://1.2.3.4/stats`, "", false}, - testCase{`http://1.2.3.4:5678/stats`, "", false}, - testCase{`1.2.3.4:5678/stats`, "", false}, - testCase{`http://hithere.com:5678/stats`, "", false}, - testCase{`hithere.com:5678/stats`, "", false}, + testCase{`/var/lib/drop/abc.sock`, "/var/lib/drop"}, + testCase{`npipe://drop`, ""}, + testCase{`http+npipe://drop`, ""}, + testCase{`\\.\pipe\drop`, ""}, + testCase{`unix:///var/lib/drop/abc.sock`, "/var/lib/drop"}, + testCase{`http+unix:///var/lib/drop/abc.sock`, "/var/lib/drop"}, + testCase{`file:///var/lib/drop/abc.sock`, "/var/lib/drop"}, + testCase{`http://localhost/stats`, ""}, + testCase{`localhost/stats`, ""}, + testCase{`http://localhost:8080/stats`, ""}, + testCase{`localhost:8080/stats`, ""}, + testCase{`http://1.2.3.4/stats`, ""}, + testCase{`http://1.2.3.4:5678/stats`, ""}, + testCase{`1.2.3.4:5678/stats`, ""}, + testCase{`http://hithere.com:5678/stats`, ""}, + testCase{`hithere.com:5678/stats`, ""}, } for _, c := range cases { t.Run(c.Endpoint, func(t *testing.T) { - if runtime.GOOS == "windows" && c.SkipWindows { - t.Skip("Skipped under windows") - } + // if runtime.GOOS == "windows" && c.SkipWindows { + // t.Skip("Skipped under windows") + // } drop := monitoringDrop(c.Endpoint) if drop != c.Drop { From 06cf453bf6a68ff3b3484db47d2254b6ea339d37 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 10 Mar 2020 13:56:42 +0100 Subject: [PATCH 3/6] imports --- x-pack/agent/pkg/agent/operation/operator_test.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/x-pack/agent/pkg/agent/operation/operator_test.go b/x-pack/agent/pkg/agent/operation/operator_test.go index de095e06225d..07e24f69ef3d 100644 --- a/x-pack/agent/pkg/agent/operation/operator_test.go +++ b/x-pack/agent/pkg/agent/operation/operator_test.go @@ -7,7 +7,6 @@ package operation import ( - "context" "fmt" "math/rand" "os" @@ -15,18 +14,9 @@ import ( "testing" "time" - operatorCfg "github.com/elastic/beats/v7/x-pack/agent/pkg/agent/operation/config" "github.com/elastic/beats/v7/x-pack/agent/pkg/agent/program" - "github.com/elastic/beats/v7/x-pack/agent/pkg/agent/stateresolver" "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact" - "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact/download" - "github.com/elastic/beats/v7/x-pack/agent/pkg/artifact/install" - "github.com/elastic/beats/v7/x-pack/agent/pkg/config" - "github.com/elastic/beats/v7/x-pack/agent/pkg/core/logger" "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/app" - "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/app/monitoring" - "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/process" - "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/retry" "github.com/elastic/beats/v7/x-pack/agent/pkg/core/plugin/state" ) From 0791c1ea33c0bfdb3c9f3e568dbc16016aed2e1b Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 10 Mar 2020 14:14:45 +0100 Subject: [PATCH 4/6] added changelog --- x-pack/agent/CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 x-pack/agent/CHANGELOG.md diff --git a/x-pack/agent/CHANGELOG.md b/x-pack/agent/CHANGELOG.md new file mode 100644 index 000000000000..f8ac02f42ce5 --- /dev/null +++ b/x-pack/agent/CHANGELOG.md @@ -0,0 +1,9 @@ +## Agent version 8.0.0 + +### Breaking changes + +### Bugfixes + +- Fixed tests on windows [16922](https://github.com/elastic/beats/pull/16922) + +### New features From 8b3c49ec8e2d97a47babe8579564ee9f78821e14 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 10 Mar 2020 14:20:23 +0100 Subject: [PATCH 5/6] md -> asciidoc --- x-pack/agent/CHANGELOG.asciidoc | 17 +++++++++++++++++ x-pack/agent/CHANGELOG.md | 9 --------- 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 x-pack/agent/CHANGELOG.asciidoc delete mode 100644 x-pack/agent/CHANGELOG.md diff --git a/x-pack/agent/CHANGELOG.asciidoc b/x-pack/agent/CHANGELOG.asciidoc new file mode 100644 index 000000000000..090d0b36487e --- /dev/null +++ b/x-pack/agent/CHANGELOG.asciidoc @@ -0,0 +1,17 @@ +// Use these for links to issue and pulls. Note issues and pulls redirect one to +// each other on Github, so don't worry too much on using the right prefix. +:issue: https://github.com/elastic/beats/issues/ +:pull: https://github.com/elastic/beats/pull/ + + +[[release-notes-8.0.0]] +=== Agent version 8.0.0 + + +==== Breaking changes + +==== Bugfixes + +- Fixed tests on windows {pull}16922[16922] + +==== New features diff --git a/x-pack/agent/CHANGELOG.md b/x-pack/agent/CHANGELOG.md deleted file mode 100644 index f8ac02f42ce5..000000000000 --- a/x-pack/agent/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -## Agent version 8.0.0 - -### Breaking changes - -### Bugfixes - -- Fixed tests on windows [16922](https://github.com/elastic/beats/pull/16922) - -### New features From 4c289cd0adf0c31b7e6a67a30dade2544d0de601 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 10 Mar 2020 14:35:01 +0100 Subject: [PATCH 6/6] removed comments --- .../agent/pkg/core/plugin/app/monitoring/beats/drop_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x-pack/agent/pkg/core/plugin/app/monitoring/beats/drop_test.go b/x-pack/agent/pkg/core/plugin/app/monitoring/beats/drop_test.go index 0f1d42a1ceda..a4d06169ca85 100644 --- a/x-pack/agent/pkg/core/plugin/app/monitoring/beats/drop_test.go +++ b/x-pack/agent/pkg/core/plugin/app/monitoring/beats/drop_test.go @@ -35,10 +35,6 @@ func TestMonitoringDrops(t *testing.T) { for _, c := range cases { t.Run(c.Endpoint, func(t *testing.T) { - // if runtime.GOOS == "windows" && c.SkipWindows { - // t.Skip("Skipped under windows") - // } - drop := monitoringDrop(c.Endpoint) if drop != c.Drop { t.Errorf("Case[%s]: Expected '%s', got '%s'", c.Endpoint, c.Drop, drop)