|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package filelogreceiver |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "fmt" |
| 9 | + "math" |
| 10 | + "testing" |
| 11 | + "time" |
| 12 | + |
| 13 | + "github.com/stretchr/testify/require" |
| 14 | + "go.opentelemetry.io/collector/component/componenttest" |
| 15 | + "go.opentelemetry.io/collector/consumer/consumertest" |
| 16 | + "go.opentelemetry.io/collector/receiver/receivertest" |
| 17 | + |
| 18 | + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/file" |
| 19 | + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver/internal/metadata" |
| 20 | + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver/internal/testutil" |
| 21 | +) |
| 22 | + |
| 23 | +func BenchmarkReadSingleStaticFile(b *testing.B) { |
| 24 | + for n := range 6 { |
| 25 | + numLines := int(math.Pow(10, float64(n))) |
| 26 | + b.Run(fmt.Sprintf("%d-lines", numLines), func(b *testing.B) { |
| 27 | + benchmarkReadSingleStaticFile(b, numLines) |
| 28 | + }) |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +func benchmarkReadSingleStaticFile(b *testing.B, numLines int) { |
| 33 | + logFileGenerator := testutil.NewLogFileGenerator(b) |
| 34 | + logFilePath := logFileGenerator.GenerateLogFile(numLines) |
| 35 | + |
| 36 | + cfg := &FileLogConfig{ |
| 37 | + InputConfig: func() file.Config { |
| 38 | + c := file.NewConfig() |
| 39 | + c.Include = []string{logFilePath} |
| 40 | + c.PollInterval = time.Microsecond |
| 41 | + c.StartAt = "beginning" |
| 42 | + return *c |
| 43 | + }(), |
| 44 | + } |
| 45 | + sink := new(consumertest.LogsSink) |
| 46 | + f := NewFactory() |
| 47 | + |
| 48 | + b.ResetTimer() |
| 49 | + for range b.N { |
| 50 | + rcvr, err := f.CreateLogs(context.Background(), receivertest.NewNopSettings(metadata.Type), cfg, sink) |
| 51 | + require.NoError(b, err) |
| 52 | + require.NoError(b, rcvr.Start(context.Background(), componenttest.NewNopHost())) |
| 53 | + |
| 54 | + require.Eventually(b, expectNLogs(sink, numLines), 2*time.Second, 2*time.Microsecond) |
| 55 | + sink.Reset() |
| 56 | + |
| 57 | + require.NoError(b, rcvr.Shutdown(context.Background())) |
| 58 | + } |
| 59 | +} |
0 commit comments