Need to change "grafanaDependency": "7.x.x" to support Grafana 8 since it currently means only Grafana v7.x.x versions are supported . Since grafana packages dependencies are 8.2.0 would recommend "grafanaDependency": ">=8.2 <9". However, verified the plugin works with v7.3.0 and v8.5.0 so maybe "grafanaDependency": ">=7.3 <9" is more suitable?
[x] Lack of instance management
We strongly recommend to use instance management so that you can cache Google Analytic client for each configured datasource in Grafana and by that be able to make use of reusing HTTP connections. In main.go, please use datasource.Manage. See working example here https://github.com/grafana/grafana-plugin-examples/blob/master/examples/datasource-basic/pkg/main.go. As you can see in this code that will be called each time a Google Analytics datasource is created/updated in Grafana which gives you a perfect opportunity to instantiate your GA client and store it on the Datasource struct. Then you can access the client from the Datasource struct when handling QueryData, CheckHealth and resource calls.
[x] Error logging
Error logging should include error key, e.g. rather than log.DefaultLogger.Error("Fail LoadSetting", err.Error()) use log.DefaultLogger.Error("Fail LoadSetting", "error", err)
[x] LoadSettings
Reference to profileId which doesn't seem to be configurable from the UI and read from secureJsonData, what's the idea with this?
The LoadSettings function seems like it could be optimized,
Suggested changes
[x] Replace Info log level with debug level
Would be nice if Info logging is replaced with debug level since it no outputs a lot of information with info level in Grafana server log.
logger=context traceID=00000000000000000000000000000000 userId=0 orgId=1 uname= t=2022-04-26T12:14:49.84+0000 lvl=info msg="Request Completed" method=GET path=/api/live/ws status=0 remote_addr=172.19.0.1 time_ms=0 duration=447.724µs size=0 referer= traceID=00000000000000000000000000000000
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:50+0000 lvl=info msg="query timezone" timezone=Europe/Stockholm
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:50+0000 lvl=info msg=getReport queries="unsupported value type"
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:50+0000 lvl=info msg=getReport reportRequests="unsupported value type"
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:50+0000 lvl=info msg="Doing GET request from analytics reporting" req="unsupported value type"
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:50.5+0000 lvl=info msg="Do GET report" report="unsupported value type" reportlen=1
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:50.5+0000 lvl=info msg=Elapsed GetreportdataatGAAPI=502.927991ms
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:59.04+0000 lvl=info msg=getWebpropertiesList WebpropertiesList="unsupported value type"
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:59.9+0000 lvl=info msg=getReport queries="unsupported value type"
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:59.9+0000 lvl=info msg=getReport reportRequests="unsupported value type"
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:14:59.9+0000 lvl=info msg="Doing GET request from analytics reporting" req="unsupported value type"
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:15:00.64+0000 lvl=info msg="Do GET report" report="unsupported value type" reportlen=1
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:15:00.64+0000 lvl=info msg=Elapsed GetreportdataatGAAPI=737.515163ms
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:15:00.64+0000 lvl=info msg=HTTPStatusCode status=200
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:15:00.64+0000 lvl=info msg=res
logger=plugin.blackcowmoo-googleanalytics-datasource t=2022-04-26T12:15:00.64+0000 lvl=info msg="%s: %s" ga:sessions=2
current situation
Detail
required change
[x] Update plugin.json
[x] Lack of instance management
[x] Error logging
[x] LoadSettings