grafana/simple-json-backend-datasource

Current development status

natenho opened this issue · 6 comments

Hey @alexanderzobnin, I'd like to use this plugin in an experimental project. Is it working? I'm unable to build it properly...to be honest, I'm not familiar with Go. Is it published somewhere or still a work in progress? I couldn't find it under grafana plugins...The main reason is that this example has alarms support, exactly what I'm looking for.

Thanks!

That would be useful for me as well, currently we have to implement the alerting system by ourserves using the API we created to integrate with Grafana. It would simplify our solution if we could use the Grafana own alerting system. I found this documentation page saying how to create a backend plugin https://grafana.com/docs/plugins/developing/backend-plugins-guide/ (using the simple json plugin as an example by the way), but brownsing through other issues on the grafana repositories, they say that backend plugins are not supported yet (grafana/grafana#6841).

Thanks!

This was my first attempt to compile the project. Basically, I followed the instructions to install yarn and run make:

npm install -g yarn
yarn install --pure-lockfile
make

The first thing I had to do is to properly setup grunt, because it was not working. Then, running make again, everything gone well with the grunt part, but in the "go build" step:

go build -i -o ./dist/simple-json-plugin_linux_amd64 ./pkg
pkg/datasource.go:13:2: cannot find package "github.com/bitly/go-simplejson" in any of:
        /usr/lib/go-1.7/src/github.com/bitly/go-simplejson (from $GOROOT)
        ($GOPATH not set)
pkg/datasource.go:14:2: cannot find package "github.com/grafana/grafana_plugin_model/go/datasource" in any of:
        /usr/lib/go-1.7/src/github.com/grafana/grafana_plugin_model/go/datasource (from $GOROOT)
        ($GOPATH not set)
pkg/datasource.go:15:2: cannot find package "github.com/hashicorp/go-hclog" in any of:
        /usr/lib/go-1.7/src/github.com/hashicorp/go-hclog (from $GOROOT)
        ($GOPATH not set)
pkg/datasource.go:16:2: cannot find package "github.com/hashicorp/go-plugin" in any of:
        /usr/lib/go-1.7/src/github.com/hashicorp/go-plugin (from $GOROOT)
        ($GOPATH not set)
pkg/datasource.go:17:2: cannot find package "golang.org/x/net/context" in any of:
        /usr/lib/go-1.7/src/golang.org/x/net/context (from $GOROOT)
        ($GOPATH not set)
pkg/datasource.go:18:2: cannot find package "golang.org/x/net/context/ctxhttp" in any of:
        /usr/lib/go-1.7/src/golang.org/x/net/context/ctxhttp (from $GOROOT)
        ($GOPATH not set)
Makefile:7: recipe for target 'build' failed
make: *** [build] Error 1

To deal with this error, I had to move the folders under vendor/ to vendor/src and
export GOPATH=$PWD/vendor then it could find the packages.

Then I stuck at this point :-( :

go build -i -o ./dist/simple-json-plugin_linux_amd64 ./pkg
# google.golang.org/grpc/credentials/internal
vendor/src/google.golang.org/grpc/credentials/internal/syscallconn.go:29: syntax error: unexpected = in type declaration
# google.golang.org/grpc/internal/syscall
vendor/src/google.golang.org/grpc/internal/syscall/syscall_linux.go:79: tcpconn.SyscallConn undefined (type *net.TCPConn has no field or method SyscallConn)
vendor/src/google.golang.org/grpc/internal/syscall/syscall_linux.go:100: tcpconn.SyscallConn undefined (type *net.TCPConn has no field or method SyscallConn)
# google.golang.org/grpc/naming
vendor/src/google.golang.org/grpc/naming/dns_resolver.go:41: undefined: net.DefaultResolver in net.DefaultResolver.LookupHost
vendor/src/google.golang.org/grpc/naming/dns_resolver.go:42: undefined: net.DefaultResolver in net.DefaultResolver.LookupSRV
# google.golang.org/grpc/resolver/dns
vendor/src/google.golang.org/grpc/resolver/dns/dns_resolver.go:68: undefined: net.DefaultResolver
vendor/src/google.golang.org/grpc/resolver/dns/dns_resolver.go:86: undefined: net.Resolver
# golang.org/x/net/http2
vendor/src/golang.org/x/net/http2/server.go:214: h1.IdleTimeout undefined (type *http.Server has no field or method IdleTimeout)
vendor/src/golang.org/x/net/http2/server.go:215: h1.IdleTimeout undefined (type *http.Server has no field or method IdleTimeout)
vendor/src/golang.org/x/net/http2/server.go:220: s.RegisterOnShutdown undefined (type *http.Server has no field or method RegisterOnShutdown)
vendor/src/golang.org/x/net/http2/server.go:2085: undefined: http.ErrAbortHandler
vendor/src/golang.org/x/net/http2/server.go:2647: undefined: http.Pusher
vendor/src/golang.org/x/net/http2/server.go:2649: undefined: http.PushOptions
vendor/src/golang.org/x/net/http2/server.go:2661: undefined: http.PushOptions
vendor/src/golang.org/x/net/http2/transport.go:494: undefined: http.NoBody
vendor/src/golang.org/x/net/http2/transport.go:500: req.GetBody undefined (type *http.Request has no field or method GetBody)
vendor/src/golang.org/x/net/http2/transport.go:502: req.GetBody undefined (type *http.Request has no field or method GetBody)
vendor/src/golang.org/x/net/http2/transport.go:502: too many errors
Makefile:7: recipe for target 'build' failed
make: *** [build] Error 2

For me the only error I have is:

pkg\plugin.go:25:4: cannot use &datasource.DatasourcePluginImpl literal (type *datasource.DatasourcePluginImpl) as type "github.com/hashicorp/go-plugin".Plugin in map value:
        *datasource.DatasourcePluginImpl does not implement "github.com/hashicorp/go-plugin".Plugin (wrong type for Client method)
                have Client(*"github.com/grafana/grafana_plugin_model/vendor/github.com/hashicorp/go-plugin".MuxBroker, *rpc.Client) (interface {}, error)
                want Client(*"github.com/hashicorp/go-plugin".MuxBroker, *rpc.Client) (interface {}, error)

And I have the same error when I want to write one from scratch.
I am using : go version go1.13.1 windows/amd64

I got it working with a go.mod file with the following:

module github.com/repo/module

go 1.13

require (
	github.com/bitly/go-simplejson v0.5.0
	github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
	github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4
	github.com/hashicorp/go-hclog v0.9.2
	github.com/hashicorp/go-plugin v1.0.1
	github.com/kr/pretty v0.1.0 // indirect
	golang.org/x/net v0.0.0-20180826012351-8a410e7b638d
)

I've managed to get the go code compiling but I am struggling with the front end compilation. @natenho could you elaborate on precisely how you managed to properly setup grunt as you mention above.

I have attempted
npm install -g yarn
yarn install --pure-lockfile and I got a series (many) errors such as

20 errors generated.
20 errors generated.
make: make: *** [Release/obj.target/fse/fsevents.o] Error 1*** [Release/obj.target/fse/fsevents.o] Error 1

If anyone could steer me in the right direction it would be greatly appreciated.

@mubeta06 I've updated build instructions in the #7, you may take a look. The docker part works perfectly and builds the project's frontend and backend successfully.
image
image
image