Skip to content

Commit

Permalink
Merge branch 'main' into datadog-receiver/add-span-obfuscator
Browse files Browse the repository at this point in the history
  • Loading branch information
lopes-felipe authored Oct 14, 2024
2 parents e27f118 + d20c3f8 commit da45a8b
Show file tree
Hide file tree
Showing 27 changed files with 88 additions and 159 deletions.
27 changes: 27 additions & 0 deletions .chloggen/lkwronski.issue-29441-slice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/ottl

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow indexing string slice type

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [29441]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
2 changes: 1 addition & 1 deletion exporter/awss3exporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/otelcol/otelcoltest v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
Expand Down Expand Up @@ -80,6 +79,7 @@ require (
go.opentelemetry.io/collector/otelcol v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pdata/testdata v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/processor v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/processor/processorprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae // indirect
Expand Down
17 changes: 0 additions & 17 deletions exporter/awss3exporter/marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/pipeline"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -51,28 +50,12 @@ type hostWithExtensions struct {
encoding encodingExtension
}

func (h hostWithExtensions) Start(context.Context, component.Host) error {
panic("unsupported")
}

func (h hostWithExtensions) Shutdown(context.Context) error {
panic("unsupported")
}

func (h hostWithExtensions) GetFactory(component.Kind, component.Type) component.Factory {
panic("unsupported")
}

func (h hostWithExtensions) GetExtensions() map[component.ID]component.Component {
return map[component.ID]component.Component{
component.MustNewID("foo"): h.encoding,
}
}

func (h hostWithExtensions) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component {
panic("unsupported")
}

type encodingExtension struct {
}

Expand Down
9 changes: 0 additions & 9 deletions exporter/elasticsearchexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pipeline"
)

