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

[chore] apply fieldalignment to routingconnector #37314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 7 additions & 10 deletions connector/routingconnector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ var (

// Config defines configuration for the Routing processor.
type Config struct {
// DefaultPipelines contains the list of pipelines to use when a more specific record can't be
// found in the routing table.
// Optional.
DefaultPipelines []pipeline.ID `mapstructure:"default_pipelines"`

// MatchOnce determines whether the connector matches multiple statements.
// Unused. Deprecated in v0.116.0. Will be removed in v0.120.0.
MatchOnce *bool `mapstructure:"match_once"`
// ErrorMode determines how the processor reacts to errors that occur while processing an OTTL
// condition.
// Valid values are `ignore` and `propagate`.
Expand All @@ -37,14 +35,13 @@ type Config struct {
// dropped from the collector.
// The default value is `propagate`.
ErrorMode ottl.ErrorMode `mapstructure:"error_mode"`

// DefaultPipelines contains the list of pipelines to use when a more specific record can't be
// found in the routing table.
// Optional.
DefaultPipelines []pipeline.ID `mapstructure:"default_pipelines"`
// Table contains the routing table for this processor.
// Required.
Table []RoutingTableItem `mapstructure:"table"`

// MatchOnce determines whether the connector matches multiple statements.
// Unused. Deprecated in v0.116.0. Will be removed in v0.120.0.
MatchOnce *bool `mapstructure:"match_once"`
}

// Validate checks if the processor configuration is valid.
Expand Down
4 changes: 2 additions & 2 deletions connector/routingconnector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (

func TestLoadConfig(t *testing.T) {
testcases := []struct {
configPath string
id component.ID
expected component.Config
id component.ID
configPath string
}{
{
configPath: filepath.Join("testdata", "config", "traces.yaml"),
Expand Down
8 changes: 4 additions & 4 deletions connector/routingconnector/internal/plogutil/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (

func TestMoveResourcesIf(t *testing.T) {
testCases := []struct {
name string
moveIf func(plog.ResourceLogs) bool
from plog.Logs
to plog.Logs
expectFrom plog.Logs
expectTo plog.Logs
moveIf func(plog.ResourceLogs) bool
name string
}{
{
name: "move_none",
Expand Down Expand Up @@ -86,12 +86,12 @@ func TestMoveResourcesIf(t *testing.T) {

func TestMoveRecordsWithContextIf(t *testing.T) {
testCases := []struct {
name string
moveIf func(plog.ResourceLogs, plog.ScopeLogs, plog.LogRecord) bool
from plog.Logs
to plog.Logs
expectFrom plog.Logs
expectTo plog.Logs
moveIf func(plog.ResourceLogs, plog.ScopeLogs, plog.LogRecord) bool
name string
}{
{
name: "move_none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (

func TestMoveResourcesIf(t *testing.T) {
testCases := []struct {
name string
moveIf func(pmetric.ResourceMetrics) bool
from pmetric.Metrics
to pmetric.Metrics
expectFrom pmetric.Metrics
expectTo pmetric.Metrics
moveIf func(pmetric.ResourceMetrics) bool
name string
}{
{
name: "move_none",
Expand Down Expand Up @@ -83,12 +83,12 @@ func TestMoveResourcesIf(t *testing.T) {

func TestMoveMetricsWithContextIf(t *testing.T) {
testCases := []struct {
name string
moveIf func(pmetric.ResourceMetrics, pmetric.ScopeMetrics, pmetric.Metric) bool
from pmetric.Metrics
to pmetric.Metrics
expectFrom pmetric.Metrics
expectTo pmetric.Metrics
moveIf func(pmetric.ResourceMetrics, pmetric.ScopeMetrics, pmetric.Metric) bool
name string
}{
{
name: "move_none",
Expand Down Expand Up @@ -265,12 +265,12 @@ func TestMoveMetricsWithContextIf(t *testing.T) {

func TestMoveDataPointsWithContextIf(t *testing.T) {
testCases := []struct {
name string
moveIf func(pmetric.ResourceMetrics, pmetric.ScopeMetrics, pmetric.Metric, any) bool
from pmetric.Metrics
to pmetric.Metrics
expectFrom pmetric.Metrics
expectTo pmetric.Metrics
moveIf func(pmetric.ResourceMetrics, pmetric.ScopeMetrics, pmetric.Metric, any) bool
name string
}{
// gauge
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (

func TestMoveResourcesIf(t *testing.T) {
testCases := []struct {
name string
moveIf func(ptrace.ResourceSpans) bool
from ptrace.Traces
to ptrace.Traces
expectFrom ptrace.Traces
expectTo ptrace.Traces
moveIf func(ptrace.ResourceSpans) bool
name string
}{
{
name: "move_none",
Expand Down Expand Up @@ -83,12 +83,12 @@ func TestMoveResourcesIf(t *testing.T) {

func TestMoveSpansWithContextIf(t *testing.T) {
testCases := []struct {
name string
moveIf func(ptrace.ResourceSpans, ptrace.ScopeSpans, ptrace.Span) bool
from ptrace.Traces
to ptrace.Traces
expectFrom ptrace.Traces
expectTo ptrace.Traces
moveIf func(ptrace.ResourceSpans, ptrace.ScopeSpans, ptrace.Span) bool
name string
}{
{
name: "move_none",
Expand Down
4 changes: 2 additions & 2 deletions connector/routingconnector/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,13 @@ func TestLogsConnectorDetailed(t *testing.T) {
isResourceBFromLowerContext := `resource.attributes["resourceName"] == "resourceB"`

testCases := []struct {
name string
cfg *Config
ctx context.Context
input plog.Logs
expectSink0 plog.Logs
expectSink1 plog.Logs
expectSinkD plog.Logs
cfg *Config
name string
}{
{
name: "request/no_request_values",
Expand Down
4 changes: 2 additions & 2 deletions connector/routingconnector/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,13 @@ func TestMetricsConnectorDetailed(t *testing.T) {
isResourceBFromLowerContext := `resource.attributes["resourceName"] == "resourceB"`

testCases := []struct {
name string
cfg *Config
ctx context.Context
input pmetric.Metrics
expectSink0 pmetric.Metrics
expectSink1 pmetric.Metrics
expectSinkD pmetric.Metrics
cfg *Config
name string
}{
{
name: "request/no_request_values",
Expand Down
2 changes: 1 addition & 1 deletion connector/routingconnector/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var (
)

type requestCondition struct {
attributeName string
compareFunc func(string) bool
attributeName string
}

func parseRequestCondition(condition string) (*requestCondition, error) {
Expand Down
22 changes: 10 additions & 12 deletions connector/routingconnector/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ type consumerProvider[C any] func(...pipeline.ID) (C, error)
// parameter C is expected to be one of: consumer.Traces, consumer.Metrics, or
// consumer.Logs.
type router[C any] struct {
logger *zap.Logger
resourceParser ottl.Parser[ottlresource.TransformContext]
spanParser ottl.Parser[ottlspan.TransformContext]
metricParser ottl.Parser[ottlmetric.TransformContext]
dataPointParser ottl.Parser[ottldatapoint.TransformContext]
logParser ottl.Parser[ottllog.TransformContext]

table []RoutingTableItem
routes map[string]routingItem[C]
routeSlice []routingItem[C]

resourceParser ottl.Parser[ottlresource.TransformContext]
spanParser ottl.Parser[ottlspan.TransformContext]
metricParser ottl.Parser[ottlmetric.TransformContext]
dataPointParser ottl.Parser[ottldatapoint.TransformContext]
logParser ottl.Parser[ottllog.TransformContext]
defaultConsumer C
logger *zap.Logger
routes map[string]routingItem[C]
consumerProvider consumerProvider[C]
table []RoutingTableItem
routeSlice []routingItem[C]
}

// newRouter creates a new router instance with based on type parameters C and K.
Expand Down Expand Up @@ -75,13 +73,13 @@ func newRouter[C any](

type routingItem[C any] struct {
consumer C
statementContext string
requestCondition *requestCondition
resourceStatement *ottl.Statement[ottlresource.TransformContext]
spanStatement *ottl.Statement[ottlspan.TransformContext]
metricStatement *ottl.Statement[ottlmetric.TransformContext]
dataPointStatement *ottl.Statement[ottldatapoint.TransformContext]
logStatement *ottl.Statement[ottllog.TransformContext]
statementContext string
}

func (r *router[C]) buildParsers(table []RoutingTableItem, settings component.TelemetrySettings) error {
Expand Down
4 changes: 2 additions & 2 deletions connector/routingconnector/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ func TestTracesConnectorDetailed(t *testing.T) {
isResourceBFromLowerContext := `resource.attributes["resourceName"] == "resourceB"`

testCases := []struct {
name string
cfg *Config
ctx context.Context
input ptrace.Traces
expectSink0 ptrace.Traces
expectSink1 ptrace.Traces
expectSinkD ptrace.Traces
cfg *Config
name string
}{
{
name: "request/no_request_values",
Expand Down
Loading