From 4a5127686d5e9e4f50e044d4fe14c0af62c2b470 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 29 Dec 2023 12:19:46 +0100 Subject: [PATCH 01/20] otel readme --- magefile.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/magefile.go b/magefile.go index 6853d82ea3b..a50d5c71f59 100644 --- a/magefile.go +++ b/magefile.go @@ -12,6 +12,7 @@ import ( "encoding/json" "errors" "fmt" + "html/template" "log" "os" "os/exec" @@ -2243,3 +2244,62 @@ func hasCleanOnExit() bool { b, _ := strconv.ParseBool(clean) return b } + +type dependency struct { + Name string + Version string +} + +func OtelReadme() error { + fmt.Println("Generating otel/README") + + const ( + readmeTmpl = "" + readmeOut = "" + ) + + // read README template + tmpls, err := template.ParseFiles(readmeTmpl) + if err != nil { + return errors.New(err, "failed to parse README template") + } + + if len(tmpls) != 1 { + fmt.Println("No OTel README template") + return nil + } + + tmpl := tmpls[0] + + receivers, exporters, processors, err := getDependencies() + if err != nil { + return errors.New(err, "Failed to get OTel dependencies") + } + + data := struct { + Receivers []dependency + Exporters []dependency + Processors []dependency + }{ + Receivers: receivers, + Exporters: exporters, + Processors: processors, + } + + // resolve template + out, err := os.OpenFile(readmeOut, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) + if err != nil { + return fmt.Errorf("failed to open file %s: %w", outfn, err) + } + defer out.Close() + + return tmpl.Execute(out, data) +} + +func getDependencies() (receivers, exporters, processors []dependency, err error) { + // read go.mod + // parse otel imports + + // group exporters, receivers and processors + return +} From bdd9353eaa9ac24030806b1d7ce9abf16ecc00e8 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 09:22:22 +0100 Subject: [PATCH 02/20] Generate Otel Readme --- internal/pkg/otel/README.md | 50 ++++++++++++++++ internal/pkg/otel/templates/README.md.tmpl | 44 ++++++++++++++ magefile.go | 68 ++++++++++++++++------ 3 files changed, 144 insertions(+), 18 deletions(-) create mode 100644 internal/pkg/otel/README.md create mode 100644 internal/pkg/otel/templates/README.md.tmpl diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md new file mode 100644 index 00000000000..7d12f057517 --- /dev/null +++ b/internal/pkg/otel/README.md @@ -0,0 +1,50 @@ +# Elastic Distribution for OpenTelemetry Collector + +This is an Elastic supported distribution of the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector). + +## Running Elastic OpenTelemetry Distribution + +To run Elastic OpenTelemetry Distribution you can use Elastic-Agent binary downloaded for your OS and architecture. +Using command + +```bash +./elastic-agent -c otel.yml run +``` + +will run Elastic-Agent as a Distro. `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. +Both `yaml` and `yml` suffixes are supported. + +> In case this condition is not met, Elastic Agent will run in its default mode and will not behave as OpenTelemetry Collector. + +Note that `validate` subcommand and `feature gates` are not supported yet. + +## Components + +This sections provides a summary of components included in Elastic OpenTelemetry Collector distribution. + +### Receivers + +| Dependency | Version | +|---|---| +| github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver | v0.89.0| +| go.opentelemetry.io/collector/receiver/otlpreceiver | v0.89.0| + + +### Exporters + +| Dependency | Version | +|---|---| +| github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter | v0.89.0| +| go.opentelemetry.io/collector/exporter/debugexporter | v0.89.0| +| go.opentelemetry.io/collector/exporter/otlpexporter | v0.89.0| + + +### Processors + +| Dependency | Version | +|---|---| +| github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor | v0.89.0| +| github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourceprocessor | v0.89.0| +| github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor | v0.89.0| +| go.opentelemetry.io/collector/processor/batchprocessor | v0.89.0| +| go.opentelemetry.io/collector/processor/memorylimiterprocessor | v0.89.0| diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl new file mode 100644 index 00000000000..902e6780c7a --- /dev/null +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -0,0 +1,44 @@ +# Elastic Distribution for OpenTelemetry Collector + +This is an Elastic supported distribution of the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector). + +## Running Elastic OpenTelemetry Distribution + +To run Elastic OpenTelemetry Distribution you can use Elastic-Agent binary downloaded for your OS and architecture. +Using command + +```bash +./elastic-agent -c otel.yml run +``` + +will run Elastic-Agent as a Distro. `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. +Both `yaml` and `yml` suffixes are supported. + +> In case this condition is not met, Elastic Agent will run in its default mode and will not behave as OpenTelemetry Collector. + +Note that `validate` subcommand and `feature gates` are not supported yet. + +## Components + +This sections provides a summary of components included in Elastic OpenTelemetry Collector distribution. + +### Receivers + +| Dependency | Version | +|---|---| +{{ range .Receivers }}| {{ .Name }} | {{ .Version -}} | +{{ end }} + +### Exporters + +| Dependency | Version | +|---|---| +{{ range .Exporters }}| {{ .Name }} | {{ .Version -}} | +{{ end }} + +### Processors + +| Dependency | Version | +|---|---| +{{ range .Processors }}| {{ .Name }} | {{ .Version -}} | +{{ end }} \ No newline at end of file diff --git a/magefile.go b/magefile.go index a50d5c71f59..6f0b1b0f678 100644 --- a/magefile.go +++ b/magefile.go @@ -551,7 +551,7 @@ func commitID() string { // Update is an alias for executing control protocol, configs, and specs. func Update() { - mg.SerialDeps(Config, BuildPGP, BuildFleetCfg) + mg.SerialDeps(Config, BuildPGP, BuildFleetCfg, OtelReadme) } // CrossBuild cross-builds the beat for all target platforms. @@ -2251,29 +2251,20 @@ type dependency struct { } func OtelReadme() error { - fmt.Println("Generating otel/README") + fmt.Println(">> Building internal/pkg/otel/README.md") - const ( - readmeTmpl = "" - readmeOut = "" - ) + readmeTmpl := filepath.Join("internal", "pkg", "otel", "templates", "README.md.tmpl") + readmeOut := filepath.Join("internal", "pkg", "otel", "README.md") // read README template - tmpls, err := template.ParseFiles(readmeTmpl) + tmpl, err := template.ParseFiles(readmeTmpl) if err != nil { - return errors.New(err, "failed to parse README template") + return fmt.Errorf("failed to parse README template: %w", err) } - if len(tmpls) != 1 { - fmt.Println("No OTel README template") - return nil - } - - tmpl := tmpls[0] - receivers, exporters, processors, err := getDependencies() if err != nil { - return errors.New(err, "Failed to get OTel dependencies") + return fmt.Errorf("Failed to get OTel dependencies: %w", err) } data := struct { @@ -2289,7 +2280,7 @@ func OtelReadme() error { // resolve template out, err := os.OpenFile(readmeOut, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) if err != nil { - return fmt.Errorf("failed to open file %s: %w", outfn, err) + return fmt.Errorf("failed to open file %s: %w", readmeOut, err) } defer out.Close() @@ -2298,7 +2289,48 @@ func OtelReadme() error { func getDependencies() (receivers, exporters, processors []dependency, err error) { // read go.mod - // parse otel imports + readFile, err := os.Open("go.mod") + if err != nil { + return nil, nil, nil, err + } + scanner := bufio.NewScanner(readFile) + + scanner.Split(bufio.ScanLines) + // process imports + for scanner.Scan() { + l := strings.TrimSpace(scanner.Text()) + // is otel + if !strings.Contains(l, "go.opentelemetry.io/") && + !strings.Contains(l, "github.com/open-telemetry/") { + continue + } + + parseLine := func(line string) (dependency, error) { + chunks := strings.SplitN(line, " ", 2) + if len(chunks) != 2 { + return dependency{}, fmt.Errorf("incorrect format for line %q", line) + } + return dependency{ + Name: chunks[0], + Version: chunks[1], + }, nil + } + + d, err := parseLine(l) + if err != nil { + return nil, nil, nil, err + } + + if strings.Contains(l, "/receiver/") { + receivers = append(receivers, d) + } else if strings.Contains(l, "/processor/") { + processors = append(processors, d) + } else if strings.Contains(l, "/exporter/") { + exporters = append(exporters, d) + } + } + + readFile.Close() // group exporters, receivers and processors return From 5ddb82f850ff74df7f402f43344e6e08aea07f56 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 09:23:17 +0100 Subject: [PATCH 03/20] readme template update --- internal/pkg/otel/templates/README.md.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl index 902e6780c7a..25b73f6944a 100644 --- a/internal/pkg/otel/templates/README.md.tmpl +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -5,13 +5,13 @@ This is an Elastic supported distribution of the [OpenTelemetry Collector](https ## Running Elastic OpenTelemetry Distribution To run Elastic OpenTelemetry Distribution you can use Elastic-Agent binary downloaded for your OS and architecture. -Using command +Running command ```bash ./elastic-agent -c otel.yml run ``` -will run Elastic-Agent as a Distro. `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. +from unpacked Elastic Agent package will run Elastic-Agent as a Distro. `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. Both `yaml` and `yml` suffixes are supported. > In case this condition is not met, Elastic Agent will run in its default mode and will not behave as OpenTelemetry Collector. From 7f4c13e38db5a2e7a0c1c27841ba44921ad3ef99 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 09:23:50 +0100 Subject: [PATCH 04/20] updated generated readme --- internal/pkg/otel/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md index 7d12f057517..89d28078193 100644 --- a/internal/pkg/otel/README.md +++ b/internal/pkg/otel/README.md @@ -5,13 +5,13 @@ This is an Elastic supported distribution of the [OpenTelemetry Collector](https ## Running Elastic OpenTelemetry Distribution To run Elastic OpenTelemetry Distribution you can use Elastic-Agent binary downloaded for your OS and architecture. -Using command +Running command ```bash ./elastic-agent -c otel.yml run ``` -will run Elastic-Agent as a Distro. `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. +from unpacked Elastic Agent package will run Elastic-Agent as a Distro. `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. Both `yaml` and `yml` suffixes are supported. > In case this condition is not met, Elastic Agent will run in its default mode and will not behave as OpenTelemetry Collector. From 0467a9db0f2ce9a0081a0cb3dedffe97a4c3864f Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 09:33:32 +0100 Subject: [PATCH 05/20] clean names --- internal/pkg/otel/README.md | 20 ++++++++++---------- magefile.go | 12 ++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md index 89d28078193..1587dc4a552 100644 --- a/internal/pkg/otel/README.md +++ b/internal/pkg/otel/README.md @@ -26,25 +26,25 @@ This sections provides a summary of components included in Elastic OpenTelemetry | Dependency | Version | |---|---| -| github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver | v0.89.0| -| go.opentelemetry.io/collector/receiver/otlpreceiver | v0.89.0| +| filelogreceiver | v0.89.0| +| otlpreceiver | v0.89.0| ### Exporters | Dependency | Version | |---|---| -| github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter | v0.89.0| -| go.opentelemetry.io/collector/exporter/debugexporter | v0.89.0| -| go.opentelemetry.io/collector/exporter/otlpexporter | v0.89.0| +| fileexporter | v0.89.0| +| debugexporter | v0.89.0| +| otlpexporter | v0.89.0| ### Processors | Dependency | Version | |---|---| -| github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor | v0.89.0| -| github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourceprocessor | v0.89.0| -| github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor | v0.89.0| -| go.opentelemetry.io/collector/processor/batchprocessor | v0.89.0| -| go.opentelemetry.io/collector/processor/memorylimiterprocessor | v0.89.0| +| attributesprocessor | v0.89.0| +| resourceprocessor | v0.89.0| +| transformprocessor | v0.89.0| +| batchprocessor | v0.89.0| +| memorylimiterprocessor | v0.89.0| diff --git a/magefile.go b/magefile.go index 6f0b1b0f678..669177e50fb 100644 --- a/magefile.go +++ b/magefile.go @@ -2305,6 +2305,15 @@ func getDependencies() (receivers, exporters, processors []dependency, err error continue } + cleanFn := func(dep, sep string) string { + chunks := strings.SplitN(dep, sep, 2) + if len(chunks) == 2 { + return chunks[1] + } + + return dep + } + parseLine := func(line string) (dependency, error) { chunks := strings.SplitN(line, " ", 2) if len(chunks) != 2 { @@ -2322,10 +2331,13 @@ func getDependencies() (receivers, exporters, processors []dependency, err error } if strings.Contains(l, "/receiver/") { + d.Name = cleanFn(d.Name, "/receiver/") receivers = append(receivers, d) } else if strings.Contains(l, "/processor/") { + d.Name = cleanFn(d.Name, "/processor/") processors = append(processors, d) } else if strings.Contains(l, "/exporter/") { + d.Name = cleanFn(d.Name, "/exporter/") exporters = append(exporters, d) } } From b05200f3149d14456d9efc7a5c6b43a50cfad623 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 09:36:40 +0100 Subject: [PATCH 06/20] clean names --- magefile.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/magefile.go b/magefile.go index 669177e50fb..ef17be9ad0e 100644 --- a/magefile.go +++ b/magefile.go @@ -2250,6 +2250,20 @@ type dependency struct { Version string } +func (d dependency) Clean(sep string) dependency { + cleanFn := func(dep, sep string) string { + chunks := strings.SplitN(dep, sep, 2) + if len(chunks) == 2 { + return chunks[1] + } + + return dep + } + + d.Name = cleanFn(d.Name, sep) + return d +} + func OtelReadme() error { fmt.Println(">> Building internal/pkg/otel/README.md") @@ -2305,15 +2319,6 @@ func getDependencies() (receivers, exporters, processors []dependency, err error continue } - cleanFn := func(dep, sep string) string { - chunks := strings.SplitN(dep, sep, 2) - if len(chunks) == 2 { - return chunks[1] - } - - return dep - } - parseLine := func(line string) (dependency, error) { chunks := strings.SplitN(line, " ", 2) if len(chunks) != 2 { @@ -2331,14 +2336,11 @@ func getDependencies() (receivers, exporters, processors []dependency, err error } if strings.Contains(l, "/receiver/") { - d.Name = cleanFn(d.Name, "/receiver/") - receivers = append(receivers, d) + receivers = append(receivers, d.Clean("/receiver/")) } else if strings.Contains(l, "/processor/") { - d.Name = cleanFn(d.Name, "/processor/") - processors = append(processors, d) + processors = append(processors, d.Clean("/processor/")) } else if strings.Contains(l, "/exporter/") { - d.Name = cleanFn(d.Name, "/exporter/") - exporters = append(exporters, d) + exporters = append(exporters, d.Clean("/exporter/")) } } From be1943c5ce867b14a6e115680d64800812a2cf46 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 09:41:59 +0100 Subject: [PATCH 07/20] template update --- internal/pkg/otel/README.md | 6 +++--- internal/pkg/otel/templates/README.md.tmpl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md index 1587dc4a552..9987fbe54b9 100644 --- a/internal/pkg/otel/README.md +++ b/internal/pkg/otel/README.md @@ -24,7 +24,7 @@ This sections provides a summary of components included in Elastic OpenTelemetry ### Receivers -| Dependency | Version | +| Component | Version | |---|---| | filelogreceiver | v0.89.0| | otlpreceiver | v0.89.0| @@ -32,7 +32,7 @@ This sections provides a summary of components included in Elastic OpenTelemetry ### Exporters -| Dependency | Version | +| Component | Version | |---|---| | fileexporter | v0.89.0| | debugexporter | v0.89.0| @@ -41,7 +41,7 @@ This sections provides a summary of components included in Elastic OpenTelemetry ### Processors -| Dependency | Version | +| Component | Version | |---|---| | attributesprocessor | v0.89.0| | resourceprocessor | v0.89.0| diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl index 25b73f6944a..8a24e7cbf45 100644 --- a/internal/pkg/otel/templates/README.md.tmpl +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -24,21 +24,21 @@ This sections provides a summary of components included in Elastic OpenTelemetry ### Receivers -| Dependency | Version | +| Component | Version | |---|---| {{ range .Receivers }}| {{ .Name }} | {{ .Version -}} | {{ end }} ### Exporters -| Dependency | Version | +| Component | Version | |---|---| {{ range .Exporters }}| {{ .Name }} | {{ .Version -}} | {{ end }} ### Processors -| Dependency | Version | +| Component | Version | |---|---| {{ range .Processors }}| {{ .Name }} | {{ .Version -}} | {{ end }} \ No newline at end of file From 2dadc65641439258f7eef726e988fd20cc51f670 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 10:03:27 +0100 Subject: [PATCH 08/20] template update --- magefile.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/magefile.go b/magefile.go index ef17be9ad0e..d688d235048 100644 --- a/magefile.go +++ b/magefile.go @@ -2260,8 +2260,10 @@ func (d dependency) Clean(sep string) dependency { return dep } - d.Name = cleanFn(d.Name, sep) - return d + return dependency{ + Name: cleanFn(d.Name, sep), + Version: d.Version, + } } func OtelReadme() error { From b3673a14763d58e1212c527fb4c44937554d5fe0 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 13:30:18 +0100 Subject: [PATCH 09/20] Update internal/pkg/otel/templates/README.md.tmpl Co-authored-by: Shaunak Kashyap --- internal/pkg/otel/templates/README.md.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl index 8a24e7cbf45..64f4b0efe5a 100644 --- a/internal/pkg/otel/templates/README.md.tmpl +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -2,7 +2,7 @@ This is an Elastic supported distribution of the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector). -## Running Elastic OpenTelemetry Distribution +## Running the Elastic Distribution for OpenTelemetry Collector To run Elastic OpenTelemetry Distribution you can use Elastic-Agent binary downloaded for your OS and architecture. Running command From fe57a05a3734b671c082dc33716a7aab0002dd0e Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 13:30:32 +0100 Subject: [PATCH 10/20] Update internal/pkg/otel/templates/README.md.tmpl Co-authored-by: Shaunak Kashyap --- internal/pkg/otel/templates/README.md.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl index 64f4b0efe5a..d208dd5a54c 100644 --- a/internal/pkg/otel/templates/README.md.tmpl +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -11,7 +11,7 @@ Running command ./elastic-agent -c otel.yml run ``` -from unpacked Elastic Agent package will run Elastic-Agent as a Distro. `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. +from unpacked Elastic Agent package will run Elastic-Agent as an OpenTelemetry Collector. The `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. Both `yaml` and `yml` suffixes are supported. > In case this condition is not met, Elastic Agent will run in its default mode and will not behave as OpenTelemetry Collector. From 43d494b7715b6602c64595a77b850a53f5d61af1 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 13:37:44 +0100 Subject: [PATCH 11/20] extensions --- magefile.go | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/magefile.go b/magefile.go index d688d235048..ddade47b96c 100644 --- a/magefile.go +++ b/magefile.go @@ -121,6 +121,9 @@ type Cloud mg.Namespace // Integration namespace contains tasks related to operating and running integration tests. type Integration mg.Namespace +// Otel namespace contains Open Telemetry related tasks. +type Otel mg.Namespace + func CheckNoChanges() error { fmt.Println(">> fmt - go run") err := sh.RunV("go", "mod", "tidy", "-v") @@ -551,7 +554,7 @@ func commitID() string { // Update is an alias for executing control protocol, configs, and specs. func Update() { - mg.SerialDeps(Config, BuildPGP, BuildFleetCfg, OtelReadme) + mg.SerialDeps(Config, BuildPGP, BuildFleetCfg, Otel.Readme) } // CrossBuild cross-builds the beat for all target platforms. @@ -2250,6 +2253,13 @@ type dependency struct { Version string } +type dependencies struct { + Receivers []dependency + Exporters []dependency + Processors []dependency + Extensions []dependency +} + func (d dependency) Clean(sep string) dependency { cleanFn := func(dep, sep string) string { chunks := strings.SplitN(dep, sep, 2) @@ -2266,7 +2276,7 @@ func (d dependency) Clean(sep string) dependency { } } -func OtelReadme() error { +func (Otel) Readme() error { fmt.Println(">> Building internal/pkg/otel/README.md") readmeTmpl := filepath.Join("internal", "pkg", "otel", "templates", "README.md.tmpl") @@ -2278,21 +2288,11 @@ func OtelReadme() error { return fmt.Errorf("failed to parse README template: %w", err) } - receivers, exporters, processors, err := getDependencies() + data, err := getOtelDependencies() if err != nil { return fmt.Errorf("Failed to get OTel dependencies: %w", err) } - data := struct { - Receivers []dependency - Exporters []dependency - Processors []dependency - }{ - Receivers: receivers, - Exporters: exporters, - Processors: processors, - } - // resolve template out, err := os.OpenFile(readmeOut, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) if err != nil { @@ -2303,15 +2303,18 @@ func OtelReadme() error { return tmpl.Execute(out, data) } -func getDependencies() (receivers, exporters, processors []dependency, err error) { +func getOtelDependencies() (*dependencies, error) { // read go.mod readFile, err := os.Open("go.mod") if err != nil { - return nil, nil, nil, err + return nil, err } + defer readFile.Close() + scanner := bufio.NewScanner(readFile) scanner.Split(bufio.ScanLines) + var receivers, extensions, exporters, processors []dependency // process imports for scanner.Scan() { l := strings.TrimSpace(scanner.Text()) @@ -2334,7 +2337,7 @@ func getDependencies() (receivers, exporters, processors []dependency, err error d, err := parseLine(l) if err != nil { - return nil, nil, nil, err + return nil, err } if strings.Contains(l, "/receiver/") { @@ -2343,11 +2346,15 @@ func getDependencies() (receivers, exporters, processors []dependency, err error processors = append(processors, d.Clean("/processor/")) } else if strings.Contains(l, "/exporter/") { exporters = append(exporters, d.Clean("/exporter/")) + } else if strings.Contains(l, "/extensions/") { + extensions = append(exporters, d.Clean("/extensions/")) } } - readFile.Close() - - // group exporters, receivers and processors - return + return &dependencies{ + Receivers: receivers, + Exporters: exporters, + Processors: processors, + Extensions: extensions, + }, nil } From b910c52648932df73f00f8532a813dbd7764aeb5 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 13:38:13 +0100 Subject: [PATCH 12/20] updated readme --- internal/pkg/otel/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md index 9987fbe54b9..2e4831c34c8 100644 --- a/internal/pkg/otel/README.md +++ b/internal/pkg/otel/README.md @@ -2,7 +2,7 @@ This is an Elastic supported distribution of the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector). -## Running Elastic OpenTelemetry Distribution +## Running the Elastic Distribution for OpenTelemetry Collector To run Elastic OpenTelemetry Distribution you can use Elastic-Agent binary downloaded for your OS and architecture. Running command @@ -11,7 +11,7 @@ Running command ./elastic-agent -c otel.yml run ``` -from unpacked Elastic Agent package will run Elastic-Agent as a Distro. `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. +from unpacked Elastic Agent package will run Elastic-Agent as an OpenTelemetry Collector. The `-c` flag needs to point to [OpenTelemetry Collector Configuration file](https://opentelemetry.io/docs/collector/configuration/) named `otel`, `otlp` or `otelcol`. Both `yaml` and `yml` suffixes are supported. > In case this condition is not met, Elastic Agent will run in its default mode and will not behave as OpenTelemetry Collector. From 0b1c017b8a83ae7cf0a29000740dc8ca66f06f83 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 13:39:44 +0100 Subject: [PATCH 13/20] updated template --- internal/pkg/otel/README.md | 8 ++++++++ internal/pkg/otel/templates/README.md.tmpl | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md index 2e4831c34c8..bb66f9aaf4b 100644 --- a/internal/pkg/otel/README.md +++ b/internal/pkg/otel/README.md @@ -22,6 +22,7 @@ Note that `validate` subcommand and `feature gates` are not supported yet. This sections provides a summary of components included in Elastic OpenTelemetry Collector distribution. + ### Receivers | Component | Version | @@ -30,6 +31,8 @@ This sections provides a summary of components included in Elastic OpenTelemetry | otlpreceiver | v0.89.0| + + ### Exporters | Component | Version | @@ -39,6 +42,8 @@ This sections provides a summary of components included in Elastic OpenTelemetry | otlpexporter | v0.89.0| + + ### Processors | Component | Version | @@ -48,3 +53,6 @@ This sections provides a summary of components included in Elastic OpenTelemetry | transformprocessor | v0.89.0| | batchprocessor | v0.89.0| | memorylimiterprocessor | v0.89.0| + + + diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl index d208dd5a54c..695ebfcdc10 100644 --- a/internal/pkg/otel/templates/README.md.tmpl +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -22,23 +22,38 @@ Note that `validate` subcommand and `feature gates` are not supported yet. This sections provides a summary of components included in Elastic OpenTelemetry Collector distribution. +{{ if .Receivers }} ### Receivers | Component | Version | |---|---| {{ range .Receivers }}| {{ .Name }} | {{ .Version -}} | {{ end }} +{{ end }} +{{ if .Exporters }} ### Exporters | Component | Version | |---|---| {{ range .Exporters }}| {{ .Name }} | {{ .Version -}} | {{ end }} +{{ end }} +{{ if .Processors }} ### Processors | Component | Version | |---|---| {{ range .Processors }}| {{ .Name }} | {{ .Version -}} | +{{ end }} +{{ end }} + +{{ if .Extensions }} +### Extensions + +| Component | Version | +|---|---| +{{ range .Extensions }}| {{ .Name }} | {{ .Version -}} | +{{ end }} {{ end }} \ No newline at end of file From efafba26080b2e1969259dda0a93f254f207dc2e Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 13:40:54 +0100 Subject: [PATCH 14/20] Update internal/pkg/otel/templates/README.md.tmpl Co-authored-by: Shaunak Kashyap --- internal/pkg/otel/templates/README.md.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl index 695ebfcdc10..10dfe508e3c 100644 --- a/internal/pkg/otel/templates/README.md.tmpl +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -20,7 +20,7 @@ Note that `validate` subcommand and `feature gates` are not supported yet. ## Components -This sections provides a summary of components included in Elastic OpenTelemetry Collector distribution. +This section provides a summary of components included in the Elastic Distribution for OpenTelemetry Collector. {{ if .Receivers }} ### Receivers From 725f6a8432858556f3d8388e95a61ce70cb4a359 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 13:41:02 +0100 Subject: [PATCH 15/20] Update internal/pkg/otel/templates/README.md.tmpl Co-authored-by: Shaunak Kashyap --- internal/pkg/otel/templates/README.md.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl index 10dfe508e3c..dcbc99329d2 100644 --- a/internal/pkg/otel/templates/README.md.tmpl +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -16,7 +16,7 @@ Both `yaml` and `yml` suffixes are supported. > In case this condition is not met, Elastic Agent will run in its default mode and will not behave as OpenTelemetry Collector. -Note that `validate` subcommand and `feature gates` are not supported yet. +Note that `validate` subcommand and [feature gates](https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md#controlling-gates) are not supported yet. ## Components From 112934b2207043efee392d5f2e3761c80cbaace7 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 13:41:21 +0100 Subject: [PATCH 16/20] updated template --- internal/pkg/otel/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md index bb66f9aaf4b..a9adb749dc2 100644 --- a/internal/pkg/otel/README.md +++ b/internal/pkg/otel/README.md @@ -16,11 +16,11 @@ Both `yaml` and `yml` suffixes are supported. > In case this condition is not met, Elastic Agent will run in its default mode and will not behave as OpenTelemetry Collector. -Note that `validate` subcommand and `feature gates` are not supported yet. +Note that `validate` subcommand and [feature gates](https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md#controlling-gates) are not supported yet. ## Components -This sections provides a summary of components included in Elastic OpenTelemetry Collector distribution. +This section provides a summary of components included in the Elastic Distribution for OpenTelemetry Collector. ### Receivers From 7cdda8f7339aa509cf6bf30c277f5f703b33247b Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 14:17:34 +0100 Subject: [PATCH 17/20] Update magefile.go Co-authored-by: Shaunak Kashyap --- magefile.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magefile.go b/magefile.go index ddade47b96c..eb80203f2a4 100644 --- a/magefile.go +++ b/magefile.go @@ -2346,8 +2346,8 @@ func getOtelDependencies() (*dependencies, error) { processors = append(processors, d.Clean("/processor/")) } else if strings.Contains(l, "/exporter/") { exporters = append(exporters, d.Clean("/exporter/")) - } else if strings.Contains(l, "/extensions/") { - extensions = append(exporters, d.Clean("/extensions/")) + } else if strings.Contains(l, "/extension/") { + extensions = append(exporters, d.Clean("/extension/")) } } From a3ec581456da92b04b72e2ce8bda9f2cb3f13402 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 14:17:49 +0100 Subject: [PATCH 18/20] Update internal/pkg/otel/templates/README.md.tmpl Co-authored-by: Shaunak Kashyap --- internal/pkg/otel/templates/README.md.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/otel/templates/README.md.tmpl b/internal/pkg/otel/templates/README.md.tmpl index dcbc99329d2..0470c57a012 100644 --- a/internal/pkg/otel/templates/README.md.tmpl +++ b/internal/pkg/otel/templates/README.md.tmpl @@ -4,7 +4,7 @@ This is an Elastic supported distribution of the [OpenTelemetry Collector](https ## Running the Elastic Distribution for OpenTelemetry Collector -To run Elastic OpenTelemetry Distribution you can use Elastic-Agent binary downloaded for your OS and architecture. +To run the Elastic Distribution for OpenTelemetry Collector you can use Elastic-Agent binary downloaded for your OS and architecture. Running command ```bash From 778de8ef282afa84f95214300803d501d256b420 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 14:18:32 +0100 Subject: [PATCH 19/20] updated template --- internal/pkg/otel/README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md index a9adb749dc2..4eca0bea4d7 100644 --- a/internal/pkg/otel/README.md +++ b/internal/pkg/otel/README.md @@ -4,7 +4,7 @@ This is an Elastic supported distribution of the [OpenTelemetry Collector](https ## Running the Elastic Distribution for OpenTelemetry Collector -To run Elastic OpenTelemetry Distribution you can use Elastic-Agent binary downloaded for your OS and architecture. +To run the Elastic Distribution for OpenTelemetry Collector you can use Elastic-Agent binary downloaded for your OS and architecture. Running command ```bash @@ -56,3 +56,13 @@ This section provides a summary of components included in the Elastic Distributi + +### Extensions + +| Component | Version | +|---|---| +| fileexporter | v0.89.0| +| debugexporter | v0.89.0| +| otlpexporter | v0.89.0| +| auth | v0.89.0 // indirect| + From b57e460c48f19640644476f18904a5ae38547517 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 3 Jan 2024 14:21:03 +0100 Subject: [PATCH 20/20] updated template --- internal/pkg/otel/README.md | 10 ---------- magefile.go | 6 +++++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/pkg/otel/README.md b/internal/pkg/otel/README.md index 4eca0bea4d7..eeac70dc574 100644 --- a/internal/pkg/otel/README.md +++ b/internal/pkg/otel/README.md @@ -56,13 +56,3 @@ This section provides a summary of components included in the Elastic Distributi - -### Extensions - -| Component | Version | -|---|---| -| fileexporter | v0.89.0| -| debugexporter | v0.89.0| -| otlpexporter | v0.89.0| -| auth | v0.89.0 // indirect| - diff --git a/magefile.go b/magefile.go index eb80203f2a4..edfb9391c3d 100644 --- a/magefile.go +++ b/magefile.go @@ -2324,6 +2324,10 @@ func getOtelDependencies() (*dependencies, error) { continue } + if strings.Contains(l, "// indirect") { + continue + } + parseLine := func(line string) (dependency, error) { chunks := strings.SplitN(line, " ", 2) if len(chunks) != 2 { @@ -2347,7 +2351,7 @@ func getOtelDependencies() (*dependencies, error) { } else if strings.Contains(l, "/exporter/") { exporters = append(exporters, d.Clean("/exporter/")) } else if strings.Contains(l, "/extension/") { - extensions = append(exporters, d.Clean("/extension/")) + extensions = append(extensions, d.Clean("/extension/")) } }