Skip to content

Commit 64c90fa

Browse files
committed
fix multiple access logs
1 parent c83e0b9 commit 64c90fa

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

internal/collector/nginxossreceiver/internal/scraper/accesslog/nginx_log_scraper.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type (
4242
logger *zap.Logger
4343
mb *metadata.MetricsBuilder
4444
rb *metadata.ResourceBuilder
45-
pipe *pipeline.DirectedPipeline
45+
pipes []*pipeline.DirectedPipeline
4646
wg *sync.WaitGroup
4747
cancel context.CancelFunc
4848
entries []*entry.Entry
@@ -103,20 +103,27 @@ func (nls *NginxLogScraper) ID() component.ID {
103103
return component.NewID(metadata.Type)
104104
}
105105

106+
// nolint: unparam
106107
func (nls *NginxLogScraper) Start(parentCtx context.Context, _ component.Host) error {
107108
nls.logger.Info("NGINX access log scraper started")
108109
ctx, cancel := context.WithCancel(parentCtx)
109110
nls.cancel = cancel
110111

111-
var err error
112-
nls.pipe, err = nls.initStanzaPipeline(nls.operators, nls.logger)
113-
if err != nil {
114-
return fmt.Errorf("init stanza pipeline: %w", err)
112+
for _, op := range nls.operators {
113+
nls.logger.Info("Initializing NGINX access log scraper pipeline", zap.Any("operator_id", op.ID()))
114+
pipe, err := nls.initStanzaPipeline([]operator.Config{op}, nls.logger)
115+
if err != nil {
116+
nls.logger.Error("Error initializing pipeline", zap.Any("id", op.ID()), zap.Any("error", err))
117+
continue
118+
}
119+
nls.pipes = append(nls.pipes, pipe)
115120
}
116121

117-
startError := nls.pipe.Start(storage.NewNopClient())
118-
if startError != nil {
119-
return fmt.Errorf("stanza pipeline start: %w", startError)
122+
for _, pipe := range nls.pipes {
123+
startError := pipe.Start(storage.NewNopClient())
124+
if startError != nil {
125+
nls.logger.Error("Error starting pipeline", zap.Any("error", startError))
126+
}
120127
}
121128

122129
nls.wg.Add(1)
@@ -206,7 +213,12 @@ func (nls *NginxLogScraper) Shutdown(_ context.Context) error {
206213
}
207214
nls.wg.Wait()
208215

209-
return nls.pipe.Stop()
216+
var err error
217+
for _, pipe := range nls.pipes {
218+
err = pipe.Stop()
219+
}
220+
221+
return err
210222
}
211223

212224
func (nls *NginxLogScraper) initStanzaPipeline(

internal/collector/nginxossreceiver/internal/scraper/accesslog/nginx_log_scraper_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@ func TestAccessLogScraper(t *testing.T) {
8282
pmetrictest.IgnoreResourceAttributeValue("instance.id")))
8383
}
8484

85-
func TestAccessLogScraperError(t *testing.T) {
86-
t.Run("include config missing", func(tt *testing.T) {
87-
logScraper := NewScraper(receivertest.NewNopSettings(component.Type{}), &config.Config{})
88-
err := logScraper.Start(context.Background(), componenttest.NewNopHost())
89-
require.Error(tt, err)
90-
assert.Contains(tt, err.Error(), "init stanza pipeline")
91-
})
92-
}
93-
9485
// Copies the contents of one file to another with the given delay. Used to simulate writing log entries to a log file.
9586
// Reason for nolint: we must use testify's assert instead of require,
9687
// for more info see https://github.com/stretchr/testify/issues/772#issuecomment-945166599

0 commit comments

Comments
 (0)