Skip to content

Commit

Permalink
[otel] docs: Add links to components in OTel README (#5087)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzej-stencel authored Jul 10, 2024
1 parent a1eccc2 commit 341a24e
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 96 deletions.
44 changes: 22 additions & 22 deletions internal/pkg/otel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,45 @@ This section provides a summary of components included in the Elastic Distributi

| Component | Version |
|---|---|
| filelogreceiver | v0.104.0 |
| hostmetricsreceiver | v0.104.0 |
| httpcheckreceiver | v0.104.0 |
| k8sclusterreceiver | v0.104.0 |
| kubeletstatsreceiver | v0.104.0 |
| otlpreceiver | v0.104.0 |
| [filelogreceiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/receiver/filelogreceiver/v0.104.0/receiver/filelogreceiver/README.md) | v0.104.0 |
| [hostmetricsreceiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/receiver/hostmetricsreceiver/v0.104.0/receiver/hostmetricsreceiver/README.md) | v0.104.0 |
| [httpcheckreceiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/receiver/httpcheckreceiver/v0.104.0/receiver/httpcheckreceiver/README.md) | v0.104.0 |
| [k8sclusterreceiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/receiver/k8sclusterreceiver/v0.104.0/receiver/k8sclusterreceiver/README.md) | v0.104.0 |
| [kubeletstatsreceiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/receiver/kubeletstatsreceiver/v0.104.0/receiver/kubeletstatsreceiver/README.md) | v0.104.0 |
| [otlpreceiver](https://github.com/open-telemetry/opentelemetry-collector/blob/receiver/otlpreceiver/v0.104.0/receiver/otlpreceiver/README.md) | v0.104.0 |

### Exporters

| Component | Version |
|---|---|
| elasticsearchexporter | v0.104.0 |
| fileexporter | v0.104.0 |
| debugexporter | v0.104.0 |
| otlpexporter | v0.104.0 |
| otlphttpexporter | v0.104.0 |
| [elasticsearchexporter](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/exporter/elasticsearchexporter/v0.104.0/exporter/elasticsearchexporter/README.md) | v0.104.0 |
| [fileexporter](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/exporter/fileexporter/v0.104.0/exporter/fileexporter/README.md) | v0.104.0 |
| [debugexporter](https://github.com/open-telemetry/opentelemetry-collector/blob/exporter/debugexporter/v0.104.0/exporter/debugexporter/README.md) | v0.104.0 |
| [otlpexporter](https://github.com/open-telemetry/opentelemetry-collector/blob/exporter/otlpexporter/v0.104.0/exporter/otlpexporter/README.md) | v0.104.0 |
| [otlphttpexporter](https://github.com/open-telemetry/opentelemetry-collector/blob/exporter/otlphttpexporter/v0.104.0/exporter/otlphttpexporter/README.md) | v0.104.0 |

### Processors

| Component | Version |
|---|---|
| elasticinframetricsprocessor | v0.7.0 |
| attributesprocessor | v0.104.0 |
| filterprocessor | v0.104.0 |
| k8sattributesprocessor | v0.104.0 |
| resourcedetectionprocessor | v0.104.0 |
| resourceprocessor | v0.104.0 |
| transformprocessor | v0.104.0 |
| batchprocessor | v0.104.0 |
| [elasticinframetricsprocessor](https://github.com/elastic/opentelemetry-collector-components/blob/processor/elasticinframetricsprocessor/v0.7.0/processor/elasticinframetricsprocessor/README.md) | v0.7.0 |
| [attributesprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/processor/attributesprocessor/v0.104.0/processor/attributesprocessor/README.md) | v0.104.0 |
| [filterprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/processor/filterprocessor/v0.104.0/processor/filterprocessor/README.md) | v0.104.0 |
| [k8sattributesprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/processor/k8sattributesprocessor/v0.104.0/processor/k8sattributesprocessor/README.md) | v0.104.0 |
| [resourcedetectionprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/processor/resourcedetectionprocessor/v0.104.0/processor/resourcedetectionprocessor/README.md) | v0.104.0 |
| [resourceprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/processor/resourceprocessor/v0.104.0/processor/resourceprocessor/README.md) | v0.104.0 |
| [transformprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/processor/transformprocessor/v0.104.0/processor/transformprocessor/README.md) | v0.104.0 |
| [batchprocessor](https://github.com/open-telemetry/opentelemetry-collector/blob/processor/batchprocessor/v0.104.0/processor/batchprocessor/README.md) | v0.104.0 |

### Extensions

| Component | Version |
|---|---|
| storage/filestorage | v0.104.0 |
| memorylimiterextension | v0.104.0 |
| [filestorage](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/extension/storage/filestorage/v0.104.0/extension/storage/filestorage/README.md) | v0.104.0 |
| [memorylimiterextension](https://github.com/open-telemetry/opentelemetry-collector/blob/extension/memorylimiterextension/v0.104.0/extension/memorylimiterextension/README.md) | v0.104.0 |

### Connectors

| Component | Version |
|---|---|
| spanmetricsconnector | v0.104.0 |
| [spanmetricsconnector](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/connector/spanmetricsconnector/v0.104.0/connector/spanmetricsconnector/README.md) | v0.104.0 |
10 changes: 5 additions & 5 deletions internal/pkg/otel/templates/README.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This section provides a summary of components included in the Elastic Distributi
| Component | Version |
|---|---|
{{ range .Receivers -}}
| {{ .Name }} | {{ .Version }} |
| [{{ .Name }}]({{ .Link }}) | {{ .Version }} |
{{ end -}}
{{ end -}}

Expand All @@ -41,7 +41,7 @@ This section provides a summary of components included in the Elastic Distributi
| Component | Version |
|---|---|
{{ range .Exporters -}}
| {{ .Name }} | {{ .Version }} |
| [{{ .Name }}]({{ .Link }}) | {{ .Version }} |
{{ end -}}
{{ end -}}

Expand All @@ -51,7 +51,7 @@ This section provides a summary of components included in the Elastic Distributi
| Component | Version |
|---|---|
{{ range .Processors -}}
| {{ .Name }} | {{ .Version }} |
| [{{ .Name }}]({{ .Link }}) | {{ .Version }} |
{{ end -}}
{{ end -}}

Expand All @@ -61,7 +61,7 @@ This section provides a summary of components included in the Elastic Distributi
| Component | Version |
|---|---|
{{ range .Extensions -}}
| {{ .Name }} | {{ .Version }} |
| [{{ .Name }}]({{ .Link }}) | {{ .Version }} |
{{ end -}}
{{ end -}}

Expand All @@ -71,6 +71,6 @@ This section provides a summary of components included in the Elastic Distributi
| Component | Version |
|---|---|
{{ range .Connectors -}}
| {{ .Name }} | {{ .Version }} |
| [{{ .Name }}]({{ .Link }}) | {{ .Version }} |
{{ end -}}
{{ end -}}
186 changes: 117 additions & 69 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3056,35 +3056,6 @@ func hasCleanOnExit() bool {
return b
}

type dependency struct {
Name string
Version string
}

type dependencies struct {
Receivers []dependency
Exporters []dependency
Processors []dependency
Extensions []dependency
Connectors []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")

Expand Down Expand Up @@ -3112,7 +3083,7 @@ func (Otel) Readme() error {
return tmpl.Execute(out, data)
}

func getOtelDependencies() (*dependencies, error) {
func getOtelDependencies() (*otelDependencies, error) {
// read go.mod
readFile, err := os.Open("go.mod")
if err != nil {
Expand All @@ -3123,55 +3094,132 @@ func getOtelDependencies() (*dependencies, error) {
scanner := bufio.NewScanner(readFile)

scanner.Split(bufio.ScanLines)
var receivers, extensions, exporters, processors, connectors []dependency
var receivers, extensions, exporters, processors, connectors []*otelDependency
// 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/") &&
!strings.Contains(l, "github.com/elastic/opentelemetry-collector-components/") {
continue
}

if strings.Contains(l, "// indirect") {
dependency := newOtelDependency(l)
if dependency == nil {
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/"))
} else if strings.Contains(l, "/connector/") {
connectors = append(connectors, d.Clean("/connector/"))
if dependency.ComponentType == "connector" {
connectors = append(connectors, dependency)
} else if dependency.ComponentType == "exporter" {
exporters = append(exporters, dependency)
} else if dependency.ComponentType == "extension" {
extensions = append(extensions, dependency)
} else if dependency.ComponentType == "processor" {
processors = append(processors, dependency)
} else if dependency.ComponentType == "receiver" {
receivers = append(receivers, dependency)
}
}

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

type otelDependency struct {
ComponentType string
Name string
Version string
Link string
}

func newOtelDependency(l string) *otelDependency {
if !strings.Contains(l, "go.opentelemetry.io/") &&
!strings.Contains(l, "github.com/open-telemetry/") &&
!strings.Contains(l, "github.com/elastic/opentelemetry-collector-components/") {
return nil
}

if strings.Contains(l, "// indirect") {
return nil
}

chunks := strings.SplitN(l, " ", 2)
if len(chunks) != 2 {
return nil
}
dependencyURI := chunks[0]
version := chunks[1]

componentName := getOtelComponentName(dependencyURI)
componentType := getOtelComponentType(dependencyURI)
link := getOtelDependencyLink(dependencyURI, version)

return &otelDependency{
ComponentType: componentType,
Name: componentName,
Version: version,
Link: link,
}
}

func getOtelComponentName(dependencyName string) string {
parts := strings.Split(dependencyName, "/")
return parts[len(parts)-1]
}

func getOtelComponentType(dependencyName string) string {
if strings.Contains(dependencyName, "/connector/") {
return "connector"
} else if strings.Contains(dependencyName, "/exporter/") {
return "exporter"
} else if strings.Contains(dependencyName, "/extension/") {
return "extension"
} else if strings.Contains(dependencyName, "/processor/") {
return "processor"
} else if strings.Contains(dependencyName, "/receiver/") {
return "receiver"
}
return ""
}

func getOtelDependencyLink(dependencyURI string, version string) string {
dependencyRepository := getDependencyRepository(dependencyURI)
dependencyPath := strings.TrimPrefix(dependencyURI, dependencyRepository+"/")
repositoryURL := getOtelRepositoryURL(dependencyURI)
return fmt.Sprintf("https://%s/blob/%s/%s/%s/README.md", repositoryURL, dependencyPath, version, dependencyPath)
}

func getDependencyRepository(dependencyURI string) string {
dependencyURIChunks := strings.Split(dependencyURI, "/")
if len(dependencyURIChunks) < 2 {
return ""
}
var dependencyRepository string
if dependencyURIChunks[0] == "go.opentelemetry.io" {
dependencyRepository = dependencyURIChunks[0] + "/" + dependencyURIChunks[1]
} else {
dependencyRepository = dependencyURIChunks[0] + "/" + dependencyURIChunks[1] + "/" + dependencyURIChunks[2]
}
return dependencyRepository
}

func getOtelRepositoryURL(dependencyURI string) string {
if strings.HasPrefix(dependencyURI, "go.opentelemetry.io/") {
return "github.com/open-telemetry/opentelemetry-collector"
} else if strings.HasPrefix(dependencyURI, "github.com/") {
parts := strings.SplitN(dependencyURI, "/", 4)
hostPart := parts[0]
orgPart := parts[1]
repoPart := parts[2]
return fmt.Sprintf("%s/%s/%s", hostPart, orgPart, repoPart)
}
return ""
}

type otelDependencies struct {
Connectors []*otelDependency
Exporters []*otelDependency
Extensions []*otelDependency
Processors []*otelDependency
Receivers []*otelDependency
}

0 comments on commit 341a24e

Please sign in to comment.