From 58017fad2babd3cac6b172fcdbbdabd7e69814b8 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 29 Jun 2020 11:25:04 -0400 Subject: [PATCH 1/7] Fix downloading so its not hard coded to beats repo name. --- .../pkg/agent/operation/common_test.go | 2 +- .../pkg/agent/operation/operation.go | 1 + .../pkg/agent/operation/operation_fetch.go | 2 +- .../elastic-agent/pkg/agent/program/spec.go | 1 + .../pkg/agent/program/spec_test.go | 2 ++ .../pkg/agent/program/supported.go | 2 +- x-pack/elastic-agent/pkg/artifact/config.go | 6 ++--- .../artifact/download/composed/downloader.go | 4 ++-- .../download/composed/downloader_test.go | 6 ++--- .../pkg/artifact/download/downloader.go | 2 +- .../pkg/artifact/download/fs/downloader.go | 2 +- .../pkg/artifact/download/fs/verifier_test.go | 6 +++-- .../pkg/artifact/download/http/downloader.go | 24 +++++++++---------- .../artifact/download/http/elastic_test.go | 11 +++++---- .../pkg/artifact/download/http/verifier.go | 4 ++-- .../artifact/download/snapshot/downloader.go | 4 ++-- .../elastic-agent/pkg/core/app/descriptor.go | 7 ++++++ x-pack/elastic-agent/spec/endpoint.yml | 1 + x-pack/elastic-agent/spec/filebeat.yml | 1 + x-pack/elastic-agent/spec/metricbeat.yml | 1 + 20 files changed, 53 insertions(+), 36 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/operation/common_test.go b/x-pack/elastic-agent/pkg/agent/operation/common_test.go index c314a5d7fdbe..06268615099a 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/common_test.go +++ b/x-pack/elastic-agent/pkg/agent/operation/common_test.go @@ -144,7 +144,7 @@ func waitFor(t *testing.T, check func() error) { type DummyDownloader struct{} -func (*DummyDownloader) Download(_ context.Context, p, v string) (string, error) { +func (*DummyDownloader) Download(_ context.Context, r, p, v string) (string, error) { return "", nil } diff --git a/x-pack/elastic-agent/pkg/agent/operation/operation.go b/x-pack/elastic-agent/pkg/agent/operation/operation.go index 3f5201f2fedc..04c25d6a85ee 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/operation.go +++ b/x-pack/elastic-agent/pkg/agent/operation/operation.go @@ -49,6 +49,7 @@ type Application interface { // Is passed around operator operations. type Descriptor interface { ServicePort() int + RepoName() string BinaryName() string Version() string ID() string diff --git a/x-pack/elastic-agent/pkg/agent/operation/operation_fetch.go b/x-pack/elastic-agent/pkg/agent/operation/operation_fetch.go index bb01890347b8..57a67bb9ee46 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/operation_fetch.go +++ b/x-pack/elastic-agent/pkg/agent/operation/operation_fetch.go @@ -70,7 +70,7 @@ func (o *operationFetch) Run(ctx context.Context, application Application) (err } }() - fullPath, err := o.downloader.Download(ctx, o.program.BinaryName(), o.program.Version()) + fullPath, err := o.downloader.Download(ctx, o.program.RepoName(), o.program.BinaryName(), o.program.Version()) if err == nil { o.logger.Infof("operation '%s' downloaded %s.%s into %s", o.Name(), o.program.BinaryName(), o.program.Version(), fullPath) } diff --git a/x-pack/elastic-agent/pkg/agent/program/spec.go b/x-pack/elastic-agent/pkg/agent/program/spec.go index ed5fc61047ca..7e32d2c1b1ec 100644 --- a/x-pack/elastic-agent/pkg/agent/program/spec.go +++ b/x-pack/elastic-agent/pkg/agent/program/spec.go @@ -28,6 +28,7 @@ var ErrMissingWhen = errors.New("program must define a 'When' expression") // to register their spec in a secure way. type Spec struct { Name string `yaml:"name"` + Repo string `yaml:"repo"` ServicePort int `yaml:"service,omitempty"` Cmd string `yaml:"cmd"` Args []string `yaml:"args"` diff --git a/x-pack/elastic-agent/pkg/agent/program/spec_test.go b/x-pack/elastic-agent/pkg/agent/program/spec_test.go index df847de7afff..6a8c38dfb2f5 100644 --- a/x-pack/elastic-agent/pkg/agent/program/spec_test.go +++ b/x-pack/elastic-agent/pkg/agent/program/spec_test.go @@ -22,6 +22,7 @@ import ( func TestSerialization(t *testing.T) { spec := Spec{ Name: "hello", + Repo: "reponame", Cmd: "hellocmd", Args: []string{"-c", "first"}, Rules: transpiler.NewRuleList( @@ -56,6 +57,7 @@ func TestSerialization(t *testing.T) { When: "1 == 1", } yml := `name: hello +repo: reponame cmd: hellocmd args: - -c diff --git a/x-pack/elastic-agent/pkg/agent/program/supported.go b/x-pack/elastic-agent/pkg/agent/program/supported.go index bdc9c951fbcc..857044d5daaf 100644 --- a/x-pack/elastic-agent/pkg/agent/program/supported.go +++ b/x-pack/elastic-agent/pkg/agent/program/supported.go @@ -20,7 +20,7 @@ func init() { // spec/endpoint.yml // spec/filebeat.yml // spec/metricbeat.yml - unpacked := packer.MustUnpack("eJzsWEuTq7gV3udn3G1SCYi2J6RqFoYeXnbT17hbEtohyQZsganGL0jlv6cEGIPdM3PvzSSrLLrsxnqcx3e+8x3++aUs1uxv65wX+zQ//LXKxJd/fKGZdSBv+zhAkx2z9YLmy/gdwC3HXsGd3TwE6u41NQTNgjMF4shNtSbIV1kmlPWyqAn2QIR88ZrOgF/HT2bm7wnyPzAQR6YFCbXPUzNVYoITEap6FqGLeI33sWvOYmZbSvS8j90MHoljnCI0URbYF6EGqwgHE7dbF2IvZ/V+Lr+7phK7OREsE9l65bbPnKCgCJ44Xk7d55ezmRsnpgWbCE1qblslfd7PFytDrG24xYAU1H6fmqk8yziHONi/prOU3Pw/sJv/abcuYRmvr3YvVrO0P9t0b3alyoFjI2eZtSOr8XOWwZpqsAoBrN3BOb9y72j9Ii8KZn7m6y/Vy6w4swxuOJoUNPeVEF3K13h/cG34RJC/IZkoyVsXO8dIuB1PXdP7PJ9Xm22rItpLF6NrzOHxwedHWyqOLkLmarEysggnG6YFFUHW4TU1ftosu+foohDsbXhmlRzBPq4MwJIgX6GaO3VtcWQOVNi5/S0CcPKaGsoaG6LLCQjRRSW4t1P63OPIbGJACuoEggn9bq1RE3QRoRac2HYfR2hy5jiou98+CN5N5Vkh8kqClp2vJKEOFEMccsdTycgn9/H8fGgfKQmCyu3/sY+LlXHiODhzvJybOd8T9DR1f0kSpljH9SrOSXYRBC/z+WqWeanhhtj3uA0PrIrFWj0UNDdU7vh8s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2JwoMvbkRf28wjJo1ZHIs/Dml4TcbX/cgWg+1zEKAsSJNHrVJcWDuifIV0njc6swz6wXXGN/1F++euY5nPeks55QPRO3K3gnYhmSdBWClNMWqZU3ErqpyFgSvJF9rBSbnWBa5ZuOsGXxXRXiSC19H+Ogj6nl/R5C8Uhw2Ejt/oeKxQFbgxhpJC4oGvvJnOXG8b1o7ITTe0HyayLjGgP8f/H5e4hPglOF5bbERBcnDHpSu3/7+EB4zm28G+9JeSTqD4sG1njJnfSN5bAgOK2vZw6FYiIKzUbiDGefv67AwFHa07WAtEQ2klp4Zrt7sToUAWHcFZlvrMmmAmVs8Aac3QkKWfRl47f54SZJxv3EwCXlDnzjQCixbTQEcbF1lzMcXO9gKlCGPWWObx8fjM0XN9SZ8/rnVVaV72PU/3VnPBwSv587FSSzBmRWbGdzb02B5GaOLjfB5qhpDOBbhP0muhdsA0ZGngBjcZ1g5WqzbOafvkNITtbdRFdDUM/bHZZmfvVib6xd37PGsZUIf+c51zWW3sX4xwXu8D6z+e1ncxwIfBUa/VtXxze/pdGkM73wi7x+rTFz8TPjgbFGfs872GzfG85Gf0ZhSrCsoUYjc5GDVNDd4d2718yf/sGny8f/5h1s1dnAG4LCkjWdkOtF8nP3uXukkU1ObLHSSn766dO///SfAAAA//9z8uWf") SupportedMap = make(map[string]Spec) for f, v := range unpacked { diff --git a/x-pack/elastic-agent/pkg/artifact/config.go b/x-pack/elastic-agent/pkg/artifact/config.go index aefe35c26e1e..a8a09de8e485 100644 --- a/x-pack/elastic-agent/pkg/artifact/config.go +++ b/x-pack/elastic-agent/pkg/artifact/config.go @@ -21,8 +21,8 @@ type Config struct { // Architecture: target architecture [32, 64] Architecture string `json:"-" config:",ignore"` - // BeatsSourceURI: source of the artifacts, e.g https://artifacts.elastic.co/downloads/beats/ - BeatsSourceURI string `json:"sourceURI" config:"sourceURI"` + // SourceURI: source of the artifacts, e.g https://artifacts.elastic.co/downloads/ + SourceURI string `json:"sourceURI" config:"sourceURI"` // TargetDirectory: path to the directory containing downloaded packages TargetDirectory string `json:"targetDirectory" config:"target_directory"` @@ -49,7 +49,7 @@ type Config struct { func DefaultConfig() *Config { dataPath := paths.Data() return &Config{ - BeatsSourceURI: "https://artifacts.elastic.co/downloads/beats/", + SourceURI: "https://artifacts.elastic.co/downloads/", TargetDirectory: filepath.Join(dataPath, "downloads"), Timeout: 30 * time.Second, PgpFile: filepath.Join(dataPath, "elastic.pgp"), diff --git a/x-pack/elastic-agent/pkg/artifact/download/composed/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/composed/downloader.go index c87608612691..ac485647228a 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/composed/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/composed/downloader.go @@ -32,11 +32,11 @@ func NewDownloader(downloaders ...download.Downloader) *Downloader { // Download fetches the package from configured source. // Returns absolute path to downloaded package and an error. -func (e *Downloader) Download(ctx context.Context, programName, version string) (string, error) { +func (e *Downloader) Download(ctx context.Context, repoName, programName, version string) (string, error) { var err error for _, d := range e.dd { - s, e := d.Download(ctx, programName, version) + s, e := d.Download(ctx, repoName, programName, version) if e == nil { return s, nil } diff --git a/x-pack/elastic-agent/pkg/artifact/download/composed/downloader_test.go b/x-pack/elastic-agent/pkg/artifact/download/composed/downloader_test.go index 9f720fae2354..34b4e6580414 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/composed/downloader_test.go +++ b/x-pack/elastic-agent/pkg/artifact/download/composed/downloader_test.go @@ -18,7 +18,7 @@ type FailingDownloader struct { called bool } -func (d *FailingDownloader) Download(ctx context.Context, a, b string) (string, error) { +func (d *FailingDownloader) Download(ctx context.Context, a, b, c string) (string, error) { d.called = true return "", errors.New("failing") } @@ -29,7 +29,7 @@ type SuccDownloader struct { called bool } -func (d *SuccDownloader) Download(ctx context.Context, a, b string) (string, error) { +func (d *SuccDownloader) Download(ctx context.Context, a, b, c string) (string, error) { d.called = true return "succ", nil } @@ -58,7 +58,7 @@ func TestComposed(t *testing.T) { for _, tc := range testCases { d := NewDownloader(tc.downloaders[0], tc.downloaders[1]) - r, _ := d.Download(nil, "a", "b") + r, _ := d.Download(nil, "a", "b", "c") assert.Equal(t, tc.expectedResult, r == "succ") diff --git a/x-pack/elastic-agent/pkg/artifact/download/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/downloader.go index 0b7010062e9b..331c738ac182 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/downloader.go @@ -8,5 +8,5 @@ import "context" // Downloader is an interface allowing download of an artifact type Downloader interface { - Download(ctx context.Context, programName, version string) (string, error) + Download(ctx context.Context, repoName, programName, version string) (string, error) } diff --git a/x-pack/elastic-agent/pkg/artifact/download/fs/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/fs/downloader.go index 877409080695..995746f7a43e 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/fs/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/fs/downloader.go @@ -39,7 +39,7 @@ func NewDownloader(config *artifact.Config) *Downloader { // Download fetches the package from configured source. // Returns absolute path to downloaded package and an error. -func (e *Downloader) Download(_ context.Context, programName, version string) (_ string, err error) { +func (e *Downloader) Download(_ context.Context, _, programName, version string) (_ string, err error) { downloadedFiles := make([]string, 0, 2) defer func() { if err != nil { diff --git a/x-pack/elastic-agent/pkg/artifact/download/fs/verifier_test.go b/x-pack/elastic-agent/pkg/artifact/download/fs/verifier_test.go index 25c5df2efda3..36eb3c518dc5 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/fs/verifier_test.go +++ b/x-pack/elastic-agent/pkg/artifact/download/fs/verifier_test.go @@ -20,6 +20,7 @@ import ( ) const ( + repoName = "beats" beatName = "filebeat" version = "7.5.1" sourcePattern = "/downloads/beats/filebeat/" @@ -36,6 +37,7 @@ func TestFetchVerify(t *testing.T) { installPath := filepath.Join("testdata", "install") targetPath := filepath.Join("testdata", "download") ctx := context.Background() + repoName := "beats" programName := "beat" version := "8.0.0" @@ -77,7 +79,7 @@ func TestFetchVerify(t *testing.T) { // second one should pass // download not skipped: package missing // verify passes because hash is not correct - _, err = downloader.Download(ctx, programName, version) + _, err = downloader.Download(ctx, repoName, programName, version) assert.NoError(t, err) // file downloaded ok @@ -146,7 +148,7 @@ func TestVerify(t *testing.T) { } testClient := NewDownloader(config) - artifact, err := testClient.Download(context.Background(), beatName, version) + artifact, err := testClient.Download(context.Background(), repoName, beatName, version) if err != nil { t.Fatal(err) } diff --git a/x-pack/elastic-agent/pkg/artifact/download/http/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/http/downloader.go index 63d093a66470..622f0b2509da 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/http/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/http/downloader.go @@ -51,7 +51,7 @@ func NewDownloaderWithClient(config *artifact.Config, client http.Client) *Downl // Download fetches the package from configured source. // Returns absolute path to downloaded package and an error. -func (e *Downloader) Download(ctx context.Context, programName, version string) (_ string, err error) { +func (e *Downloader) Download(ctx context.Context, repoName, programName, version string) (_ string, err error) { downloadedFiles := make([]string, 0, 2) defer func() { if err != nil { @@ -62,19 +62,19 @@ func (e *Downloader) Download(ctx context.Context, programName, version string) }() // download from source to dest - path, err := e.download(ctx, e.config.OS(), programName, version) + path, err := e.download(ctx, e.config.OS(), repoName, programName, version) downloadedFiles = append(downloadedFiles, path) if err != nil { return "", err } - hashPath, err := e.downloadHash(ctx, e.config.OS(), programName, version) + hashPath, err := e.downloadHash(ctx, e.config.OS(), repoName, programName, version) downloadedFiles = append(downloadedFiles, hashPath) return path, err } -func (e *Downloader) composeURI(programName, packageName string) (string, error) { - upstream := e.config.BeatsSourceURI +func (e *Downloader) composeURI(repoName, programName, packageName string) (string, error) { + upstream := e.config.SourceURI if !strings.HasPrefix(upstream, "http") && !strings.HasPrefix(upstream, "file") && !strings.HasPrefix(upstream, "/") { // always default to https upstream = fmt.Sprintf("https://%s", upstream) @@ -86,11 +86,11 @@ func (e *Downloader) composeURI(programName, packageName string) (string, error) return "", errors.New(err, "invalid upstream URI", errors.TypeConfig) } - uri.Path = path.Join(uri.Path, programName, packageName) + uri.Path = path.Join(uri.Path, repoName, programName, packageName) return uri.String(), nil } -func (e *Downloader) download(ctx context.Context, operatingSystem, programName, version string) (string, error) { +func (e *Downloader) download(ctx context.Context, operatingSystem, repoName, programName, version string) (string, error) { filename, err := artifact.GetArtifactName(programName, version, operatingSystem, e.config.Arch()) if err != nil { return "", errors.New(err, "generating package name failed") @@ -101,10 +101,10 @@ func (e *Downloader) download(ctx context.Context, operatingSystem, programName, return "", errors.New(err, "generating package path failed") } - return e.downloadFile(ctx, programName, filename, fullPath) + return e.downloadFile(ctx, repoName, programName, filename, fullPath) } -func (e *Downloader) downloadHash(ctx context.Context, operatingSystem, programName, version string) (string, error) { +func (e *Downloader) downloadHash(ctx context.Context, operatingSystem, repoName, programName, version string) (string, error) { filename, err := artifact.GetArtifactName(programName, version, operatingSystem, e.config.Arch()) if err != nil { return "", errors.New(err, "generating package name failed") @@ -118,11 +118,11 @@ func (e *Downloader) downloadHash(ctx context.Context, operatingSystem, programN filename = filename + ".sha512" fullPath = fullPath + ".sha512" - return e.downloadFile(ctx, programName, filename, fullPath) + return e.downloadFile(ctx, repoName, programName, filename, fullPath) } -func (e *Downloader) downloadFile(ctx context.Context, programName, filename, fullPath string) (string, error) { - sourceURI, err := e.composeURI(programName, filename) +func (e *Downloader) downloadFile(ctx context.Context, repoName, programName, filename, fullPath string) (string, error) { + sourceURI, err := e.composeURI(repoName, programName, filename) if err != nil { return "", err } diff --git a/x-pack/elastic-agent/pkg/artifact/download/http/elastic_test.go b/x-pack/elastic-agent/pkg/artifact/download/http/elastic_test.go index 8087fc288234..2614fbbd407d 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/http/elastic_test.go +++ b/x-pack/elastic-agent/pkg/artifact/download/http/elastic_test.go @@ -22,10 +22,11 @@ import ( ) const ( + repoName = "beats" beatName = "filebeat" version = "7.5.1" sourcePattern = "/downloads/beats/filebeat/" - source = "http://artifacts.elastic.co/downloads/beats/" + source = "http://artifacts.elastic.co/downloads/" ) type testCase struct { @@ -44,7 +45,7 @@ func TestDownload(t *testing.T) { elasticClient := getElasticCoClient() config := &artifact.Config{ - BeatsSourceURI: source, + SourceURI: source, TargetDirectory: targetDir, Timeout: timeout, } @@ -56,7 +57,7 @@ func TestDownload(t *testing.T) { config.Architecture = testCase.arch testClient := NewDownloaderWithClient(config, elasticClient) - artifactPath, err := testClient.Download(context.Background(), beatName, version) + artifactPath, err := testClient.Download(context.Background(), repoName, beatName, version) if err != nil { t.Fatal(err) } @@ -82,7 +83,7 @@ func TestVerify(t *testing.T) { elasticClient := getElasticCoClient() config := &artifact.Config{ - BeatsSourceURI: source, + SourceURI: source, TargetDirectory: targetDir, Timeout: timeout, } @@ -94,7 +95,7 @@ func TestVerify(t *testing.T) { config.Architecture = testCase.arch testClient := NewDownloaderWithClient(config, elasticClient) - artifact, err := testClient.Download(context.Background(), beatName, version) + artifact, err := testClient.Download(context.Background(), repoName, beatName, version) if err != nil { t.Fatal(err) } diff --git a/x-pack/elastic-agent/pkg/artifact/download/http/verifier.go b/x-pack/elastic-agent/pkg/artifact/download/http/verifier.go index 486f222c8e50..171b3363aecc 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/http/verifier.go +++ b/x-pack/elastic-agent/pkg/artifact/download/http/verifier.go @@ -173,7 +173,7 @@ func (v *Verifier) verifyAsc(programName, version string) (bool, error) { } func (v *Verifier) composeURI(programName, filename string) (string, error) { - upstream := v.config.BeatsSourceURI + upstream := v.config.SourceURI if !strings.HasPrefix(upstream, "http") && !strings.HasPrefix(upstream, "file") && !strings.HasPrefix(upstream, "/") { // always default to https upstream = fmt.Sprintf("https://%s", upstream) @@ -185,7 +185,7 @@ func (v *Verifier) composeURI(programName, filename string) (string, error) { return "", errors.New(err, "invalid upstream URI", errors.TypeNetwork, errors.M(errors.MetaKeyURI, upstream)) } - uri.Path = path.Join(uri.Path, programName, filename+ascSuffix) + uri.Path = path.Join(uri.Path, "beats", programName, filename+ascSuffix) return uri.String(), nil } diff --git a/x-pack/elastic-agent/pkg/artifact/download/snapshot/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/snapshot/downloader.go index 022cda0ffffc..f45a38d3f973 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/snapshot/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/snapshot/downloader.go @@ -35,7 +35,7 @@ func snapshotConfig(config *artifact.Config) (*artifact.Config, error) { return &artifact.Config{ OperatingSystem: config.OperatingSystem, Architecture: config.Architecture, - BeatsSourceURI: snapshotURI, + SourceURI: snapshotURI, TargetDirectory: config.TargetDirectory, Timeout: config.Timeout, PgpFile: config.PgpFile, @@ -81,7 +81,7 @@ func snapshotURI() (string, error) { return "", fmt.Errorf("uri is not a string") } - index := strings.Index(uri, "/elastic-agent/") + index := strings.Index(uri, "/beats/elastic-agent/") if index == -1 { return "", fmt.Errorf("not an agent uri: '%s'", uri) } diff --git a/x-pack/elastic-agent/pkg/core/app/descriptor.go b/x-pack/elastic-agent/pkg/core/app/descriptor.go index 5f556405971e..f0ee517f451d 100644 --- a/x-pack/elastic-agent/pkg/core/app/descriptor.go +++ b/x-pack/elastic-agent/pkg/core/app/descriptor.go @@ -16,6 +16,7 @@ import ( // Descriptor defines a program which needs to be run. // Is passed around operator operations. type Descriptor struct { + repoName string executionCtx ExecutionContext directory string spec ProcessSpec @@ -27,6 +28,7 @@ func NewDescriptor(pSpec program.Spec, version string, config *artifact.Config, dir := directory(binaryName, version, config) return &Descriptor{ + repoName: pSpec.Repo, directory: dir, executionCtx: NewExecutionContext(pSpec.ServicePort, binaryName, version, tags), spec: spec(dir, binaryName), @@ -39,6 +41,11 @@ func (p *Descriptor) ServicePort() int { return p.executionCtx.ServicePort } +// RepoName is the name of the repository the binary is built from. E.g beats. +func (p *Descriptor) RepoName() string { + return p.repoName +} + // BinaryName is the name of the binary. E.g filebeat. func (p *Descriptor) BinaryName() string { return p.executionCtx.BinaryName diff --git a/x-pack/elastic-agent/spec/endpoint.yml b/x-pack/elastic-agent/spec/endpoint.yml index e864c182e6e8..10f9d86ae85a 100644 --- a/x-pack/elastic-agent/spec/endpoint.yml +++ b/x-pack/elastic-agent/spec/endpoint.yml @@ -1,4 +1,5 @@ name: Endpoint Security +repo: endpoint-dev cmd: endpoint-security service: 6788 check_install: diff --git a/x-pack/elastic-agent/spec/filebeat.yml b/x-pack/elastic-agent/spec/filebeat.yml index 20305373674e..ff567749b8e2 100644 --- a/x-pack/elastic-agent/spec/filebeat.yml +++ b/x-pack/elastic-agent/spec/filebeat.yml @@ -1,4 +1,5 @@ name: Filebeat +repo: beats cmd: filebeat args: ["-E", "setup.ilm.enabled=false", "-E", "setup.template.enabled=false", "-E", "management.mode=x-pack-fleet", "-E", "management.enabled=true", "-E", "logging.level=debug"] rules: diff --git a/x-pack/elastic-agent/spec/metricbeat.yml b/x-pack/elastic-agent/spec/metricbeat.yml index 14552838b75f..1b62452c0bbe 100644 --- a/x-pack/elastic-agent/spec/metricbeat.yml +++ b/x-pack/elastic-agent/spec/metricbeat.yml @@ -1,4 +1,5 @@ name: Metricbeat +repo: beats cmd: metricbeat args: ["-E", "setup.ilm.enabled=false", "-E", "setup.template.enabled=false", "-E", "management.mode=x-pack-fleet", "-E", "management.enabled=true", "-E", "logging.level=debug"] post_install: From 123ba3e520635c87c0c2310b95648eef29488ead Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 29 Jun 2020 16:49:04 -0400 Subject: [PATCH 2/7] Add artifact to spec file, use artifact for download. --- .../pkg/agent/operation/operation.go | 2 +- .../pkg/agent/operation/operation_fetch.go | 2 +- .../elastic-agent/pkg/agent/program/spec.go | 2 +- .../pkg/agent/program/supported.go | 2 +- x-pack/elastic-agent/pkg/artifact/artifact.go | 4 ++-- .../artifact/download/composed/downloader.go | 4 ++-- .../pkg/artifact/download/downloader.go | 2 +- .../pkg/artifact/download/fs/downloader.go | 10 ++++----- .../pkg/artifact/download/http/downloader.go | 22 +++++++++---------- .../elastic-agent/pkg/core/app/descriptor.go | 10 ++++----- x-pack/elastic-agent/pkg/release/version.go | 6 ++--- x-pack/elastic-agent/spec/endpoint.yml | 2 +- x-pack/elastic-agent/spec/filebeat.yml | 2 +- x-pack/elastic-agent/spec/metricbeat.yml | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/operation/operation.go b/x-pack/elastic-agent/pkg/agent/operation/operation.go index 04c25d6a85ee..ebe6bc3065db 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/operation.go +++ b/x-pack/elastic-agent/pkg/agent/operation/operation.go @@ -49,8 +49,8 @@ type Application interface { // Is passed around operator operations. type Descriptor interface { ServicePort() int - RepoName() string BinaryName() string + ArtifactName() string Version() string ID() string Directory() string diff --git a/x-pack/elastic-agent/pkg/agent/operation/operation_fetch.go b/x-pack/elastic-agent/pkg/agent/operation/operation_fetch.go index 57a67bb9ee46..fc72915ee604 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/operation_fetch.go +++ b/x-pack/elastic-agent/pkg/agent/operation/operation_fetch.go @@ -70,7 +70,7 @@ func (o *operationFetch) Run(ctx context.Context, application Application) (err } }() - fullPath, err := o.downloader.Download(ctx, o.program.RepoName(), o.program.BinaryName(), o.program.Version()) + fullPath, err := o.downloader.Download(ctx, o.program.BinaryName(), o.program.ArtifactName(), o.program.Version()) if err == nil { o.logger.Infof("operation '%s' downloaded %s.%s into %s", o.Name(), o.program.BinaryName(), o.program.Version(), fullPath) } diff --git a/x-pack/elastic-agent/pkg/agent/program/spec.go b/x-pack/elastic-agent/pkg/agent/program/spec.go index 7e32d2c1b1ec..2d859c1950b4 100644 --- a/x-pack/elastic-agent/pkg/agent/program/spec.go +++ b/x-pack/elastic-agent/pkg/agent/program/spec.go @@ -28,10 +28,10 @@ var ErrMissingWhen = errors.New("program must define a 'When' expression") // to register their spec in a secure way. type Spec struct { Name string `yaml:"name"` - Repo string `yaml:"repo"` ServicePort int `yaml:"service,omitempty"` Cmd string `yaml:"cmd"` Args []string `yaml:"args"` + Artifact string `yaml:"artifact"` Rules *transpiler.RuleList `yaml:"rules"` CheckInstallSteps *transpiler.StepList `yaml:"check_install"` PostInstallSteps *transpiler.StepList `yaml:"post_install"` diff --git a/x-pack/elastic-agent/pkg/agent/program/supported.go b/x-pack/elastic-agent/pkg/agent/program/supported.go index 857044d5daaf..343466f7e494 100644 --- a/x-pack/elastic-agent/pkg/agent/program/supported.go +++ b/x-pack/elastic-agent/pkg/agent/program/supported.go @@ -20,7 +20,7 @@ func init() { // spec/endpoint.yml // spec/filebeat.yml // spec/metricbeat.yml - unpacked := packer.MustUnpack("eJzsWF2To7gVfc/PmNekEhCDE1K1D4ZevtqNx3S3JPSGJDdgC0wNtjGk8t9TAozB3bO7M9nNUx662pb1ce/Vueeeq399qsot+9u24OUhK45/bXLx6Z+faG4fycshCZG+Z45R0mKTvAK449gvubt/ZDmsaXtIyO33I3EgsPLgSB7m42y6DsCG52In9w527PN6We5iB+5iVc4NlAhdqnVyOHoO/ExQ8EZyUZGXw6NnLRPPNVPuJAvP8gXNw5oCceKW2hIUqCwXyvbZ6+c5dkO0p4WVLRPPWh49ywcE+yUp9lk/ZioxUgXVoLLOlu3TsqypFigYiBPTwpQ69cLKlITgVESqkcfoItbJQe6VMMdW4odD4uXwRFzzHCNdWeFARBpsYhzq3jAvwn7B2sFuS0m8fNw7u9nlHVcY1kTzU+K83o37ggFDZXkgWONN9vn43Pl8fRHj5Ue+Xp52y0fm+gJr8BQjveWOXdGHw+Pq2RRbB+4wICV1XofYmXWEw8M6W2bfuM/rGSnLeXuN0RBzlb7z+QNbClgR/NTHOxefsRYoLIcpfTkkW015HMYr7sAGaySlLhRjXN1AUAfuuGM068wsaWGq3H0aMHAU25dDwl1Rk01vF8/tiiM42il9HnG07GIg71oh2H+7n8sArAgKFKp5C88RJ+ZChdX9bzGA+jqTe9kZdeB+8BVE6KL2vg0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qTYtcD2Y4iBSe64F5wjEEPbh3fp6i+gU5DcKQz5ZCrnW6Je9ZljK7NAxQNa9XguVDX0cjvgZ3UMyqdgiBdNdQTReaevOmfl1hxaVn1XPxbYHffH0c1Rw8QqAaCAqh6VrZN+1nfExTopA64LZ2au0LG3WBuBcBqsyI4qhMU9qBmnZkRTe6snUC6xjS5M07uUfqZeLBUdzRim80GhwoiThuk3+5IChxUvAleqXumAtR2aC7l6qwatxLWshAVtWf7BIcDyCxY0e771BfhZzyAwNsh3RjaBAgTNNsTnA4FoG2wpQbf4GPTFZg4JRIqcOghVN8yLzjHADYMmPVQlBTMtjEwT0Rejx3YihMDsOaOmZEiEuwRUHu99dBQK+1Q9P5HCnkonsGe3k49Y88P9/NvwNB3AGRHDWuGgVNS5zug1519P3M0sD76PjvTydC3xMYNBfNWT75T5jeIqtu6OPYAetNqd6mZAGWOVw+2GtEZg+uRGavp8BxAbZSjCQj8kB+3HOYEkTOT7381TPZNOtgOQwAb/MjdbMskLAjObhePHhpaDQ+XDqUznH/+ugR9HzNe9r857P9VQHBvl8LvQkJ7WVz9O0AZbjkQWuIoAORi483/GDh7garxzeLZXH3pgOa/l3l5/Bij7qc94/mQBmP4sbWUtRdgXUzBq7+YTNbeL0Gqf6uL4H2Q6lkC4DbGQR0/QmCvkVufuMPjSCuDzaG4xayzraIGERi0QDG2o8/T6L35DwDlA5j8EIT+mXcGcP0LoZnjUGBw/z5p6DfDWlIEZ5WXB/33+R0zxG/29ckcXcpvXWRvM3IClLceA2BJUKipy/qoPqbz+Q8B2/Q7s7XSHX45BLiiE3+6L4naesRYG32XNorzOi2Gy1EHYbCMcaipWUqQU8cgLZatDXdw823+NUbka7xu/y4p4IolmsRmRzv9+edP//ivfwYAAP//Yq/3CA==") SupportedMap = make(map[string]Spec) for f, v := range unpacked { diff --git a/x-pack/elastic-agent/pkg/artifact/artifact.go b/x-pack/elastic-agent/pkg/artifact/artifact.go index 72c9ad06a2a6..b4961b56da72 100644 --- a/x-pack/elastic-agent/pkg/artifact/artifact.go +++ b/x-pack/elastic-agent/pkg/artifact/artifact.go @@ -21,14 +21,14 @@ var packageArchMap = map[string]string{ } // GetArtifactName constructs a path to a downloaded artifact -func GetArtifactName(program, version, operatingSystem, arch string) (string, error) { +func GetArtifactName(artifactPath, version, operatingSystem, arch string) (string, error) { key := fmt.Sprintf("%s-binary-%s", operatingSystem, arch) suffix, found := packageArchMap[key] if !found { return "", errors.New(fmt.Sprintf("'%s' is not a valid combination for a package", key), errors.TypeConfig) } - return fmt.Sprintf("%s-%s-%s", program, version, suffix), nil + return fmt.Sprintf("%s-%s-%s", artifactPath, version, suffix), nil } // GetArtifactPath returns a full path of artifact for a program in specific version diff --git a/x-pack/elastic-agent/pkg/artifact/download/composed/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/composed/downloader.go index ac485647228a..9209c8e84c1a 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/composed/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/composed/downloader.go @@ -32,11 +32,11 @@ func NewDownloader(downloaders ...download.Downloader) *Downloader { // Download fetches the package from configured source. // Returns absolute path to downloaded package and an error. -func (e *Downloader) Download(ctx context.Context, repoName, programName, version string) (string, error) { +func (e *Downloader) Download(ctx context.Context, programName, artifactName, version string) (string, error) { var err error for _, d := range e.dd { - s, e := d.Download(ctx, repoName, programName, version) + s, e := d.Download(ctx, programName, artifactName, version) if e == nil { return s, nil } diff --git a/x-pack/elastic-agent/pkg/artifact/download/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/downloader.go index 331c738ac182..7bfbd4b70192 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/downloader.go @@ -8,5 +8,5 @@ import "context" // Downloader is an interface allowing download of an artifact type Downloader interface { - Download(ctx context.Context, repoName, programName, version string) (string, error) + Download(ctx context.Context, programName, artifactName, version string) (string, error) } diff --git a/x-pack/elastic-agent/pkg/artifact/download/fs/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/fs/downloader.go index 995746f7a43e..df289ae03ad9 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/fs/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/fs/downloader.go @@ -39,7 +39,7 @@ func NewDownloader(config *artifact.Config) *Downloader { // Download fetches the package from configured source. // Returns absolute path to downloaded package and an error. -func (e *Downloader) Download(_ context.Context, _, programName, version string) (_ string, err error) { +func (e *Downloader) Download(_ context.Context, programName, artifactName, version string) (_ string, err error) { downloadedFiles := make([]string, 0, 2) defer func() { if err != nil { @@ -50,18 +50,18 @@ func (e *Downloader) Download(_ context.Context, _, programName, version string) }() // download from source to dest - path, err := e.download(e.config.OS(), programName, version) + path, err := e.download(e.config.OS(), programName, artifactName, version) downloadedFiles = append(downloadedFiles, path) if err != nil { return "", err } - hashPath, err := e.downloadHash(e.config.OS(), programName, version) + hashPath, err := e.downloadHash(e.config.OS(), programName, artifactName, version) downloadedFiles = append(downloadedFiles, hashPath) return path, err } -func (e *Downloader) download(operatingSystem, programName, version string) (string, error) { +func (e *Downloader) download(operatingSystem, programName, _, version string) (string, error) { filename, err := artifact.GetArtifactName(programName, version, operatingSystem, e.config.Arch()) if err != nil { return "", errors.New(err, "generating package name failed") @@ -75,7 +75,7 @@ func (e *Downloader) download(operatingSystem, programName, version string) (str return e.downloadFile(filename, fullPath) } -func (e *Downloader) downloadHash(operatingSystem, programName, version string) (string, error) { +func (e *Downloader) downloadHash(operatingSystem, programName, _, version string) (string, error) { filename, err := artifact.GetArtifactName(programName, version, operatingSystem, e.config.Arch()) if err != nil { return "", errors.New(err, "generating package name failed") diff --git a/x-pack/elastic-agent/pkg/artifact/download/http/downloader.go b/x-pack/elastic-agent/pkg/artifact/download/http/downloader.go index 622f0b2509da..358b793fccf4 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/http/downloader.go +++ b/x-pack/elastic-agent/pkg/artifact/download/http/downloader.go @@ -51,7 +51,7 @@ func NewDownloaderWithClient(config *artifact.Config, client http.Client) *Downl // Download fetches the package from configured source. // Returns absolute path to downloaded package and an error. -func (e *Downloader) Download(ctx context.Context, repoName, programName, version string) (_ string, err error) { +func (e *Downloader) Download(ctx context.Context, programName, artifactName, version string) (_ string, err error) { downloadedFiles := make([]string, 0, 2) defer func() { if err != nil { @@ -62,18 +62,18 @@ func (e *Downloader) Download(ctx context.Context, repoName, programName, versio }() // download from source to dest - path, err := e.download(ctx, e.config.OS(), repoName, programName, version) + path, err := e.download(ctx, e.config.OS(), programName, artifactName, version) downloadedFiles = append(downloadedFiles, path) if err != nil { return "", err } - hashPath, err := e.downloadHash(ctx, e.config.OS(), repoName, programName, version) + hashPath, err := e.downloadHash(ctx, e.config.OS(), programName, artifactName, version) downloadedFiles = append(downloadedFiles, hashPath) return path, err } -func (e *Downloader) composeURI(repoName, programName, packageName string) (string, error) { +func (e *Downloader) composeURI(artifactName, packageName string) (string, error) { upstream := e.config.SourceURI if !strings.HasPrefix(upstream, "http") && !strings.HasPrefix(upstream, "file") && !strings.HasPrefix(upstream, "/") { // always default to https @@ -86,11 +86,11 @@ func (e *Downloader) composeURI(repoName, programName, packageName string) (stri return "", errors.New(err, "invalid upstream URI", errors.TypeConfig) } - uri.Path = path.Join(uri.Path, repoName, programName, packageName) + uri.Path = path.Join(uri.Path, artifactName, packageName) return uri.String(), nil } -func (e *Downloader) download(ctx context.Context, operatingSystem, repoName, programName, version string) (string, error) { +func (e *Downloader) download(ctx context.Context, operatingSystem, programName, artifactName, version string) (string, error) { filename, err := artifact.GetArtifactName(programName, version, operatingSystem, e.config.Arch()) if err != nil { return "", errors.New(err, "generating package name failed") @@ -101,10 +101,10 @@ func (e *Downloader) download(ctx context.Context, operatingSystem, repoName, pr return "", errors.New(err, "generating package path failed") } - return e.downloadFile(ctx, repoName, programName, filename, fullPath) + return e.downloadFile(ctx, artifactName, filename, fullPath) } -func (e *Downloader) downloadHash(ctx context.Context, operatingSystem, repoName, programName, version string) (string, error) { +func (e *Downloader) downloadHash(ctx context.Context, operatingSystem, programName, artifactName, version string) (string, error) { filename, err := artifact.GetArtifactName(programName, version, operatingSystem, e.config.Arch()) if err != nil { return "", errors.New(err, "generating package name failed") @@ -118,11 +118,11 @@ func (e *Downloader) downloadHash(ctx context.Context, operatingSystem, repoName filename = filename + ".sha512" fullPath = fullPath + ".sha512" - return e.downloadFile(ctx, repoName, programName, filename, fullPath) + return e.downloadFile(ctx, artifactName, filename, fullPath) } -func (e *Downloader) downloadFile(ctx context.Context, repoName, programName, filename, fullPath string) (string, error) { - sourceURI, err := e.composeURI(repoName, programName, filename) +func (e *Downloader) downloadFile(ctx context.Context, artifactName, filename, fullPath string) (string, error) { + sourceURI, err := e.composeURI(artifactName, filename) if err != nil { return "", err } diff --git a/x-pack/elastic-agent/pkg/core/app/descriptor.go b/x-pack/elastic-agent/pkg/core/app/descriptor.go index f0ee517f451d..330b0da11e7c 100644 --- a/x-pack/elastic-agent/pkg/core/app/descriptor.go +++ b/x-pack/elastic-agent/pkg/core/app/descriptor.go @@ -16,7 +16,7 @@ import ( // Descriptor defines a program which needs to be run. // Is passed around operator operations. type Descriptor struct { - repoName string + artifactName string executionCtx ExecutionContext directory string spec ProcessSpec @@ -28,7 +28,7 @@ func NewDescriptor(pSpec program.Spec, version string, config *artifact.Config, dir := directory(binaryName, version, config) return &Descriptor{ - repoName: pSpec.Repo, + artifactName: pSpec.Artifact, directory: dir, executionCtx: NewExecutionContext(pSpec.ServicePort, binaryName, version, tags), spec: spec(dir, binaryName), @@ -41,9 +41,9 @@ func (p *Descriptor) ServicePort() int { return p.executionCtx.ServicePort } -// RepoName is the name of the repository the binary is built from. E.g beats. -func (p *Descriptor) RepoName() string { - return p.repoName +// ArtifactName is the name of the artifact to download from the artifact store. E.g beats/filebeat. +func (p *Descriptor) ArtifactName() string { + return p.artifactName } // BinaryName is the name of the binary. E.g filebeat. diff --git a/x-pack/elastic-agent/pkg/release/version.go b/x-pack/elastic-agent/pkg/release/version.go index 7c139d943a93..147c6f78741e 100644 --- a/x-pack/elastic-agent/pkg/release/version.go +++ b/x-pack/elastic-agent/pkg/release/version.go @@ -5,7 +5,6 @@ package release import ( - "strconv" "time" libbeatVersion "github.com/elastic/beats/v7/libbeat/version" @@ -31,6 +30,7 @@ func Version() string { // Snapshot returns true if binary was built as snapshot. func Snapshot() bool { - val, err := strconv.ParseBool(snapshot) - return err == nil && val + return true + //val, err := strconv.ParseBool(snapshot) + //return err == nil && val } diff --git a/x-pack/elastic-agent/spec/endpoint.yml b/x-pack/elastic-agent/spec/endpoint.yml index 10f9d86ae85a..18e56cf82ad3 100644 --- a/x-pack/elastic-agent/spec/endpoint.yml +++ b/x-pack/elastic-agent/spec/endpoint.yml @@ -1,6 +1,6 @@ name: Endpoint Security -repo: endpoint-dev cmd: endpoint-security +artifact: endpoint-dev service: 6788 check_install: - exec_file: diff --git a/x-pack/elastic-agent/spec/filebeat.yml b/x-pack/elastic-agent/spec/filebeat.yml index ff567749b8e2..81c82e276aef 100644 --- a/x-pack/elastic-agent/spec/filebeat.yml +++ b/x-pack/elastic-agent/spec/filebeat.yml @@ -1,7 +1,7 @@ name: Filebeat -repo: beats cmd: filebeat args: ["-E", "setup.ilm.enabled=false", "-E", "setup.template.enabled=false", "-E", "management.mode=x-pack-fleet", "-E", "management.enabled=true", "-E", "logging.level=debug"] +artifact: beats/filebeat rules: - fix_stream: {} - inject_index: diff --git a/x-pack/elastic-agent/spec/metricbeat.yml b/x-pack/elastic-agent/spec/metricbeat.yml index 1b62452c0bbe..fcc8428517a8 100644 --- a/x-pack/elastic-agent/spec/metricbeat.yml +++ b/x-pack/elastic-agent/spec/metricbeat.yml @@ -1,7 +1,7 @@ name: Metricbeat -repo: beats cmd: metricbeat args: ["-E", "setup.ilm.enabled=false", "-E", "setup.template.enabled=false", "-E", "management.mode=x-pack-fleet", "-E", "management.enabled=true", "-E", "logging.level=debug"] +artifact: beats/metricbeat post_install: - move_file: path: "modules.d/system.yml" From cc13299a76f8f87ce325f93446b0711d7987ab1d Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 29 Jun 2020 17:16:30 -0400 Subject: [PATCH 3/7] Fix tar installer. --- .../elastic-agent/pkg/artifact/install/tar/tar_installer.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/elastic-agent/pkg/artifact/install/tar/tar_installer.go b/x-pack/elastic-agent/pkg/artifact/install/tar/tar_installer.go index f73ace5765a5..5c7f0f593a3c 100644 --- a/x-pack/elastic-agent/pkg/artifact/install/tar/tar_installer.go +++ b/x-pack/elastic-agent/pkg/artifact/install/tar/tar_installer.go @@ -50,8 +50,9 @@ func (i *Installer) Install(_ context.Context, programName, version, installDir os.RemoveAll(installDir) } - return unpack(f, installDir) - + // unpack must occur in directory that holds the installation directory + // or the extraction will be double nested + return unpack(f, filepath.Dir(installDir)) } func unpack(r io.Reader, dir string) error { From d017817bbc5ba369f92db25ac2bd59b945992b08 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 29 Jun 2020 17:26:40 -0400 Subject: [PATCH 4/7] Fix downloading. --- .../elastic-agent/pkg/agent/operation/monitoring.go | 13 +++++++++---- x-pack/elastic-agent/pkg/agent/program/spec.go | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/operation/monitoring.go b/x-pack/elastic-agent/pkg/agent/operation/monitoring.go index 6aad94a2e62a..10947f4d7dfe 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/monitoring.go +++ b/x-pack/elastic-agent/pkg/agent/operation/monitoring.go @@ -5,6 +5,8 @@ package operation import ( + "fmt" + "github.com/hashicorp/go-multierror" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configrequest" @@ -19,6 +21,7 @@ const ( monitoringEnabledSubkey = "enabled" logsProcessName = "filebeat" metricsProcessName = "metricbeat" + artifactPrefix = "beats" ) func (o *Operator) handleStartSidecar(s configrequest.Step) (result error) { @@ -133,8 +136,9 @@ func (o *Operator) generateMonitoringSteps(version string, output interface{}) [ ID: stepID, Version: version, ProgramSpec: program.Spec{ - Name: logsProcessName, - Cmd: logsProcessName, + Name: logsProcessName, + Cmd: logsProcessName, + Artifact: fmt.Sprintf("%s/%s", artifactPrefix, logsProcessName), }, Meta: map[string]interface{}{ configrequest.MetaConfigKey: fbConfig, @@ -154,8 +158,9 @@ func (o *Operator) generateMonitoringSteps(version string, output interface{}) [ ID: stepID, Version: version, ProgramSpec: program.Spec{ - Name: metricsProcessName, - Cmd: metricsProcessName, + Name: metricsProcessName, + Cmd: metricsProcessName, + Artifact: fmt.Sprintf("%s/%s", artifactPrefix, logsProcessName), }, Meta: map[string]interface{}{ configrequest.MetaConfigKey: mbConfig, diff --git a/x-pack/elastic-agent/pkg/agent/program/spec.go b/x-pack/elastic-agent/pkg/agent/program/spec.go index 2d859c1950b4..5646a3652e9d 100644 --- a/x-pack/elastic-agent/pkg/agent/program/spec.go +++ b/x-pack/elastic-agent/pkg/agent/program/spec.go @@ -31,7 +31,7 @@ type Spec struct { ServicePort int `yaml:"service,omitempty"` Cmd string `yaml:"cmd"` Args []string `yaml:"args"` - Artifact string `yaml:"artifact"` + Artifact string `yaml:"artifact"` Rules *transpiler.RuleList `yaml:"rules"` CheckInstallSteps *transpiler.StepList `yaml:"check_install"` PostInstallSteps *transpiler.StepList `yaml:"post_install"` From 184415d865b919453b67306872e510ae591ca127 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 29 Jun 2020 18:40:04 -0400 Subject: [PATCH 5/7] Fix tests. --- x-pack/elastic-agent/pkg/agent/program/spec_test.go | 10 +++++----- .../pkg/artifact/download/fs/verifier_test.go | 13 ++++++------- .../pkg/artifact/download/http/elastic_test.go | 6 +++--- x-pack/elastic-agent/pkg/release/version.go | 6 +++--- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/program/spec_test.go b/x-pack/elastic-agent/pkg/agent/program/spec_test.go index 6a8c38dfb2f5..df1fb082f7af 100644 --- a/x-pack/elastic-agent/pkg/agent/program/spec_test.go +++ b/x-pack/elastic-agent/pkg/agent/program/spec_test.go @@ -21,10 +21,10 @@ import ( func TestSerialization(t *testing.T) { spec := Spec{ - Name: "hello", - Repo: "reponame", - Cmd: "hellocmd", - Args: []string{"-c", "first"}, + Name: "hello", + Cmd: "hellocmd", + Args: []string{"-c", "first"}, + Artifact: "nested/hellocmd", Rules: transpiler.NewRuleList( transpiler.Copy("inputs", "filebeat"), transpiler.Filter("filebeat", "output", "keystore"), @@ -57,11 +57,11 @@ func TestSerialization(t *testing.T) { When: "1 == 1", } yml := `name: hello -repo: reponame cmd: hellocmd args: - -c - first +artifact: nested/hellocmd rules: - copy: from: inputs diff --git a/x-pack/elastic-agent/pkg/artifact/download/fs/verifier_test.go b/x-pack/elastic-agent/pkg/artifact/download/fs/verifier_test.go index 36eb3c518dc5..4787656d8b0a 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/fs/verifier_test.go +++ b/x-pack/elastic-agent/pkg/artifact/download/fs/verifier_test.go @@ -20,10 +20,9 @@ import ( ) const ( - repoName = "beats" - beatName = "filebeat" - version = "7.5.1" - sourcePattern = "/downloads/beats/filebeat/" + beatName = "filebeat" + artifactName = "beats/filebeat" + version = "7.5.1" ) type testCase struct { @@ -37,8 +36,8 @@ func TestFetchVerify(t *testing.T) { installPath := filepath.Join("testdata", "install") targetPath := filepath.Join("testdata", "download") ctx := context.Background() - repoName := "beats" programName := "beat" + artifactName := "beats/beat" version := "8.0.0" targetFilePath := filepath.Join(targetPath, "beat-8.0.0-darwin-x86_64.tar.gz") @@ -79,7 +78,7 @@ func TestFetchVerify(t *testing.T) { // second one should pass // download not skipped: package missing // verify passes because hash is not correct - _, err = downloader.Download(ctx, repoName, programName, version) + _, err = downloader.Download(ctx, programName, artifactName, version) assert.NoError(t, err) // file downloaded ok @@ -148,7 +147,7 @@ func TestVerify(t *testing.T) { } testClient := NewDownloader(config) - artifact, err := testClient.Download(context.Background(), repoName, beatName, version) + artifact, err := testClient.Download(context.Background(), beatName, artifactName, version) if err != nil { t.Fatal(err) } diff --git a/x-pack/elastic-agent/pkg/artifact/download/http/elastic_test.go b/x-pack/elastic-agent/pkg/artifact/download/http/elastic_test.go index 2614fbbd407d..a1e1ced0b662 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/http/elastic_test.go +++ b/x-pack/elastic-agent/pkg/artifact/download/http/elastic_test.go @@ -22,8 +22,8 @@ import ( ) const ( - repoName = "beats" beatName = "filebeat" + artifactName = "beats/filebeat" version = "7.5.1" sourcePattern = "/downloads/beats/filebeat/" source = "http://artifacts.elastic.co/downloads/" @@ -57,7 +57,7 @@ func TestDownload(t *testing.T) { config.Architecture = testCase.arch testClient := NewDownloaderWithClient(config, elasticClient) - artifactPath, err := testClient.Download(context.Background(), repoName, beatName, version) + artifactPath, err := testClient.Download(context.Background(), beatName, artifactName, version) if err != nil { t.Fatal(err) } @@ -95,7 +95,7 @@ func TestVerify(t *testing.T) { config.Architecture = testCase.arch testClient := NewDownloaderWithClient(config, elasticClient) - artifact, err := testClient.Download(context.Background(), repoName, beatName, version) + artifact, err := testClient.Download(context.Background(), beatName, artifactName, version) if err != nil { t.Fatal(err) } diff --git a/x-pack/elastic-agent/pkg/release/version.go b/x-pack/elastic-agent/pkg/release/version.go index 147c6f78741e..7c139d943a93 100644 --- a/x-pack/elastic-agent/pkg/release/version.go +++ b/x-pack/elastic-agent/pkg/release/version.go @@ -5,6 +5,7 @@ package release import ( + "strconv" "time" libbeatVersion "github.com/elastic/beats/v7/libbeat/version" @@ -30,7 +31,6 @@ func Version() string { // Snapshot returns true if binary was built as snapshot. func Snapshot() bool { - return true - //val, err := strconv.ParseBool(snapshot) - //return err == nil && val + val, err := strconv.ParseBool(snapshot) + return err == nil && val } From d1464db35f19bc01103c4267ce81ac4c028ef74e Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 29 Jun 2020 18:44:04 -0400 Subject: [PATCH 6/7] Add changelog. --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index c66798a01da4..848ffdc3e777 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -73,3 +73,4 @@ - Agent now runs the GRPC server and spawned application connect by to Agent {pull}18973[18973] - Rename input.type logs to logfile {pull}19360[19360] - Agent now installs/uninstalls Elastic Endpoint {pull}19248[19248] +- Agent now downloads Elastic Endpoint {pull}19503[19503] From 3148d284639ffbeb3199965a256b847f9d5b3e5e Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 29 Jun 2020 22:40:20 -0400 Subject: [PATCH 7/7] Revert some un-needed changes. --- x-pack/elastic-agent/pkg/agent/operation/common_test.go | 2 +- x-pack/elastic-agent/pkg/artifact/artifact.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/operation/common_test.go b/x-pack/elastic-agent/pkg/agent/operation/common_test.go index 06268615099a..1f3232844056 100644 --- a/x-pack/elastic-agent/pkg/agent/operation/common_test.go +++ b/x-pack/elastic-agent/pkg/agent/operation/common_test.go @@ -144,7 +144,7 @@ func waitFor(t *testing.T, check func() error) { type DummyDownloader struct{} -func (*DummyDownloader) Download(_ context.Context, r, p, v string) (string, error) { +func (*DummyDownloader) Download(_ context.Context, p, a, v string) (string, error) { return "", nil } diff --git a/x-pack/elastic-agent/pkg/artifact/artifact.go b/x-pack/elastic-agent/pkg/artifact/artifact.go index b4961b56da72..b1dfb4d8a5e2 100644 --- a/x-pack/elastic-agent/pkg/artifact/artifact.go +++ b/x-pack/elastic-agent/pkg/artifact/artifact.go @@ -21,14 +21,14 @@ var packageArchMap = map[string]string{ } // GetArtifactName constructs a path to a downloaded artifact -func GetArtifactName(artifactPath, version, operatingSystem, arch string) (string, error) { +func GetArtifactName(programName, version, operatingSystem, arch string) (string, error) { key := fmt.Sprintf("%s-binary-%s", operatingSystem, arch) suffix, found := packageArchMap[key] if !found { return "", errors.New(fmt.Sprintf("'%s' is not a valid combination for a package", key), errors.TypeConfig) } - return fmt.Sprintf("%s-%s-%s", artifactPath, version, suffix), nil + return fmt.Sprintf("%s-%s-%s", programName, version, suffix), nil } // GetArtifactPath returns a full path of artifact for a program in specific version