-
Notifications
You must be signed in to change notification settings - Fork 198
Add components YAML file with Core and Extended info #8530
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0896ed1
Add components YAML file with Core and Extended info
theletterf 27d73aa
Rename file
theletterf fec5cdd
Add test
theletterf ae0efbe
Format
theletterf 0c3d599
Merge branch 'main' into add-components-yaml
theletterf 2b0e1ad
Update internal/pkg/otel/core_components_test.go
theletterf d72217b
Simplify test
theletterf b6d4b28
Format
theletterf 766116b
Update internal/pkg/otel/core_components_test.go
theletterf 57a3d43
Update internal/pkg/otel/core_components_test.go
theletterf 805ccbe
Fix missing quotes
theletterf 3e6c73e
Merge branch 'main' into add-components-yaml
theletterf 5f9914a
Merge branch 'main' into add-components-yaml
theletterf 454d193
Merge branch 'main' into add-components-yaml
theletterf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Components classification for the OpenTelemetry Collector | ||
| components: | ||
|
|
||
| # | ||
| # List of core components of the EDOT Collector | ||
| # | ||
|
|
||
| # Receivers | ||
| - filelogreceiver | ||
| - hostmetricsreceiver | ||
| - k8sclusterreceiver | ||
| - k8sobjectsreceiver | ||
| - kubeletstatsreceiver | ||
| - otlpreceiver | ||
|
|
||
| # Exporters | ||
| - elasticsearchexporter | ||
| - otlpexporter | ||
| - otlphttpexporter | ||
|
|
||
| # Processors | ||
| - attributesprocessor | ||
| - batchprocessor | ||
| - elasticinframetricsprocessor | ||
| - elastictraceprocessor | ||
| - k8sattributesprocessor | ||
| - resourcedetectionprocessor | ||
| - resourceprocessor | ||
| - transformprocessor | ||
|
|
||
| # Connectors | ||
| - elasticapmconnector | ||
| - routingconnector | ||
|
|
||
| # Extensions | ||
| - filestorage | ||
|
|
||
| # Providers | ||
| - envprovider | ||
| - fileprovider | ||
| - httpprovider | ||
| - httpsprovider | ||
| - yamlprovider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
| // you may not use this file except in compliance with the Elastic License 2.0. | ||
|
|
||
| package otel | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| // TestCoreComponentsInGoMod verifies that all components listed in core-components.yaml | ||
| // are present in the project dependencies. | ||
| func TestCoreComponentsInGoMod(t *testing.T) { | ||
| // Extract components from project dependencies | ||
| moduleComponents, err := extractComponentsFromDeps() | ||
| require.NoError(t, err, "Failed to extract components from dependencies") | ||
|
|
||
| // Print found components for debugging | ||
| t.Logf("Found components in dependencies: %v", moduleComponents) | ||
|
|
||
| // Load components from core-components.yaml | ||
| yamlComponents, err := loadCoreComponentsYAML() | ||
| require.NoError(t, err, "Failed to load core-components.yaml") | ||
|
|
||
| // Verify all components in YAML are present in dependencies | ||
| for _, component := range yamlComponents { | ||
| assert.Contains(t, moduleComponents, component) | ||
| } | ||
| } | ||
|
|
||
| // GoListModule represents the relevant parts of the `go list -json` output | ||
| type GoListModule struct { | ||
| Deps []string `json:"Deps"` | ||
| } | ||
|
|
||
| // extractComponentsFromDeps extracts component names from the project dependencies | ||
| // by running `go list -json` and parsing the output | ||
| func extractComponentsFromDeps() ([]string, error) { | ||
| // Run go list -json to get the dependencies | ||
| cmd := exec.Command("go", "list", "-json", "github.com/elastic/elastic-agent") | ||
| output, err := cmd.Output() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to run go list command: %w", err) | ||
| } | ||
|
|
||
| // Parse the JSON output | ||
| var module GoListModule | ||
| if err := json.Unmarshal(output, &module); err != nil { | ||
| return nil, fmt.Errorf("failed to parse go list output: %w", err) | ||
| } | ||
|
|
||
| // Component types to look for in dependency paths | ||
| componentTypes := []string{ | ||
| "processor", | ||
| "receiver", | ||
| "extension", | ||
| "exporter", | ||
| "connector", | ||
| "confmap/provider", | ||
| "storage", | ||
| } | ||
|
|
||
| // Extract component names from dependency paths | ||
| var components []string | ||
| for _, dep := range module.Deps { | ||
| for _, cType := range componentTypes { | ||
| // Check if the dependency path contains the component type | ||
| if strings.Contains(dep, "/"+cType+"/") { | ||
| // Extract the component name (last part of the path) | ||
| parts := strings.Split(dep, "/") | ||
| if len(parts) > 0 { | ||
| componentName := parts[len(parts)-1] | ||
| components = append(components, componentName) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Special case for filestorage which is under extension/storage/ | ||
| if strings.Contains(dep, "/extension/storage/") { | ||
| parts := strings.Split(dep, "/") | ||
| if len(parts) > 0 { | ||
| componentName := parts[len(parts)-1] | ||
| components = append(components, componentName) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return components, nil | ||
| } | ||
|
|
||
| // loadCoreComponentsYAML loads the components from core-components.yaml | ||
| func loadCoreComponentsYAML() ([]string, error) { | ||
| // Get the directory of the current file | ||
| _, filename, _, ok := runtime.Caller(0) | ||
| if !ok { | ||
| return nil, fmt.Errorf("failed to get current file path") | ||
| } | ||
| dir := filepath.Dir(filename) | ||
| yamlPath := filepath.Join(dir, "core-components.yaml") | ||
|
|
||
| yamlFile, err := os.ReadFile(yamlPath) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var data struct { | ||
| Components []string `yaml:"components"` | ||
| } | ||
|
|
||
| err = yaml.Unmarshal(yamlFile, &data) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Filter out any empty strings or comments | ||
| var filteredComponents []string | ||
| for _, comp := range data.Components { | ||
| comp = strings.TrimSpace(comp) | ||
| if comp != "" && !strings.HasPrefix(comp, "#") { | ||
| filteredComponents = append(filteredComponents, comp) | ||
| } | ||
| } | ||
|
|
||
| return filteredComponents, nil | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.