256 Commits

Author SHA1 Message Date
rastsislau-matusevich
f2dfe55d27 orchestrator: add manage-topic flag and document skip-migrations (#2109)
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
2025-11-20 22:58:41 +01:00
Vincent Bernat
abca5e983d chore: modernize some code 2025-11-14 23:22:02 +01:00
Vincent Bernat
beb9a3f0ba build: add even more linting rules
Notably, shorten function signatures by not repeating types.
2025-11-12 22:43:12 +01:00
Vincent Bernat
217c484061 common/helpers: rename PrefixTo16 to PrefixTo6
Move it to common/helpers/ipv6.go and use it where needed.
2025-11-04 08:05:30 +01:00
Vincent Bernat
ee6e197e8e chore: switch to math/rand/v2 2025-10-26 12:14:20 +01:00
Vincent Bernat
589a79972b orchestrator/kafka: bump kadm to 1.17.1
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
And revert usage of ForceMetadataRefresh(), not needed anymore.
2025-10-22 20:43:44 +02:00
Vincent Bernat
4390c89c52 orchestrator/kafka: force metadata refresh during tests
New versions of kadm cache metadata by default. Ask a refresh to avoid
that.
2025-10-22 20:43:44 +02:00
Vincent Bernat
1cc33d4cc3 outlet/routing: fix lookup benchmark
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
The lookup benchmark was incorrect. When looking up a large number of
prefixes on each loop, b.Loop() calibrate on a larger and less precise
value than if it were measuring only one lookup where it would iterate
more to get a precise timing.

The problem may also exist for the insertion benchmark, but it's
difficult to do only one insertion per loop, as after many iterations,
there is nothing more we can insert. I suppose BART's author is not
trying to benchmark insertions because of this.

See https://github.com/akvorado/akvorado/pull/2040 and
https://github.com/gaissmai/bart/issues/351#issuecomment-3428806758.
2025-10-21 22:28:56 +02:00
Vincent Bernat
0f72ffd676 cmd: automatic restart of orchestrator on configuration change 2025-09-19 21:53:01 +02:00
Vincent Bernat
3807e2ac1e docker: update Kafka and Loki 2025-09-06 21:33:58 +02:00
Vincent Bernat
b1d6382585 common/embed: replace all go:embed use by an embedded archive
Some of the files were quite big:

- asns.csv ~ 3 MB
- index.js ~ 1.5 MB
- *.svg ~ 2 MB

Use a ZIP archive to put them all and embed it. This reduce the binary
size from 89 MB to 82 MB. 🤯

This also pulls some code modernization (use of http.ServeFileFS).
2025-09-03 00:00:05 +02:00
Vincent Bernat
413f923dcc docker: update ClickHouse to 25.8 2025-08-30 23:46:17 +02:00
Vincent Bernat
e2f1df9add tests: replace godebug by go-cmp for structure diffs
go-cmp is stricter and allow to catch more problems. Moreover, the
output is a bit nicer.
2025-08-23 16:03:09 +02:00
Vincent Bernat
59215899fc common/reporter: when running benchmarks, set log level to warning 2025-08-17 11:06:07 +02:00
Vincent Bernat
f7cc5e3dbc orchestrator/clickhouse: add a benchmark for networks.csv
```
goos: linux
goarch: amd64
pkg: akvorado/orchestrator/clickhouse
cpu: AMD Ryzen 5 5600X 6-Core Processor
BenchmarkNetworks-12                 482                 2.447 ms/op
```
2025-08-17 11:05:58 +02:00
Vincent Bernat
f974d5591a orchestrator/clickhouse: run some tests without a ClickHouse database
Some tests don't rely on the ClickHouse database at all. Allow them to
run without it.
2025-08-17 10:42:10 +02:00
Vincent Bernat
6b2af58a64 orchestrator/geoip: add a benchmark for Iterate*Databases()
Now:

```
goos: linux
goarch: amd64
pkg: akvorado/orchestrator/geoip
cpu: AMD Ryzen 7 PRO 6850U with Radeon Graphics
BenchmarkIterDatabase/ASN-16                3376               457.0 ns/entry
BenchmarkIterDatabase/GeoIP-16              2410               754.5 ns/entry
```

Before 0a10764cc9:

```
goos: linux
goarch: amd64
pkg: akvorado/orchestrator/geoip
cpu: AMD Ryzen 7 PRO 6850U with Radeon Graphics
BenchmarkIterDatabase/ASN-16                2863               609.3 ns/entry
BenchmarkIterDatabase/GeoIP-16              3286               719.3 ns/entry
```

I was hoping for a bit more!
2025-08-17 08:48:25 +02:00
kornix
2c8161e946 orchestrator/clickhouse: fix name for ICMP type 0, code 0
Name field updated for ICMP type 0, code 0 message

Fix #1892
2025-08-17 08:11:55 +02:00
Vincent Bernat
6118bb7aac common/helpers: convert SubnetMap to github.com/gaissmai/bart
I did not benchmark it myself, but it was benchmarked here:
 https://github.com/osrg/gobgp/issues/1414#issuecomment-3067255941

Of course, no guarantee that this benchmark matches our use cases.
Moreover, SubnetMap have been optimized to avoid parsing keys all
the time.

Also, the interface is a bit nicer and it uses netip.Prefix directly.

The next step is to convert outlet/routing/provider/bmp.
2025-08-16 09:38:44 +02:00
Vincent Bernat
98eb1bdba5 chore: make a run of gofumpt 2025-08-05 06:21:34 +02:00
Vincent Bernat
03b947e3c5 chore: fix many staticcheck warnings
The most important ones were fixed in the two previous commit.
2025-08-02 20:54:49 +02:00
Vincent Bernat
4f68271eea orchestrator/clickhouse: fix GeoIP-related tests 2025-08-02 18:06:38 +02:00
Vincent Bernat
1ce6fb4163 orchestrator: switch to UnmarshalMaxmindDB for geoip parsing
This should be more performant than introspection. Add more test
databases as well.
2025-08-02 16:42:19 +02:00
Vincent Bernat
0a10764cc9 orchestrator: switch to github.com/oschwald/maxminddb-golang/v2
Also, remove the AS name, this is not used at all.
2025-08-02 15:56:54 +02:00
Vincent Bernat
f5ae97e30d orchestrator/clickhouse: guess IP by connecting to port 80
It seems MacOS does not like to connect to port 0 (even if this is not
really a connection).
2025-07-30 08:36:12 +02:00
Vincent Bernat
a70029a4cd orchestrator/clickhouse: also guess the port when guessing HTTP URL 2025-07-30 08:11:28 +02:00
Vincent Bernat
19d07d350c common/remotedatasource: add a Stop() method
This is cleaner this way. We can't use it for the static provider as we
cannot stop a provider.
2025-07-29 08:36:16 +02:00
Vincent Bernat
5e669db4b3 chore: use errors.New() instead of fmt.Errorf() 2025-07-29 07:42:49 +02:00
Vincent Bernat
18beb310ee chore: replace interface{} with any 2025-07-29 07:42:49 +02:00
Vincent Bernat
10dfefebb4 orchestrator/clickhouse: avoid leaking contexts
Scope the cancel() method to avoid leaking contexts in an infinite loop.
2025-07-29 07:42:49 +02:00
Vincent Bernat
cce61cb0d6 common/remotedatasource: rename from remotedatasourcefetcher
Also rename RemoteDataSource to Source.
2025-07-28 18:41:50 +02:00
Vincent Bernat
76151bea66 common/helpers: make some mapstructure hooks work with embedded structs
When using `mapstructure:",squash"`, most structure-specific hook don't
dive into the structure as they are provided with the parent structure.
Add an helper to make them work on the embedded structure as well and
use it for the generic "deprecated fields" hook, but also for the hook
for the common Kafka configuration.

This is a bit brittle. There are other use cases, but they may not need
this change.
2025-07-27 21:44:28 +02:00
Vincent Bernat
756e4a8fbd */kafka: switch to franz-go
The concurrency of this library is easier to handle than Sarama.
Notably, it is more compatible with the new model of "almost share
nothing" we use for the inlet and the outlet. The lock for workers in
outlet is removed. We can now use sync.Pool to allocate slice of bytes
in inlet.

It may also be more performant.

In the future, we may want to commit only when pushing data to
ClickHouse. However, this does not seem easy when there is a rebalance.
In case of rebalance, we need to do something when a partition is
revoked to avoid duplicating data. For example, we could flush the
current batch to ClickHouse. Have a look at the
`example/mark_offsets/main.go` file in franz-go repository for a
possible approach. In the meantime, we rely on autocommit.

Another contender could be https://github.com/segmentio/kafka-go. Also
see https://github.com/twmb/franz-go/pull/1064.
2025-07-27 21:44:28 +02:00
Vincent Bernat
47494ddf79 docker: udpate ClickHouse to 25.3
And sort tables to load them in the right order by looking at the
dependencies. This version of ClickHouse is less lenient.
2025-07-27 21:44:28 +02:00
Vincent Bernat
46155379e7 orchestrator/kafka: try to make Kafka test more robust
It seems topics are not created/updated synchronously in Kafka. This is
a pain.
2025-07-27 21:44:28 +02:00
Vincent Bernat
18fad44f25 orchestrator/kafka: add a log message for partition increase 2025-07-27 21:44:28 +02:00
Vincent Bernat
85226d0326 docker: create a database "test" for ClickHouse
Keep using the default one for the migration tests, but for the small
tests, use the "test" one.
2025-07-27 21:44:28 +02:00
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
Vincent Bernat
5a9a6e6f0a common/helpers: add a hook to deprecate some fields
And apply it to SystemLogTTL and PrometheusEndpoint. It would be nice to
log a warning, but we don't have access to a logger here.
2025-07-27 21:44:28 +02:00
Vincent Bernat
c70f3b74bf orchestrator/clickhouse: remove init.sh endpoint
Instead, just map configuration files inside the container. As we don't
have to push the schema anymore, pushing some arbitrary configuration
does not seem to be our job.
2025-07-27 21:44:28 +02:00
Vincent Bernat
ab96b05583 orchestrator/clickhouse: update protocols.csv 2025-07-13 09:39:45 +02:00
Vincent Bernat
d60a714b8c orchestrator/clickhouse: do not embed clickhouse database settings
Instead, properly use them from the clickhousedb component. Also provide
some automatic migration.
2025-07-08 09:06:31 +02:00
Vincent Bernat
183a5cbb25 orchestrator/clickhouse: do not hardcode schema hash in tests 2025-07-05 20:32:01 +02:00
Vincent Bernat
fb3f5f976b common: use slices from standard library instead of x/exp/slices 2025-06-15 13:58:30 +02:00
Vincent Bernat
e08331a286 common/helpers: switch to a blessed fork of mapstructure 2025-02-15 14:51:17 +01:00
Vincent Bernat
0b98674e69 orchestrator/clickhouse: set TTL for more log tables 2024-12-26 15:39:12 +01:00
Vincent Bernat
3d6d3461d9 orchestrator/clickhouse: also sets TTL for system.text_log table 2024-12-26 15:28:37 +01:00
netixx
f0d85ebb9e Fix system reload request to include db name 2024-12-17 18:23:00 +01:00
Vincent Bernat
aa9e5d1d67 orchestrator/clickhouse: escape user-provided strings
Notably username and password may contain quotes or backslashes.
2024-10-27 08:43:19 +01:00
netixx
b62a433858 Support basic-auth to reach orchestrator from clickhouse 2024-10-27 08:02:10 +01:00