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

Merge remote main to prod #4527

Merged
merged 6 commits into from
Sep 13, 2023
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
30 changes: 30 additions & 0 deletions .chloggen/pkg-stanza-extract-trim-split.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use this changelog template to create an entry for release notes.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Make trim func composable

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

# (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: |
- Adds trim.WithFunc to allow trim funcs to wrap bufio.SplitFuncs.
- Removes trim.Func from split.Config.Func. Use trim.WithFunc instead.
- Removes trim.Func from flush.WithPeriod. Use trim.WithFunc instead.

# 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: [api]
20 changes: 20 additions & 0 deletions .chloggen/splunkent-client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "adding component logic to splunkenterprise receiver"

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

# (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:
2 changes: 1 addition & 1 deletion cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aliyun/aliyun-log-go-sdk v0.1.54 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/antonmedv/expr v1.15.1 // indirect
github.com/antonmedv/expr v1.15.2 // indirect
github.com/apache/arrow/go/v12 v12.0.1 // indirect
github.com/apache/pulsar-client-go v0.8.1 // indirect
github.com/apache/pulsar-client-go/oauth2 v0.0.0-20220120090717-25e59572242e // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aliyun/aliyun-log-go-sdk v0.1.54 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/antonmedv/expr v1.15.1 // indirect
github.com/antonmedv/expr v1.15.2 // indirect
github.com/apache/arrow/go/v12 v12.0.1 // indirect
github.com/apache/pulsar-client-go v0.8.1 // indirect
github.com/apache/pulsar-client-go/oauth2 v0.0.0-20220120090717-25e59572242e // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/oteltestbedcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/alecthomas/participle/v2 v2.1.0 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/antonmedv/expr v1.15.1 // indirect
github.com/antonmedv/expr v1.15.2 // indirect
github.com/apache/thrift v0.19.0 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.45.7 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/oteltestbedcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/demo/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
OTELCOL_IMG=otel/opentelemetry-collector:0.67.0
OTELCOL_IMG=otel/opentelemetry-collector:0.85.0
OTELCOL_ARGS=
2 changes: 1 addition & 1 deletion examples/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This demo uses `docker-compose` and by default runs against the
to the `examples/demo` folder and run:

```shell
docker-compose up -d
docker compose up -d
```

The demo exposes the following backends:
Expand Down
6 changes: 3 additions & 3 deletions examples/demo/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ exporters:
endpoint: "http://zipkin-all-in-one:9411/api/v2/spans"
format: proto

jaeger:
endpoint: jaeger-all-in-one:14250
otlp:
endpoint: jaeger-all-in-one:4317
tls:
insecure: true

Expand All @@ -36,7 +36,7 @@ service:
traces:
receivers: [otlp]
processors: [batch]
exporters: [logging, zipkin, jaeger]
exporters: [logging, zipkin, otlp]
metrics:
receivers: [otlp]
processors: [batch]
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Showmax/go-fqdn v1.0.0 // indirect
github.com/antonmedv/expr v1.15.1 // indirect
github.com/antonmedv/expr v1.15.2 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions exporter/datadogexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aliyun/aliyun-log-go-sdk v0.1.54 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/antonmedv/expr v1.15.1 // indirect
github.com/antonmedv/expr v1.15.2 // indirect
github.com/apache/arrow/go/v12 v12.0.1 // indirect
github.com/apache/pulsar-client-go v0.8.1 // indirect
github.com/apache/pulsar-client-go/oauth2 v0.0.0-20220120090717-25e59572242e // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/filter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter
go 1.20

require (
github.com/antonmedv/expr v1.15.1
github.com/antonmedv/expr v1.15.2
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.85.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.85.0
Expand Down
4 changes: 2 additions & 2 deletions internal/filter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/stanza/fileconsumer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c Config) BuildWithSplitFunc(logger *zap.SugaredLogger, emit emit.Callback
}

