Files
akvorado/orchestrator/root.go
Vincent Bernat ac68c5970e inlet: split inlet into new inlet and outlet
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
2025-07-27 21:44:28 +02:00

70 lines
2.1 KiB
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
// Package orchestrator synchronizes the different internal services.
package orchestrator
import (
"sync"
"akvorado/common/httpserver"
"akvorado/common/reporter"
)
// Component represents the broker.
type Component struct {
r *reporter.Reporter
d *Dependencies
config Configuration
serviceLock sync.Mutex
serviceConfigurations map[ServiceType][]interface{}
}
// Dependencies define the dependencies of the broker.
type Dependencies struct {
HTTP *httpserver.Component
}
// ServiceType describes the different internal services
type ServiceType string
var (
// InletService represents the inlet service type
InletService ServiceType = "inlet"
// OutletService represents the outlet service type
OutletService ServiceType = "outlet"
// OrchestratorService represents the orchestrator service type
OrchestratorService ServiceType = "orchestrator"
// ConsoleService represents the console service type
ConsoleService ServiceType = "console"
// DemoExporterService represents the demo exporter service type
DemoExporterService ServiceType = "demo-exporter"
)
// New creates a new broker component.
func New(r *reporter.Reporter, configuration Configuration, dependencies Dependencies) (*Component, error) {
c := Component{
r: r,
d: &dependencies,
config: configuration,
serviceConfigurations: map[ServiceType][]interface{}{},
}
c.d.HTTP.GinRouter.GET("/api/v0/orchestrator/configuration/:service", c.configurationHandlerFunc)
c.d.HTTP.GinRouter.GET("/api/v0/orchestrator/configuration/:service/:index", c.configurationHandlerFunc)
return &c, nil
}
// RegisterConfiguration registers the configuration for a service.
func (c *Component) RegisterConfiguration(service ServiceType, configuration interface{}) {
c.serviceLock.Lock()
if _, ok := c.serviceConfigurations[service]; !ok {
c.serviceConfigurations[service] = []interface{}{}
}
c.serviceConfigurations[service] = append(c.serviceConfigurations[service], configuration)
c.serviceLock.Unlock()
}