-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
receiver.go
76 lines (60 loc) · 2.16 KB
/
receiver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package adapter // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter"
import (
"context"
"fmt"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/extension/experimental/storage"
rcvr "go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.uber.org/multierr"
"go.uber.org/zap"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/pipeline"
)
type receiver struct {
set component.TelemetrySettings
id component.ID
pipe pipeline.Pipeline
emitter *helper.LogEmitter
consumer consumer.Logs
obsrecv *receiverhelper.ObsReport
storageID *component.ID
storageClient storage.Client
}
// Ensure this receiver adheres to required interface
var _ rcvr.Logs = (*receiver)(nil)
// Start tells the receiver to start
func (r *receiver) Start(ctx context.Context, host component.Host) error {
r.set.Logger.Info("Starting stanza receiver")
if err := r.setStorageClient(ctx, host); err != nil {
return fmt.Errorf("storage client: %w", err)
}
if err := r.pipe.Start(r.storageClient); err != nil {
return fmt.Errorf("start stanza: %w", err)
}
return nil
}
func (r *receiver) consumeEntries(ctx context.Context, entries []*entry.Entry) {
obsrecvCtx := r.obsrecv.StartLogsOp(ctx)
pLogs := ConvertEntries(entries)
logRecordCount := pLogs.LogRecordCount()
cErr := r.consumer.ConsumeLogs(ctx, pLogs)
if cErr != nil {
r.set.Logger.Error("ConsumeLogs() failed", zap.Error(cErr))
}
r.obsrecv.EndLogsOp(obsrecvCtx, "stanza", logRecordCount, cErr)
}
// Shutdown is invoked during service shutdown
func (r *receiver) Shutdown(ctx context.Context) error {
r.set.Logger.Info("Stopping stanza receiver")
pipelineErr := r.pipe.Stop()
if r.storageClient != nil {
clientErr := r.storageClient.Close(ctx)
return multierr.Combine(pipelineErr, clientErr)
}
return pipelineErr
}