Kafka sink adapter for the Ankusa webhook ingestion framework.

This package exists so ankusa core stays free of the :brod dependency (and the crc32cer NIF it pulls in). Only deployments that opt into a Kafka sink need this package.

Installation

def deps do
  [
    {:ankusa, "~> 0.7"},
    {:ankusa_kafka, "~> 0.7"}
  ]
end

Usage

See Ankusa.Sink.Kafka moduledoc for configuration and semantics.

config :ankusa,
  sources: %{
    "orders" => [
      sinks: [
        {Ankusa.Sink.Kafka,
         brokers: ["localhost:9092"],
         topic: "ankusa.events"}
      ]
    ]
  }

Sinks belong to a source. Ankusa.Config.new/1 takes the same sources for a non-default instance.

The intake log of wal.type: dual

Ankusa.Intake.Kafka is the adapter of the dual-commit intake log (ADR 0002): a hook is acked only after it is fsynced on the node and confirmed in a replicated topic, so a lost host loses nothing.

config =
  Ankusa.Config.new(
    wal: :dual,
    intake: %{
      type: :kafka,
      node_id: "ankusa-a",
      kafka: [brokers: ["kafka-1:9092", "kafka-2:9092", "kafka-3:9092"]]
    },
    backup: %{
      enabled: true,
      max_age_ms: 300_000,
      blob_store: {Ankusa.BlobStore.S3, bucket: "backups"}
    }
  )

{:ok, _pid} = Ankusa.Instance.start_link(config)

The autostarted default instance reads only :autostart, :port, :data_dir, :roles and :sources from application env; everything else takes effect through Ankusa.Config.new/1 and Ankusa.Instance.

The topic (ankusa.intake.<fleet>) is the operator's, and the adapter never creates one. verify/1 refuses it at boot unless it has replication factor 3 or more, min.insync.replicas 2 or more, unclean.leader.election.enable=false, a retention.ms of at least twice backup.max_age_ms and a max.message.bytes of at least intake.max_record_bytes:

kafka-topics.sh --bootstrap-server kafka-1:9092 --create --topic ankusa.intake.default \
  --partitions 3 --replication-factor 3 --config min.insync.replicas=2 \
  --config unclean.leader.election.enable=false --config retention.ms=3600000 \
  --config max.message.bytes=11000000

See docs/deployment.md for sizing, the replacement procedure and recover.

Testing

The compose file has two clusters: a single Redpanda broker (the sink's tests) and a three-broker KRaft cluster (the intake adapter's tests, which stop and restart brokers with docker compose, so they need the docker CLI):

docker compose up -d --wait
mix test
docker compose down -v

mix run bench/partition_bench.exs measures what one partition of that cluster carries at the plan's per-node rate.