forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] add metadata status checks on the distribution (#21275)
Add a test checking that the status metadata of a component matches their presence in the otelcontribcol test suite.
- Loading branch information
Showing
2 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,95 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/confmap/provider/fileprovider" | ||
) | ||
|
||
func TestComponentsArePresent(t *testing.T) { | ||
components, err := components() | ||
require.NoError(t, err) | ||
var metadataComponents []string | ||
e := filepath.Walk(filepath.Join("..", ".."), func(path string, info os.FileInfo, err error) error { | ||
if err == nil && "metadata.yaml" == info.Name() { | ||
metadataComponents = append(metadataComponents, path) | ||
} | ||
return nil | ||
}) | ||
require.NoError(t, e) | ||
|
||
for _, metadataComponent := range metadataComponents { | ||
t.Run(metadataComponent, func(tt *testing.T) { | ||
m, err := loadMetadata(metadataComponent) | ||
require.NoError(tt, err) | ||
if m.Status == nil { | ||
tt.Skip("no status present, skipping", metadataComponent) | ||
return | ||
} | ||
inDevelopment := true | ||
for stability, pipelines := range m.Status.Stability { | ||
if stability != "development" && len(pipelines) > 0 { | ||
inDevelopment = false | ||
break | ||
} | ||
} | ||
|
||
if inDevelopment { | ||
tt.Skip("component in development, skipping", metadataComponent) | ||
return | ||
} | ||
switch m.Status.Class { | ||
case "connector": | ||
assert.NotNil(tt, components.Connectors[component.Type(m.Type)], "missing connector: %s", m.Type) | ||
case "exporter": | ||
assert.NotNil(tt, components.Exporters[component.Type(m.Type)], "missing exporter: %s", m.Type) | ||
case "extension": | ||
assert.NotNil(tt, components.Extensions[component.Type(m.Type)], "missing extension: %s", m.Type) | ||
case "processor": | ||
assert.NotNil(tt, components.Processors[component.Type(m.Type)], "missing processor: %s", m.Type) | ||
case "receiver": | ||
assert.NotNil(tt, components.Receivers[component.Type(m.Type)], "missing receiver: %s", m.Type) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func loadMetadata(filePath string) (metadata, error) { | ||
cp, err := fileprovider.New().Retrieve(context.Background(), "file:"+filePath, nil) | ||
if err != nil { | ||
return metadata{}, err | ||
} | ||
|
||
conf, err := cp.AsConf() | ||
if err != nil { | ||
return metadata{}, err | ||
} | ||
|
||
md := metadata{} | ||
if err := conf.Unmarshal(&md); err != nil { | ||
return md, err | ||
} | ||
|
||
return md, nil | ||
} | ||
|
||
type metadata struct { | ||
Type string `mapstructure:"type"` | ||
Status *status `mapstructure:"status"` | ||
} | ||
|
||
type status struct { | ||
Stability map[string][]string `mapstructure:"stability"` | ||
Distributions []string `mapstructure:"distributions"` | ||
Class string `mapstructure:"class"` | ||
Warnings []string `mapstructure:"warnings"` | ||
} |
This file contains 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