forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combined_logs.go
91 lines (73 loc) · 2.15 KB
/
combined_logs.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package mongodbatlasreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver"
import (
"context"
"fmt"
"go.opentelemetry.io/collector/component"
"go.uber.org/multierr"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter"
)
// combinedLogsReceiver wraps alerts and log receivers in a single log receiver to be consumed by the factory
type combinedLogsReceiver struct {
alerts *alertsReceiver
logs *logsReceiver
events *eventsReceiver
accessLogs *accessLogsReceiver
storageID *component.ID
id component.ID
}
// Starts up the combined MongoDB Atlas Logs and Alert Receiver
func (c *combinedLogsReceiver) Start(ctx context.Context, host component.Host) error {
var errs error
storageClient, err := adapter.GetStorageClient(ctx, host, c.storageID, c.id)
if err != nil {
return fmt.Errorf("failed to get storage client: %w", err)
}
if c.alerts != nil {
if err := c.alerts.Start(ctx, host, storageClient); err != nil {
errs = multierr.Append(errs, err)
}
}
if c.logs != nil {
if err := c.logs.Start(ctx, host); err != nil {
errs = multierr.Append(errs, err)
}
}
if c.events != nil {
if err := c.events.Start(ctx, host, storageClient); err != nil {
errs = multierr.Append(errs, err)
}
}
if c.accessLogs != nil {
if err := c.accessLogs.Start(ctx, host, storageClient); err != nil {
errs = multierr.Append(errs, err)
}
}
return errs
}
// Shutsdown the combined MongoDB Atlas Logs and Alert Receiver
func (c *combinedLogsReceiver) Shutdown(ctx context.Context) error {
var errs error
if c.alerts != nil {
if err := c.alerts.Shutdown(ctx); err != nil {
errs = multierr.Append(errs, err)
}
}
if c.logs != nil {
if err := c.logs.Shutdown(ctx); err != nil {
errs = multierr.Append(errs, err)
}
}
if c.events != nil {
if err := c.events.Shutdown(ctx); err != nil {
errs = multierr.Append(errs, err)
}
}
if c.accessLogs != nil {
if err := c.accessLogs.Shutdown(ctx); err != nil {
errs = multierr.Append(errs, err)
}
}
return errs
}