devshawn / kafka-gitops

🚀Manage Apache Kafka topics and generate ACLs through a desired state file.
https://devshawn.github.io/kafka-gitops
Apache License 2.0
320 stars 71 forks source link

Nullpointer exception thrown on empty topic properties. #47

Closed RobinGoussey closed 3 years ago

RobinGoussey commented 4 years ago

Hi, I tried running the docker (through docker compose), and I received a nullpointer exception without explenation. I don't really know if it can be seen as a bug, or missing error message. Basically if I just fill in the name of the topic, and rely on defaults, it gives a nullpointer exception.

I tried to create topics, but with all settings in default, and I got a nullpointer exception. Command:

$ docker-compose -f kafka-gitops.yml up
Recreating kafka-gitops ... done
Attaching to kafka-gitops
kafka-gitops    | 14:32:51.731 [main] INFO com.devshawn.kafka.gitops.config.KafkaGitopsConfigLoader - Kafka Config: {bootstrap.servers=localhost:9092, client.id=kafka-gitops}
kafka-gitops    | 14:32:51.735 [main] INFO com.devshawn.kafka.gitops.service.ParserService - Parsing desired state file...
kafka-gitops    | java.lang.NullPointerException
kafka-gitops    |       at com.devshawn.kafka.gitops.service.ParserService.parseStateFile(ParserService.java:84)
kafka-gitops    |       at com.devshawn.kafka.gitops.service.ParserService.parseStateFile(ParserService.java:42)
kafka-gitops    |       at com.devshawn.kafka.gitops.StateManager.getAndValidateStateFile(StateManager.java:72)
kafka-gitops    |       at com.devshawn.kafka.gitops.cli.ValidateCommand.call(ValidateCommand.java:26)
kafka-gitops    |       at com.devshawn.kafka.gitops.cli.ValidateCommand.call(ValidateCommand.java:15)
kafka-gitops    |       at picocli.CommandLine.executeUserObject(CommandLine.java:1783)
kafka-gitops    |       at picocli.CommandLine.access$900(CommandLine.java:145)
kafka-gitops    |       at picocli.CommandLine$RunLast.handle(CommandLine.java:2141)
kafka-gitops    |       at picocli.CommandLine$RunLast.handle(CommandLine.java:2108)
kafka-gitops    |       at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:1975)
kafka-gitops    |       at picocli.CommandLine.execute(CommandLine.java:1904)
kafka-gitops    |       at com.devshawn.kafka.gitops.MainCommand.main(MainCommand.java:69)
kafka-gitops exited with code 1

docker-compose:

version: '3'

services:
  kafka-gitops:
    image: devshawn/kafka-gitops
    container_name: kafka-gitops
    environment:
      - KAFKA_BOOTSTRAP_SERVERS=localhost:9092
    entrypoint: kafka-gitops -v -f /state-test.yml validate
    volumes:
    - ./state-test.yml:/state-test.yml

my desired state:

topics:
  test:

settings:
  topics:
    defaults:
      partitions: 1
      replication: 1
      configs:
        cleanup.policy: delete
        retention.ms: -1
    blacklist:
      prefixed:
        - _confluent
devshawn commented 4 years ago

Hi @RobinGoussey, thanks for the detailed report! You're receiving a null pointer exception as this isn't valid yaml (per the parser kafka-gitops is using, at least. It may be transforming it to an array instead of an object):

topics:
  test:

That probably needs a better error message. It would need to be structured as:

topics:
  test: {}

With this fix, if you run it, you'll get the following error message:

[INVALID] Not set: [partitions] in state file definition: topics -> test

We currently only support setting a default replication factor, and do not support defaulting partitions / configs, as it says in the specifications page of the docs:

defaults [Optional]: Specify topic defaults so you don’t need to specify them for every topic in the state file. Currently, only replication is supported.

I hope that helps! If setting defaults such as partitions and topic configs is desired, we can open an enhancement issue to look into that for the future. :-)

RobinGoussey commented 4 years ago

Hi @devshawn, I think all settings should be able to be defaulted, as this would make a default template possible, and only the topic names as a list of topics. So an enhancement would be nice :)

devshawn commented 3 years ago

We can open a new issue for the enhancement 👍