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

Delete all the unused parsers #3249

Merged
merged 14 commits into from
Sep 23, 2024
Prev Previous commit
Next Next commit
fix tests
jaronoff97 committed Aug 7, 2024
commit 91cf3829bf519cf23b2b958c4fa67d4ff9f53701
8 changes: 7 additions & 1 deletion apis/v1beta1/config.go
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ import (

"github.com/open-telemetry/opentelemetry-operator/internal/components"
"github.com/open-telemetry/opentelemetry-operator/internal/components/exporters"
"github.com/open-telemetry/opentelemetry-operator/internal/components/processors"
"github.com/open-telemetry/opentelemetry-operator/internal/components/receivers"
)

@@ -155,7 +156,12 @@ func (c *Config) getRbacRulesForComponentKinds(logger logr.Logger, componentKind
retriever = exporters.ParserFor
cfg = c.Exporters
case KindProcessor:
break
retriever = processors.ProcessorFor
if c.Processors == nil {
cfg = AnyConfig{}
} else {
cfg = *c.Processors
}
}
for componentName := range enabledComponents[componentKind] {
// TODO: Clean up the naming here and make it simpler to use a retriever.
3 changes: 1 addition & 2 deletions internal/components/generic_config_parser.go
Original file line number Diff line number Diff line change
@@ -28,10 +28,9 @@ var (
)

// GenericParser serves as scaffolding for custom parsing logic by isolating
// functionality to idempotent functions like RBACRuleGenerator
// functionality to idempotent functions like RBACRuleGenerator.
type GenericParser[T any] struct {
name string
config T
rbacGen RBACRuleGenerator[T]
}

2 changes: 1 addition & 1 deletion internal/components/processors/helpers.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ func ProcessorFor(name string) components.Parser {
if parser, ok := registry[components.ComponentType(name)]; ok {
return parser
}
return components.NewSilentSinglePortParser(components.ComponentType(name), components.UnsetPort, nil)
return components.NewSilentSinglePortParser(components.ComponentType(name), components.UnsetPort)
}

var componentParsers = []components.Parser{
4 changes: 2 additions & 2 deletions internal/components/processors/helpers_test.go
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ func TestDownstreamParsers(t *testing.T) {
parserName string
}{
{"k8sattributes", "k8sattributes", "__k8sattributes"},
{"opencensus", "opencensus", "__opencensus"},
{"resourcedetection", "resourcedetection", "__resourcedetection"},
} {
t.Run(tt.processorName, func(t *testing.T) {
t.Run("builds successfully", func(t *testing.T) {
@@ -50,7 +50,7 @@ func TestDownstreamParsers(t *testing.T) {
_, err := parser.Ports(logger, tt.processorName, func() {})

// verify
assert.ErrorContains(t, err, "expected a map, got 'func'")
assert.Nil(t, err)
})

})
2 changes: 1 addition & 1 deletion internal/components/receivers/helpers.go
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ func ReceiverFor(name string) components.Parser {
if parser, ok := registry[components.ComponentType(name)]; ok {
return parser
}
return components.NewSilentSinglePortParser(components.ComponentType(name), components.UnsetPort, nil)
return components.NewSilentSinglePortParser(components.ComponentType(name), components.UnsetPort)
}

var (
14 changes: 3 additions & 11 deletions internal/components/single_endpoint.go
Original file line number Diff line number Diff line change
@@ -65,18 +65,10 @@ type SingleEndpointParser struct {

// failSilently allows the parser to prevent the propagation of failure if the parser fails to set a port.
failSilently bool
rbacGen RBACRuleGenerator[SingleEndpointConfig]
}

func (s *SingleEndpointParser) GetRBACRules(logger logr.Logger, config interface{}) ([]rbacv1.PolicyRule, error) {
if s.rbacGen == nil {
return nil, nil
}
var singleEndpointConfig SingleEndpointConfig
if err := mapstructure.Decode(config, &singleEndpointConfig); err != nil {
return nil, err
}
return s.rbacGen(logger, singleEndpointConfig)
return nil, nil
}

func (s *SingleEndpointParser) Ports(logger logr.Logger, name string, config interface{}) ([]corev1.ServicePort, error) {
@@ -119,13 +111,13 @@ func NewSinglePortParser(name string, port int32, opts ...PortBuilderOption) *Si
}

// NewSilentSinglePortParser returns a SingleEndpointParser that errors silently on failure to find a port.
func NewSilentSinglePortParser(name string, port int32, rbacGen RBACRuleGenerator[SingleEndpointConfig], opts ...PortBuilderOption) *SingleEndpointParser {
func NewSilentSinglePortParser(name string, port int32, opts ...PortBuilderOption) *SingleEndpointParser {
servicePort := &corev1.ServicePort{
Name: naming.PortName(name, port),
Port: port,
}
for _, opt := range opts {
opt(servicePort)
}
return &SingleEndpointParser{name: name, svcPort: servicePort, rbacGen: rbacGen, failSilently: true}
return &SingleEndpointParser{name: name, svcPort: servicePort, failSilently: true}
}
2 changes: 1 addition & 1 deletion internal/components/single_endpoint_test.go
Original file line number Diff line number Diff line change
@@ -393,7 +393,7 @@ func TestNewSilentSinglePortParser_Ports(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := components.NewSilentSinglePortParser(tt.fields.name, tt.fields.port, nil, tt.fields.opts...)
s := components.NewSilentSinglePortParser(tt.fields.name, tt.fields.port, tt.fields.opts...)
got, err := s.Ports(logr.Discard(), tt.fields.name, tt.args.config)
if !tt.wantErr(t, err, fmt.Sprintf("Ports(%v)", tt.args.config)) {
return
10 changes: 9 additions & 1 deletion pkg/instrumentation/sdk_test.go
Original file line number Diff line number Diff line change
@@ -596,6 +596,14 @@ func TestSDKInjection(t *testing.T) {
Name: "OTEL_TRACES_SAMPLER",
Value: "always_on",
},
{
Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
{
Name: "OTEL_RESOURCE_ATTRIBUTES_NODE_NAME",
ValueFrom: &corev1.EnvVarSource{
@@ -606,7 +614,7 @@ func TestSDKInjection(t *testing.T) {
},
{
Name: "OTEL_RESOURCE_ATTRIBUTES",
Value: "foo=bar,k8s.container.name=other,service.version=explicitly_set,foo=test,fromcr=val,fromtest=val,k8s.namespace.name=project1,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=app",
Value: "foo=bar,k8s.container.name=other,service.version=explicitly_set,foo=test,fromcr=val,fromtest=val,k8s.namespace.name=project1,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)",
},
},
},