hoptical / grafana-kafka-datasource

A Grafana datasource plugin for Apache Kafka
Apache License 2.0
34 stars 13 forks source link

Mage Error #6

Open hoptical opened 2 years ago

hoptical commented 2 years ago

Running mage command faces bellow error:

$ mage build:backend -v
# github.com/grafana/grafana-starter-datasource-backend/pkg/kafka_helper
pkg/kafka_helper/client.go:12:12: undefined: kafka.Consumer
pkg/kafka_helper/client.go:15:48: undefined: kafka.Consumer
pkg/kafka_helper/client.go:17:25: undefined: kafka.NewConsumer
pkg/kafka_helper/client.go:17:44: undefined: kafka.ConfigMap
pkg/kafka_helper/client.go:42:50: undefined: kafka.Event
pkg/kafka_helper/client.go:50:8: undefined: kafka.Message
pkg/kafka_helper/client.go:53:7: undefined: kafka.Error
pkg/kafka_helper/client.go:60:18: undefined: kafka.ErrAllBrokersDown
Error: running "go build -o dist/gpx_kafka-datasource_linux_amd64 -ldflags -w -s -extldflags "-static" -X 'main.commit=efe069bd4332485c723ec3c23116b6eaf04d918e' -X 'github.com/grafana/grafana-plugin-sdk-go/build.buildInfoJSON={"time":1636410898742,"version":"1.0.0","repo":"git@github.com:exaco/kafka-datasource.git","branch":"main","hash":"efe069bd4332485c723ec3c23116b6eaf04d918e"}' -X 'main.version=1.0.0' -X 'main.branch=main' ./pkg" failed with exit code 2

But its ok with the direct go build command and Grafana works with it successfully: go build -o dist/gpx_kafka-datasource_linux_amd64 ./pkg

marcusolsson commented 2 years ago

I think you need to:

  1. Update the package name in the go.mod file.
  2. It seems like the kafka package requires cgo, to you'll need to enable it as well. Add the following to your Magefile.go:
var _ = build.SetBeforeBuildCallback(func(cfg build.Config) (build.Config, error) {
    cfg.EnableCGo = true
    return cfg, nil
})

Also looks like the kafka package isn't supported on Windows, so you might have some trouble building the Windows binary.

hoptical commented 2 years ago

@marcusolsson Thanks for your answer. Yes, It worked after your suggested modifications. So according to this link, we've below considerations with confluent-kafka-go package:

However, in future, we'll consider changing to other packages such as kafka-go or goka.