func TestExporterLogs(t *testing.T) {
Expand Down Expand Up @@ -1600,18 +1599,10 @@ type mockHost struct {
extensions map[component.ID]component.Component
}

func (h *mockHost) GetFactory(kind component.Kind, typ component.Type) component.Factory {
panic(fmt.Errorf("expected call to GetFactory(%v, %v)", kind, typ))
}

func (h *mockHost) GetExtensions() map[component.ID]component.Component {
return h.extensions
}

func (h *mockHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component {
panic(fmt.Errorf("expected call to GetExporters"))
}

type roundTripperFunc func(*http.Request) (*http.Response, error)

func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
Expand Down
2 changes: 1 addition & 1 deletion exporter/elasticsearchexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ require (
go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/extension/auth v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/semconv v0.111.1-0.20241008154146-ea48c09c31ae
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
Expand Down Expand Up @@ -74,6 +73,7 @@ require (
go.opentelemetry.io/collector/extension/experimental/storage v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
Expand Down
9 changes: 0 additions & 9 deletions exporter/fileexporter/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pipeline"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/otlpencodingextension"
)
Expand All @@ -28,18 +27,10 @@ type hostWithEncoding struct {
encodings map[component.ID]component.Component
}

func (h hostWithEncoding) GetFactory(_ component.Kind, _ component.Type) component.Factory {
panic("unsupported")
}

func (h hostWithEncoding) GetExtensions() map[component.ID]component.Component {
return h.encodings
}

func (h hostWithEncoding) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component {
panic("unsupported")
}

func TestEncoding(t *testing.T) {
f := NewFactory()
cfg := f.CreateDefaultConfig().(*Config)
Expand Down
2 changes: 1 addition & 1 deletion exporter/fileexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/extension v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
Expand Down Expand Up @@ -48,6 +47,7 @@ require (
go.opentelemetry.io/collector/extension/experimental/storage v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion exporter/rabbitmqexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
go.opentelemetry.io/collector/consumer v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/exporter v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
)
Expand Down Expand Up @@ -81,6 +80,7 @@ require (
go.opentelemetry.io/collector/extension/experimental/storage v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/receiver v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
Expand Down
9 changes: 0 additions & 9 deletions exporter/rabbitmqexporter/marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pipeline"
)

func TestMarshalUsingEncodingExtension(t *testing.T) {
Expand All @@ -40,14 +39,6 @@ type mockEncodingExtension struct {
mock.Mock
}

func (h *mockHostWithEncodings) GetFactory(component.Kind, component.Type) component.Factory {
return nil
}

func (h *mockHostWithEncodings) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component {
return nil
}

func (h *mockHostWithEncodings) GetExtensions() map[component.ID]component.Component {
args := h.Called()
return args.Get(0).(map[component.ID]component.Component)
Expand Down
9 changes: 0 additions & 9 deletions extension/awsproxy/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/extension/extensiontest"
"go.opentelemetry.io/collector/pipeline"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/proxy"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
Expand Down Expand Up @@ -101,18 +100,10 @@ type nopHost struct {
reportFunc func(event *componentstatus.Event)
}

func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory {
return nil
}

func (nh *nopHost) GetExtensions() map[component.ID]component.Component {
return nil
}

func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component {
return nil
}

func (nh *nopHost) Report(event *componentstatus.Event) {
nh.reportFunc(event)
}
2 changes: 1 addition & 1 deletion extension/awsproxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
go.opentelemetry.io/collector/config/configtls v1.17.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/confmap v1.17.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/extension v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae
go.uber.org/zap v1.27.0
)

Expand All @@ -38,6 +37,7 @@ require (
go.opentelemetry.io/collector/featuregate v1.17.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
Expand Down
9 changes: 0 additions & 9 deletions extension/observer/ecsobserver/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"go.opentelemetry.io/collector/component/componentstatus"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/extension/extensiontest"
"go.opentelemetry.io/collector/pipeline"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/ecsobserver/internal/ecsmock"
Expand Down Expand Up @@ -82,18 +81,10 @@ type nopHost struct {
reportFunc func(event *componentstatus.Event)
}

func (nh *nopHost) GetFactory(component.Kind, component.Type) component.Factory {
return nil
}

func (nh *nopHost) GetExtensions() map[component.ID]component.Component {
return nil
}

func (nh *nopHost) GetExportersWithSignal() map[pipeline.Signal]map[component.ID]component.Component {
return nil
}

func (nh *nopHost) Report(event *componentstatus.Event) {
nh.reportFunc(event)
}
2 changes: 1 addition & 1 deletion extension/observer/ecsobserver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
go.opentelemetry.io/collector/component/componentstatus v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/confmap v1.17.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/extension v0.111.1-0.20241008154146-ea48c09c31ae
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
Expand All @@ -34,6 +33,7 @@ require (
go.opentelemetry.io/collector/config/configtelemetry v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions pkg/ottl/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,13 @@ func Test_e2e_ottl_features(t *testing.T) {
tCtx.GetLogRecord().Attributes().PutBool("isMap", true)
},
},
{
name: "extract value from Split function result slice of type []string",
statement: `set(attributes["my.environment.2"], Split(resource.attributes["host.name"],"h")[1])`,
want: func(tCtx ottllog.TransformContext) {
tCtx.GetLogRecord().Attributes().PutStr("my.environment.2", "ost")
},
},
}

for _, tt := range tests {
Expand Down
18 changes: 15 additions & 3 deletions pkg/ottl/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,15 @@ func (g exprGetter[K]) Get(ctx context.Context, tCtx K) (any, error) {
}
result = ottlcommon.GetValue(r.At(int(*k.Int)))
case []any:
if int(*k.Int) >= len(r) || int(*k.Int) < 0 {
return nil, fmt.Errorf("index %v out of bounds", *k.Int)
result, err = getElementByIndex(r, k.Int)
if err != nil {
return nil, err
}
case []string:
result, err = getElementByIndex(r, k.Int)
if err != nil {
return nil, err
}
result = r[*k.Int]
default:
return nil, fmt.Errorf("type, %T, does not support int indexing", result)
}
Expand All @@ -125,6 +130,13 @@ func (g exprGetter[K]) Get(ctx context.Context, tCtx K) (any, error) {
return result, nil
}

func getElementByIndex[T any](r []T, idx *int64) (any, error) {
if int(*idx) >= len(r) || int(*idx) < 0 {
return nil, fmt.Errorf("index %v out of bounds", *idx)
}
return r[*idx], nil
}

type listGetter[K any] struct {
slice []Getter[K]
}
Expand Down
30 changes: 30 additions & 0 deletions pkg/ottl/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func basicSlice() (ExprFunc[any], error) {
}, nil
}

func basicSliceString() (ExprFunc[any], error) {
return func(_ context.Context, _ any) (any, error) {
return []any{
[]string{
"pass",
},
}, nil
}, nil
}

func Test_newGetter(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -237,6 +247,25 @@ func Test_newGetter(t *testing.T) {
},
want: "pass",
},
{
name: "function call nested SliceString",
val: value{
Literal: &mathExprLiteral{
Converter: &converter{
Function: "SliceString",
Keys: []key{
{
Int: ottltest.Intp(0),
},
{
Int: ottltest.Intp(0),
},
},
},
},
},
want: "pass",
},
{
name: "enum",
val: value{
Expand Down Expand Up @@ -532,6 +561,7 @@ func Test_newGetter(t *testing.T) {
createFactory("Map", &struct{}{}, basicMap),
createFactory("PSlice", &struct{}{}, pslice),
createFactory("Slice", &struct{}{}, basicSlice),
createFactory("SliceString", &struct{}{}, basicSliceString),
)

p, _ := NewParser[any](
Expand Down
Loading

0 comments on commit da45a8b

Please sign in to comment.