Ingesting log from kafka to loki

Hello, i’m currently exploring an idea to deploy loki in an kubernetes environment that don’t have access to persistence volume (hence no wal) but have access to kafka. My primary concern is to make sure that all logs routed to kafka are safely persisted in loki without data loss.

My idea is

  1. Deploy loki write with additional container that fetch logs from kafka.
  2. Have that container write the logs to loki write container.
  3. Periodically call shutdown with flush to loki write
  4. After successfully doing step no.3, commit the consumer offset to kafka.

My question, will this scenario works in ensuring the persistence of the logs to loki? And can this pod (which contain loki write and custom container) scaled horizontally?

Thanks

Check/test otel kafka receiver for this case:

Anything what is statefull is a problem to scale horizontally.

Hi @jangaraj , thanks for the reference. But how does kafka otel receiver ensure that log sent to loki have been persisted into the chunk storage?

I think your plan is sound.

You should just call the /flush endpoint without shutdown. Shutdown / restart every flush seems rather inefficient.

I think it sounds good on paper. In terms of scaling that’s up to how you code your kafka extractor. You can use the Zookeeper cluster within Kafka, write your extractor state so you can form a cluster for parallel processing, you can then scale your kafka extractor along with Loki writer. And your flow would be:

  1. One extractor per Loki writer.
  2. extractor retrieve logs from Kafka.
  3. extractor sends logs to its dedicated writer.
  4. extractor sends /flush to its dedicated writer.
  5. extractor writes offset back to Kafka.
  6. Repeat.

Performance would probably be the primary concern here. You probably don’t want to flush too often, but you also don’t want to wait too long.

Thanks a lot @tonyswumac

got it. luckily i don’t have to move the log in realtime so i think it will works.
thanks a lot for the guidance