-
Notifications
You must be signed in to change notification settings - Fork 24
/
exporter.go
56 lines (44 loc) · 1.35 KB
/
exporter.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
package alertsexporter
import (
"context"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
"github.com/fluxninja/aperture/v2/pkg/alerts"
"github.com/fluxninja/aperture/v2/pkg/log"
)
type alertsExporter struct {
cfg *Config
}
func newExporter(cfg *Config) (*alertsExporter, error) {
ex := &alertsExporter{
cfg: cfg,
}
return ex, nil
}
// Start implements the Component interface.
func (ex *alertsExporter) Start(_ context.Context, _ component.Host) error {
return nil
}
// Shutdown implements the Component interface.
func (ex *alertsExporter) Shutdown(_ context.Context) error {
return nil
}
// Capabilities returns the capabilities of the exporter.
func (ex *alertsExporter) Capabilities() consumer.Capabilities {
return consumer.Capabilities{
MutatesData: false,
}
}
// ConsumeLogs sends alert from logs to alert manager clients.
func (ex *alertsExporter) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
alerts := alerts.AlertsFromLogs(ld)
for _, amClient := range ex.cfg.alertMgr.Clients {
log.Trace().Int("alerts", ld.LogRecordCount()).Str("client", amClient.GetName()).Msg("Exporting alerts")
err := amClient.SendAlerts(ctx, alerts)
if err != nil {
log.Warn().Err(err).Msgf("could not send alerts for client: %+v", amClient.GetName())
}
}
return nil
}