Debugging a provider plugin

I'm building a traefik provider plugin, it's failing to load with an immediate runtime panic. I'm at a loss on the best way to debug, I've installed yaegi locally hoping I could reproduce there but not sure how to simulate loading the plugin?

Any help would be appreciated!
Thanks, Dan

Here's some logs with the error:

raefik-test  | time="2024-11-12T19:19:57Z" level=info msg="Configuration loaded from file: /etc/traefik/traefik.yml"
traefik-test  | time="2024-11-12T19:19:57Z" level=info msg="Traefik version 2.10.7 built on 2023-12-06T15:54:59Z"
traefik-test  | time="2024-11-12T19:19:57Z" level=debug msg="Static configuration loaded {\"global\":{\"checkNewVersion\":true},\"serversTransport\":{\"maxIdleConnsPerHost\":200},\"entryPoints\":{\"traefik\":{\"address\":\":8080\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":\"10s\"},\"respondingTimeouts\":{\"idleTimeout\":\"3m0s\"}},\"forwardedHeaders\":{},\"http\":{},\"http2\":{\"maxConcurrentStreams\":250},\"udp\":{\"timeout\":\"3s\"}},\"web\":{\"address\":\":80\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":\"10s\"},\"respondingTimeouts\":{\"idleTimeout\":\"3m0s\"}},\"forwardedHeaders\":{},\"http\":{},\"http2\":{\"maxConcurrentStreams\":250},\"udp\":{\"timeout\":\"3s\"}}},\"providers\":{\"providersThrottleDuration\":\"2s\",\"docker\":{\"watch\":true,\"endpoint\":\"unix:///var/run/docker.sock\",\"defaultRule\":\"Host(`{{ normalize .Name }}`)\",\"swarmModeRefreshSeconds\":\"15s\"}},\"api\":{\"insecure\":true,\"dashboard\":true},\"metrics\":{\"prometheus\":{\"buckets\":[0.1,0.3,1.2,5],\"addEntryPointsLabels\":true,\"addServicesLabels\":true,\"entryPoint\":\"traefik\"}},\"log\":{\"level\":\"DEBUG\",\"format\":\"common\"},\"experimental\":{\"localPlugins\":{\"traefik_cloud_saver\":{\"moduleName\":\"github.com/danbiagini/traefik-cloud-saver\"}}}}"
traefik-test  | time="2024-11-12T19:19:57Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://doc.traefik.io/traefik/contributing/data-collection/\n"
traefik-test  | time="2024-11-12T19:19:57Z" level=error msg="plugins-local/src/github.com/danbiagini/traefik-cloud-saver/vendor/google.golang.org/grpc/grpclog/loggerv2.go:36:17: panic" module=github.com/danbiagini/traefik-cloud-saver plugin=plugin-traefik_cloud_saver
traefik-test  | time="2024-11-12T19:19:57Z" level=error msg="plugins-local/src/github.com/danbiagini/traefik-cloud-saver/vendor/google.golang.org/grpc/grpclog/grpclog.go:33:14: panic" module=github.com/danbiagini/traefik-cloud-saver plugin=plugin-traefik_cloud_saver
traefik-test  | panic: runtime error: invalid memory address or nil pointer dereference [recovered]
traefik-test  |         panic: runtime error: invalid memory address or nil pointer dereference [recovered]
traefik-test  |         panic: runtime error: invalid memory address or nil pointer dereference
traefik-test  | [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x44b068]
traefik-test  | 
traefik-test  | goroutine 1 [running]:
traefik-test  | github.com/traefik/yaegi/interp.runCfg.func1()
traefik-test  |         github.com/traefik/yaegi@v0.15.1/interp/run.go:205 +0x16c
traefik-test  | panic({0x3c26ec0?, 0x8491c80?})
traefik-test  |         runtime/panic.go:914 +0x218
traefik-test  | github.com/traefik/yaegi/interp.runCfg.func1()

Just to add some more debug steps I've tried:

  1. adding print statements to the New() and Init() functions, i.e. os.Stdout.WriteString("DEBUG: New CloudSaver\n")
  2. commenting out the plugin in my traefik.yml (traefik then loads successfully)
  3. unit tests and linter both pass

An update for future readers. It seems there's an incompatibility issue with using the library "google.golang.org/api/compute/v1" in traefik. I've tried both traefik 2 & 3, same result.

I've switched to using the google HTTP APIs directly, I'm having more success with this approach.

Thanks for providing solution. It help me a lot.

1 Like