// Ensure that splitter is buildable
factory := splitter.NewCustomFactory(splitFunc, c.FlushPeriod)
factory := splitter.NewCustomFactory(splitFunc, c.TrimConfig.Func(), c.FlushPeriod)
if _, err := factory.SplitFunc(); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/fileconsumer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (m *Manager) poll(ctx context.Context) {
// Get the list of paths on disk
matches, err := m.fileMatcher.MatchFiles()
if err != nil {
m.Warnf("finding files: %v", err)
m.Infof("finding files: %v", err)
}

for len(matches) > m.maxBatchFiles {
Expand Down
10 changes: 7 additions & 3 deletions pkg/stanza/fileconsumer/internal/header/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/pipeline"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/split"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/trim"
)

type Config struct {
Expand Down Expand Up @@ -69,13 +70,16 @@ func NewConfig(matchRegex string, metadataOperators []operator.Config, enc encod
return nil, fmt.Errorf("failed to compile `pattern`: %w", err)
}

splitFunc, err := split.NewlineSplitFunc(enc, false, func(b []byte) []byte {
return bytes.Trim(b, "\r\n")
})
splitFunc, err := split.NewlineSplitFunc(enc, false)
if err != nil {
return nil, fmt.Errorf("failed to create split func: %w", err)
}

var trimFunc trim.Func = func(b []byte) []byte {
return bytes.Trim(b, "\r\n")
}
splitFunc = trim.WithFunc(splitFunc, trimFunc)

return &Config{
regex: regex,
SplitFunc: splitFunc,
Expand Down
6 changes: 4 additions & 2 deletions pkg/stanza/fileconsumer/internal/splitter/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ import (

type customFactory struct {
splitFunc bufio.SplitFunc
trimFunc trim.Func
flushPeriod time.Duration
}

var _ Factory = (*customFactory)(nil)

func NewCustomFactory(splitFunc bufio.SplitFunc, flushPeriod time.Duration) Factory {
func NewCustomFactory(splitFunc bufio.SplitFunc, trimFunc trim.Func, flushPeriod time.Duration) Factory {
return &customFactory{
splitFunc: splitFunc,
trimFunc: trimFunc,
flushPeriod: flushPeriod,
}
}

// SplitFunc builds a bufio.SplitFunc based on the configuration
func (f *customFactory) SplitFunc() (bufio.SplitFunc, error) {
return flush.WithPeriod(f.splitFunc, trim.Nop, f.flushPeriod), nil
return trim.WithFunc(flush.WithPeriod(f.splitFunc, f.flushPeriod), f.trimFunc), nil
}
62 changes: 60 additions & 2 deletions pkg/stanza/fileconsumer/internal/splitter/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"time"

"github.com/stretchr/testify/assert"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/trim"
)

func TestCustom(t *testing.T) {
factory := NewCustomFactory(bufio.ScanLines, 0)
factory := NewCustomFactory(bufio.ScanLines, trim.Nop, 0)
splitFunc, err := factory.SplitFunc()
assert.NoError(t, err)
assert.NotNil(t, splitFunc)
Expand All @@ -35,9 +37,33 @@ func TestCustom(t *testing.T) {
assert.Nil(t, token)
}

func TestCustomWithTrim(t *testing.T) {
factory := NewCustomFactory(bufio.ScanLines, trim.Whitespace, 0)
splitFunc, err := factory.SplitFunc()
assert.NoError(t, err)
assert.NotNil(t, splitFunc)

input := []byte(" hello \n world \n extra ")

advance, token, err := splitFunc(input, false)
assert.NoError(t, err)
assert.Equal(t, 8, advance)
assert.Equal(t, []byte("hello"), token)

advance, token, err = splitFunc(input[8:], false)
assert.NoError(t, err)
assert.Equal(t, 8, advance)
assert.Equal(t, []byte("world"), token)

advance, token, err = splitFunc(input[16:], false)
assert.NoError(t, err)
assert.Equal(t, 0, advance)
assert.Nil(t, token)
}

func TestCustomWithFlush(t *testing.T) {
flushPeriod := 100 * time.Millisecond
factory := NewCustomFactory(bufio.ScanLines, flushPeriod)
factory := NewCustomFactory(bufio.ScanLines, trim.Nop, flushPeriod)
splitFunc, err := factory.SplitFunc()
assert.NoError(t, err)
assert.NotNil(t, splitFunc)
Expand Down Expand Up @@ -66,3 +92,35 @@ func TestCustomWithFlush(t *testing.T) {
assert.Equal(t, 7, advance)
assert.Equal(t, []byte(" extra "), token)
}

func TestCustomWithFlushTrim(t *testing.T) {
flushPeriod := 100 * time.Millisecond
factory := NewCustomFactory(bufio.ScanLines, trim.Whitespace, flushPeriod)
splitFunc, err := factory.SplitFunc()
assert.NoError(t, err)
assert.NotNil(t, splitFunc)

input := []byte(" hello \n world \n extra ")

advance, token, err := splitFunc(input, false)
assert.NoError(t, err)
assert.Equal(t, 8, advance)
assert.Equal(t, []byte("hello"), token)

advance, token, err = splitFunc(input[8:], false)
assert.NoError(t, err)
assert.Equal(t, 8, advance)
assert.Equal(t, []byte("world"), token)

advance, token, err = splitFunc(input[16:], false)
assert.NoError(t, err)
assert.Equal(t, 0, advance)
assert.Nil(t, token)

time.Sleep(2 * flushPeriod)

advance, token, err = splitFunc(input[16:], false)
assert.NoError(t, err)
assert.Equal(t, 7, advance)
assert.Equal(t, []byte("extra"), token) // Ensure trim applies to flushed token
}
9 changes: 7 additions & 2 deletions pkg/stanza/fileconsumer/internal/splitter/multiline.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ func NewSplitFuncFactory(

// SplitFunc builds a bufio.SplitFunc based on the configuration
func (f *splitFuncFactory) SplitFunc() (bufio.SplitFunc, error) {
splitFunc, err := f.splitConfig.Func(f.encoding, false, f.maxLogSize, f.trimFunc)
splitFunc, err := f.splitConfig.Func(f.encoding, false, f.maxLogSize)
if err != nil {
return nil, err
}
return flush.WithPeriod(splitFunc, f.trimFunc, f.flushPeriod), nil
splitFunc = flush.WithPeriod(splitFunc, f.flushPeriod)
if f.encoding == encoding.Nop {
// Special case where we should never trim
return splitFunc, nil
}
return trim.WithFunc(splitFunc, f.trimFunc), nil
}
Loading