Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Readme file for otel #3992

Merged
merged 23 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4a51276
otel readme
michalpristas Dec 29, 2023
e48ea17
Merge branch 'main' of github.com:elastic/elastic-agent into otel-readme
michalpristas Jan 2, 2024
bdd9353
Generate Otel Readme
michalpristas Jan 3, 2024
5ddb82f
readme template update
michalpristas Jan 3, 2024
7f4c13e
updated generated readme
michalpristas Jan 3, 2024
0467a9d
clean names
michalpristas Jan 3, 2024
b05200f
clean names
michalpristas Jan 3, 2024
be1943c
template update
michalpristas Jan 3, 2024
2dadc65
template update
michalpristas Jan 3, 2024
9f61534
Merge branch 'main' of github.com:elastic/elastic-agent into otel-readme
michalpristas Jan 3, 2024
b3673a1
Update internal/pkg/otel/templates/README.md.tmpl
michalpristas Jan 3, 2024
fe57a05
Update internal/pkg/otel/templates/README.md.tmpl
michalpristas Jan 3, 2024
43d494b
extensions
michalpristas Jan 3, 2024
8ed7bba
Merge branch 'otel-readme' of github.com:michalpristas/elastic-agent …
michalpristas Jan 3, 2024
b910c52
updated readme
michalpristas Jan 3, 2024
0b1c017
updated template
michalpristas Jan 3, 2024
efafba2
Update internal/pkg/otel/templates/README.md.tmpl
michalpristas Jan 3, 2024
725f6a8
Update internal/pkg/otel/templates/README.md.tmpl
michalpristas Jan 3, 2024
112934b
updated template
michalpristas Jan 3, 2024
7cdda8f
Update magefile.go
michalpristas Jan 3, 2024
a3ec581
Update internal/pkg/otel/templates/README.md.tmpl
michalpristas Jan 3, 2024
778de8e
updated template
michalpristas Jan 3, 2024
b57e460
updated template
michalpristas Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions internal/pkg/otel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Elastic Distribution for OpenTelemetry Collector

This is an Elastic supported distribution of the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector).

## Running the Elastic Distribution for OpenTelemetry Collector

To run the Elastic Distribution for OpenTelemetry Collector you can use Elastic-Agent binary downloaded for your OS and architecture.
Running command

```bash
./elastic-agent -c otel.yml run
```

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.

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 section provides a summary of components included in the Elastic Distribution for OpenTelemetry Collector.


### Receivers

| Component | Version |
|---|---|
| filelogreceiver | v0.89.0|
| otlpreceiver | v0.89.0|




### Exporters

| Component | Version |
|---|---|
| fileexporter | v0.89.0|
| debugexporter | v0.89.0|
| otlpexporter | v0.89.0|




### Processors

| Component | Version |
|---|---|
| attributesprocessor | v0.89.0|
| resourceprocessor | v0.89.0|
| transformprocessor | v0.89.0|
| batchprocessor | v0.89.0|
| memorylimiterprocessor | v0.89.0|



59 changes: 59 additions & 0 deletions internal/pkg/otel/templates/README.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Elastic Distribution for OpenTelemetry Collector

This is an Elastic supported distribution of the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector).

## Running the Elastic Distribution for OpenTelemetry Collector

To run the Elastic Distribution for OpenTelemetry Collector you can use Elastic-Agent binary downloaded for your OS and architecture.
Running command

```bash
./elastic-agent -c otel.yml run
```

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.

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 section provides a summary of components included in the Elastic Distribution for OpenTelemetry Collector.

{{ 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 }}
121 changes: 120 additions & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"encoding/json"
"errors"
"fmt"
"html/template"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -120,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")
Expand Down Expand Up @@ -550,7 +554,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, Otel.Readme)
}

// CrossBuild cross-builds the beat for all target platforms.
Expand Down Expand Up @@ -2243,3 +2247,118 @@ func hasCleanOnExit() bool {
b, _ := strconv.ParseBool(clean)
return b
}

type dependency struct {
Name string
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)
if len(chunks) == 2 {
return chunks[1]
}

return dep
}

return dependency{
Name: cleanFn(d.Name, sep),
Version: d.Version,
}
}

func (Otel) Readme() error {
fmt.Println(">> Building internal/pkg/otel/README.md")

readmeTmpl := filepath.Join("internal", "pkg", "otel", "templates", "README.md.tmpl")
readmeOut := filepath.Join("internal", "pkg", "otel", "README.md")

// read README template
tmpl, err := template.ParseFiles(readmeTmpl)
if err != nil {
return fmt.Errorf("failed to parse README template: %w", err)
}

data, err := getOtelDependencies()
if err != nil {
return fmt.Errorf("Failed to get OTel dependencies: %w", err)
}

// 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", readmeOut, err)
}
defer out.Close()

return tmpl.Execute(out, data)
}

func getOtelDependencies() (*dependencies, error) {
// read go.mod
readFile, err := os.Open("go.mod")
if err != nil {
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())
// is otel
if !strings.Contains(l, "go.opentelemetry.io/") &&
!strings.Contains(l, "github.com/open-telemetry/") {
continue
}

if strings.Contains(l, "// indirect") {
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, err
}

if strings.Contains(l, "/receiver/") {
receivers = append(receivers, d.Clean("/receiver/"))
} else if strings.Contains(l, "/processor/") {
processors = append(processors, d.Clean("/processor/"))
} else if strings.Contains(l, "/exporter/") {
exporters = append(exporters, d.Clean("/exporter/"))
} else if strings.Contains(l, "/extension/") {
extensions = append(extensions, d.Clean("/extension/"))
}
}

return &dependencies{
Receivers: receivers,
Exporters: exporters,
Processors: processors,
Extensions: extensions,
}, nil
}
Loading