0

I use Kafka with the Python SDK and run the Code in a Kubernetes Cluster. The "main" consumer function looks like this:

def consume(self):
    logger.info("Consumer starting listening.")
    try:
        while True:
            msg = self.consumer.poll(timeout=0.1)
            if msg is None:
                continue
            if msg.error():
                if msg.error().code() == KafkaError._PARTITION_EOF:
                    continue
                continue
            try:
                received_message = self.json_deserialize(msg.value())
            except ValidationError as err:  
                self.consumer.commit(message=msg)
                continue
            processed_message = self.processor(received_message)
            self.producer.send_object(
                processed_message,
                topic=self.producer.topics[0],  # Success topic (aus config)
                trace_id=processed_message.header.trace_id,
            )
            self.consumer.commit(message=msg)

    except KeyboardInterrupt:
        logger.info("Received keyboard interrupt signal")
    finally:
        self.stop()

So the code performs a while loop and processes the message.

I have researched the following options:

  1. Perform a HTTP request => does not work with Kafka
  2. Process the LAST log message and check the date. => does not work, since I don´t know when the next message will be processed.

My colleagues gave me the following probes, but in my Opinion they do absolutly nothing?!

          readinessProbe:
            exec:
              command: [ '/bin/bash' ]
              args: [ '-c', 'echo readinessProbe erfolgreich' ]
            initialDelaySeconds: ${{READINESS_INITIAL_DELAY_SECONDS}}
            timeoutSeconds: ${{READINESS_TIMEOUT}}
          livenessProbe:
            exec:
              command: [ '/bin/bash' ]
              args: [ '-c', 'echo livenessProbe erfolgreich' ]
            initialDelaySeconds: ${{LIVENESS_INITIAL_DELAY_SECONDS}}
            timeoutSeconds: ${{LIVENESS_TIMEOUT}}

So my main Questions are:

  1. Am I right and the readinessprobe and livenessProbe do absolutely nothing?
  2. If yes, what would be an option to perform these probs on my pods?
Data Mastery
  • 1,555
  • 4
  • 18
  • 60

1 Answers1

0

If your probes are meant to be checking your Python pod, it doesn't matter what Kafka supports. You can wrap your Python code in a simple web server.

You're correct that echoing something is useless for checking something is ready or healthy

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • "You can wrap your Python code in a simple web server." -> what do you mean with that? Run the code in a second container in the pod? The Code already runs in a Container. – Data Mastery Mar 21 '22 at 15:53
  • Containers don't matter here. You're asking how to run an external healthcheck. Use Flask, for example. Make your probes check that via http. – OneCricketeer Mar 21 '22 at 16:51