mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
This change split the inlet component into a simpler inlet and a new outlet component. The new inlet component receive flows and put them in Kafka, unparsed. The outlet component takes them from Kafka and resume the processing from here (flow parsing, enrichment) and puts them in ClickHouse. The main goal is to ensure the inlet does a minimal work to not be late when processing packets (and restart faster). It also brings some simplification as the number of knobs to tune everything is reduced: for inlet, we only need to tune the queue size for UDP, the number of workers and a few Kafka parameters; for outlet, we need to tune a few Kafka parameters, the number of workers and a few ClickHouse parameters. The outlet component features a simple Kafka input component. The core component becomes just a callback function. There is also a new ClickHouse component to push data to ClickHouse using the low-level ch-go library with batch inserts. This processing has an impact on the internal representation of a FlowMessage. Previously, it was tailored to dynamically build the protobuf message to be put in Kafka. Now, it builds the batch request to be sent to ClickHouse. This makes the FlowMessage structure hides the content of the next batch request and therefore, it should be reused. This also changes the way we decode flows as they don't output FlowMessage anymore, they reuse one that is provided to each worker. The ClickHouse tables are slightly updated. Instead of using Kafka engine, the Null engine is used instead. Fix #1122
79 lines
1.9 KiB
Go
79 lines
1.9 KiB
Go
// SPDX-FileCopyrightText: 2024 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
// Package pb contains the definition of RawFlow, the protobuf-based
|
|
// structure to exchange flows between the inlet and the outlet.
|
|
package pb
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"akvorado/common/helpers/bimap"
|
|
)
|
|
|
|
// Version is the version of the schema. On incompatible changes, this should be
|
|
// bumped.
|
|
var Version = 5
|
|
|
|
var decoderMap = bimap.New(map[RawFlow_Decoder]string{
|
|
RawFlow_DECODER_NETFLOW: "netflow",
|
|
RawFlow_DECODER_SFLOW: "sflow",
|
|
})
|
|
|
|
// MarshalText turns a decoder to text
|
|
func (d RawFlow_Decoder) MarshalText() ([]byte, error) {
|
|
got, ok := decoderMap.LoadValue(d)
|
|
if ok {
|
|
return []byte(got), nil
|
|
}
|
|
return nil, errors.New("unknown decoder")
|
|
}
|
|
|
|
// UnmarshalText provides a decoder from text
|
|
func (d *RawFlow_Decoder) UnmarshalText(input []byte) error {
|
|
if len(input) == 0 {
|
|
*d = RawFlow_DECODER_UNSPECIFIED
|
|
return nil
|
|
}
|
|
got, ok := decoderMap.LoadKey(string(input))
|
|
if ok {
|
|
*d = got
|
|
return nil
|
|
}
|
|
return errors.New("unknown decoder")
|
|
}
|
|
|
|
var tsMap = bimap.New(map[RawFlow_TimestampSource]string{
|
|
RawFlow_TS_INPUT: "input", // this is the default value
|
|
RawFlow_TS_NETFLOW_FIRST_SWITCHED: "netflow-first-switched",
|
|
RawFlow_TS_NETFLOW_PACKET: "netflow-packet",
|
|
})
|
|
|
|
// MarshalText turns a timestamp source to text
|
|
func (ts RawFlow_TimestampSource) MarshalText() ([]byte, error) {
|
|
got, ok := tsMap.LoadValue(ts)
|
|
if ok {
|
|
return []byte(got), nil
|
|
}
|
|
return nil, errors.New("unknown timestamp source")
|
|
}
|
|
|
|
// UnmarshalText provides a timestamp source from text
|
|
func (ts *RawFlow_TimestampSource) UnmarshalText(input []byte) error {
|
|
if len(input) == 0 {
|
|
*ts = RawFlow_TS_INPUT
|
|
return nil
|
|
}
|
|
if string(input) == "udp" {
|
|
*ts = RawFlow_TS_INPUT
|
|
return nil
|
|
}
|
|
got, ok := tsMap.LoadKey(string(input))
|
|
if ok {
|
|
*ts = got
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown timestamp source %q", string(input))
|
|
}
|