-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
formatdriver.go
57 lines (48 loc) · 1.66 KB
/
formatdriver.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2022-present Datadog, Inc.
package goflowlib
import (
"context"
"fmt"
"go.uber.org/atomic"
"github.com/DataDog/datadog-agent/comp/netflow/common"
flowpb "github.com/netsampler/goflow2/pb"
)
// AggregatorFormatDriver is used as goflow formatter to forward flow data to aggregator/EP Forwarder
type AggregatorFormatDriver struct {
namespace string
flowAggIn chan *common.Flow
listenerFlowCount *atomic.Int64
}
// NewAggregatorFormatDriver returns a new AggregatorFormatDriver
func NewAggregatorFormatDriver(flowAgg chan *common.Flow, namespace string, listenerFlowCount *atomic.Int64) *AggregatorFormatDriver {
return &AggregatorFormatDriver{
namespace: namespace,
flowAggIn: flowAgg,
listenerFlowCount: listenerFlowCount,
}
}
// Prepare desc
func (d *AggregatorFormatDriver) Prepare() error {
return nil
}
// Init desc
func (d *AggregatorFormatDriver) Init(context.Context) error {
return nil
}
// Format desc
func (d *AggregatorFormatDriver) Format(data interface{}) ([]byte, []byte, error) {
switch flow := data.(type) {
case *flowpb.FlowMessage:
d.listenerFlowCount.Add(1)
d.flowAggIn <- ConvertFlow(flow, d.namespace)
case *common.FlowMessageWithAdditionalFields:
d.listenerFlowCount.Add(1)
d.flowAggIn <- ConvertFlowWithAdditionalFields(flow, d.namespace)
default:
return nil, nil, fmt.Errorf("message is not flowpb.FlowMessage or common.FlowMessageWithAdditionalFields")
}
return nil, nil, nil
}