Self developed metricbeat module throws in docker a strange error

Hi,
I developed a metricbeat module and metricset. I ran "mage update" and "mage build" and tested it in my VM and it ran perfectly.
I then zipped the following files, copied dit to another VM (Ubuntu as well) and started it and it ran perfectly:

tar zcvf my_module.tar.gz module/my_module \
   fields.yml metricbeat.reference.yml \
   metricbeat.yml modules.d/my_module.yml metricbeat

Btw. my module has the name "My_module" and my metricset has the name file_mon.

Ok, then I wanted to containerize it, to deploy it with the following dockerfile:

FROM ubuntu:18.04 

RUN mkdir -p /metricbeat/modules.d
RUN apt update
RUN apt -y upgrade


COPY metricbeat /metricbeat
COPY metricbeat.yml /metricbeat
COPY metricbeat.reference.yml /metricbeat
COPY fields.yml /metricbeat
COPY modules.d/my_module.yml /metricbeat/modules.d/my_module.yml
EXPOSE 9200

CMD cd /metricbeat && ./metricbeat -e -d "*"

Now this is the strange part:

I always get this error message:

{"log.level":"error","@timestamp":"2022-04-04T20:44:10.000Z","log.origin":{"file.name":"runtime/panic.go","file.line":221},"message":"recovered from panic while fetching 'my_module/file_mon' for host 'localhost'. Recovering, but please report this.","service.name":"metricbeat","error":{"message":"runtime error: invalid memory address or nil pointer dereference"},"stack":"github.com/elastic/beats/v7/libbeat/logp.Recover\n\tgithub.com/elastic/beats/v7/libbeat/logp/global.go:102\nruntime.gopanic\n\truntime/panic.go:1038\nruntime.panicmem\n\truntime/panic.go:221\nruntime.sigpanic\n\truntime/signal_unix.go:735\ngithub.com/elastic/beats/v7/metricbeat/module/my_module/file_mon.(*MetricSet).Fetch\n\tgithub.com/elastic/beats/v7/metricbeat/module/my_module/file_mon/file_mon.go:72\ngithub.com/elastic/beats/v7/metricbeat/mb/module.(*metricSetWrapper).fetch\n\tgithub.com/elastic/beats/v7/metricbeat/mb/module/wrapper.go:251\ngithub.com/elastic/beats/v7/metricbeat/mb/module.(*metricSetWrapper).startPeriodicFetching\n\tgithub.com/elastic/beats/v7/metricbeat/mb/module/wrapper.go:223\ngithub.com/elastic/beats/v7/metricbeat/mb/module.(*metricSetWrapper).run\n\tgithub.com/elastic/beats/v7/metricbeat/mb/module/wrapper.go:207\ngithub.com/elastic/beats/v7/metricbeat/mb/module.(*Wrapper).Start.func1\n\tgithub.com/elastic/beats/v7/metricbeat/mb/module/wrapper.go:147","ecs.version":"1.6.0"}

The crazy part is this: when I copy the system.yml module configfile and enable it and when i disable "my_module", the error does not appear.

Has anyone experience with self written metricbeat modules and discovered the same error? Again, i can deploy the zip file to any machine and it runs smoothly. Even if i use another docker base image like centos:7 or docker.elastic.co/beats/metricbeat:8.1.2 i am running into the same problem. the current version of metricbeat for the development environment is

./metricbeat version
metricbeat version 8.3.0 (amd64), libbeat 8.3.0 [7e22a97892a86d42a2d8966e70b942d564a32d69 built 2022-04-04 18:46:01 +0000 UTC]

Help is very appreciated

Thanks
Pascal

I close the topic, since the problem has been solved.
The panic was caused by a call on Go object, that was nil.
To be more precise, i tried to read statistics of a file that was not existing.

See my journey here.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.