Skip to content

Commit

Permalink
Merge pull request open-telemetry#1 from rancher-sandbox/logr
Browse files Browse the repository at this point in the history
[chore] replace adapter logger with logr interface
  • Loading branch information
Janelle Law authored Nov 8, 2023
2 parents 56e93a9 + d10b767 commit 9f8e669
Show file tree
Hide file tree
Showing 41 changed files with 164 additions and 17 deletions.
1 change: 1 addition & 0 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down
1 change: 1 addition & 0 deletions cmd/configschema/go.sum

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

1 change: 1 addition & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down
1 change: 1 addition & 0 deletions cmd/otelcontribcol/go.sum

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

1 change: 1 addition & 0 deletions cmd/oteltestbedcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions cmd/oteltestbedcol/go.sum

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

1 change: 1 addition & 0 deletions exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ require (
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions exporter/datadogexporter/go.sum

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

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum

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

13 changes: 6 additions & 7 deletions pkg/stanza/adapter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"sync"

"github.com/cespare/xxhash/v2"
"github.com/go-logr/logr"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
)
Expand Down Expand Up @@ -71,7 +71,7 @@ type Converter struct {
// when Stop() is called.
wg sync.WaitGroup

logger *zap.Logger
logger logr.Logger
}

type converterOption interface {
Expand All @@ -90,7 +90,7 @@ func (o workerCountOption) apply(c *Converter) {
c.workerCount = o.workerCount
}

func NewConverter(logger *zap.Logger, opts ...converterOption) *Converter {
func NewConverter(logger logr.Logger, opts ...converterOption) *Converter {
c := &Converter{
workerChan: make(chan []*entry.Entry),
workerCount: int(math.Max(1, float64(runtime.NumCPU()/4))),
Expand All @@ -106,7 +106,7 @@ func NewConverter(logger *zap.Logger, opts ...converterOption) *Converter {
}

func (c *Converter) Start() {
c.logger.Debug("Starting log converter", zap.Int("worker_count", c.workerCount))
c.logger.Info("Starting log converter", "worker_count", c.workerCount)

c.wg.Add(c.workerCount)
for i := 0; i < c.workerCount; i++ {
Expand Down Expand Up @@ -186,9 +186,8 @@ func (c *Converter) flushLoop() {

case pLogs := <-c.flushChan:
if err := c.flush(ctx, pLogs); err != nil {
c.logger.Debug("Problem sending log entries",
zap.Error(err),
)
c.logger.Info("Problem sending log entries",
"error", err)
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/stanza/adapter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"testing"
"time"

"github.com/go-logr/zapr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -347,7 +348,7 @@ func TestAllConvertedEntriesAreSentAndReceived(t *testing.T) {
t.Run(strconv.Itoa(i), func(t *testing.T) {
t.Parallel()

converter := NewConverter(zap.NewNop())
converter := NewConverter(zapr.NewLogger(zap.NewNop()))
converter.Start()
defer converter.Stop()

Expand Down Expand Up @@ -409,7 +410,7 @@ func TestAllConvertedEntriesAreSentAndReceived(t *testing.T) {
}

func TestConverterCancelledContextCancellsTheFlush(t *testing.T) {
converter := NewConverter(zap.NewNop())
converter := NewConverter(zapr.NewLogger(zap.NewNop()))
converter.Start()
defer converter.Stop()
var wg sync.WaitGroup
Expand Down Expand Up @@ -822,7 +823,7 @@ func BenchmarkConverter(b *testing.B) {
b.Run(fmt.Sprintf("worker_count=%d", wc), func(b *testing.B) {
for i := 0; i < b.N; i++ {

converter := NewConverter(zap.NewNop(), withWorkerCount(wc))
converter := NewConverter(zapr.NewLogger(zap.NewNop()), withWorkerCount(wc))
converter.Start()
defer converter.Stop()

Expand Down
3 changes: 2 additions & 1 deletion pkg/stanza/adapter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package adapter // import "github.com/open-telemetry/opentelemetry-collector-con
import (
"context"

"github.com/go-logr/zapr"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/obsreport"
Expand Down Expand Up @@ -65,7 +66,7 @@ func createLogsReceiver(logReceiverType LogReceiverType) rcvr.CreateLogsFunc {
if baseCfg.numWorkers > 0 {
converterOpts = append(converterOpts, withWorkerCount(baseCfg.numWorkers))
}
converter := NewConverter(params.Logger, converterOpts...)
converter := NewConverter(zapr.NewLogger(params.Logger), converterOpts...)
obsrecv, err := obsreport.NewReceiver(obsreport.ReceiverSettings{
ReceiverID: params.ID,
ReceiverCreateSettings: params,
Expand Down
3 changes: 2 additions & 1 deletion pkg/stanza/adapter/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/go-logr/zapr"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
Expand Down Expand Up @@ -51,7 +52,7 @@ func createNoopReceiver(nextConsumer consumer.Logs) (*receiver, error) {
emitter: emitter,
consumer: nextConsumer,
logger: zap.NewNop(),
converter: NewConverter(zap.NewNop()),
converter: NewConverter(zapr.NewLogger(zap.NewNop())),
obsrecv: obsrecv,
}, nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/stanza/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require (
github.com/antonmedv/expr v1.15.0
github.com/bmatcuk/doublestar/v4 v4.6.0
github.com/cespare/xxhash/v2 v2.2.0
github.com/go-logr/logr v1.2.4
github.com/go-logr/zapr v1.2.4
github.com/influxdata/go-syslog/v3 v3.0.1-0.20210608084020-ac565dc76ba6
github.com/jpillora/backoff v1.0.0
github.com/json-iterator/go v1.1.12
Expand Down
9 changes: 9 additions & 0 deletions pkg/stanza/go.sum

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

3 changes: 1 addition & 2 deletions pkg/stanza/operator/input/windows/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import (
"sync"
"time"

"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"go.uber.org/zap"
)

const operatorType = "windows_eventlog_input"
Expand Down
2 changes: 2 additions & 0 deletions processor/logstransformprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/processor/logst
go 1.20

require (
github.com/go-logr/zapr v1.2.4
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.84.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.84.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza v0.84.0
Expand All @@ -21,6 +22,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/influxdata/go-syslog/v3 v3.0.1-0.20210608084020-ac565dc76ba6 // indirect
Expand Down
Loading

0 comments on commit 9f8e669

Please sign in to comment.