SingleStat as the starting point for developing a plugin

Hello.

I’m trying to create a “hacked” version of SingleStat plugin from the Grafana’s core. My changes are rather simple, I’m willing to make SingleStat background change according to panel’s alerting state instead of static thresholds.

So, as far as SingleStat is also in the list of recommended starting points in the Grafana’s docs, I gave it a try. I’ve made a copy of the plugin in the Grafana’s source tree, hacked it and I’m able to compile it inside the source tree. But it would mean I should recompile it for each new version of Grafana and have it installed with my hacks.

So I’ve tried to extract the code as a separate plugin and failed miserably. Mostly because of the dependencies. I’ve inspected other example and non-example plugins several times. No luck at all.

Can someone help me to make it building at least? Here’s my code: https://github.com/divanikus/alertstat

Ok, I’ll try to be more specific, to not sound like I want my work be done by someone else.

If I use “@types/grafana”: “github:CorpGlory/types-grafana.git”, it won’t build because of missing modules

⠼ Bundling plugin in dev mode  [tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(15,25)
    TS2307: Cannot find module 'grafana/app/features/panel/panellinks/link_srv'.

[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(30,3)
TS2564: Property ‘series’ has no initializer and is not definitely assigned in the constructor.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(32,3)
TS2564: Property ‘fontSizes’ has no initializer and is not definitely assigned in the constructor.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(33,3)
TS2564: Property ‘unitFormats’ has no initializer and is not definitely assigned in the constructor.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(34,3)
TS2564: Property ‘invalidGaugeRange’ has no initializer and is not definitely assigned in the constructor.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(382,28)
TS2339: Property ‘$location’ does not exist on type ‘AlertStatCtrl’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(651,9)
TS2322: Type ‘null’ is not assignable to type ‘{ target: string; href: string; title: string; }’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(699,26)
TS2339: Property ‘place_tt’ does not exist on type ‘JQLite’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks/link_srv.ts(2,25)
TS2307: Cannot find module ‘app/features/dashboard/services/TimeSrv’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks/link_srv.ts(3,42)
TS2307: Cannot find module ‘app/features/templating/template_srv’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks/link_srv.ts(4,24)
TS2307: Cannot find module ‘app/core/core_module’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks/link_srv.ts(5,47)
TS2307: Cannot find module ‘app/core/utils/url’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks/link_srv.ts(17,32)
TS7006: Parameter ‘variable’ implicitly has an ‘any’ type.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks/link_srv.ts(134,62)

If I use hardcoded absolute paths to my 6.3.4 grafana source tree, it just returns some crazy stuff I don’t know how to handle:

⠇ Bundling plugin in dev mode  Module not found: Error: Can't resolve 'app/core/core_module' in '/opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks'

Module not found: Error: Can’t resolve ‘app/core/utils/ticks’ in ‘/opt/go/src/github.com/grafana/grafana/public/app/core’
Module not found: Error: Can’t resolve ‘app/core/utils/url’ in ‘/opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks’
Module not found: Error: Can’t resolve ‘app/features/alerting/AlertTabCtrl’ in ‘/opt/go/src/github.com/grafana/grafana/public/app/plugins’
Module not found: Error: Can’t resolve ‘app/features/panel/metrics_panel_ctrl’ in ‘/opt/go/src/github.com/grafana/grafana/public/app/plugins’
Module not found: Error: Can’t resolve ‘app/features/panel/panel_ctrl’ in ‘/opt/go/src/github.com/grafana/grafana/public/app/plugins’
Module not found: Error: Can’t resolve ‘app/features/panel/query_ctrl’ in ‘/opt/go/src/github.com/grafana/grafana/public/app/plugins’
Module not found: Error: Can’t resolve ‘app/features/templating/template_srv’ in ‘/opt/go/src/github.com/grafana/grafana/public/app/features/panel/panellinks’
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(30,3)
TS2564: Property ‘series’ has no initializer and is not definitely assigned in the constructor.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(32,3)
TS2564: Property ‘fontSizes’ has no initializer and is not definitely assigned in the constructor.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(33,3)
TS2564: Property ‘unitFormats’ has no initializer and is not definitely assigned in the constructor.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(34,3)
TS2564: Property ‘invalidGaugeRange’ has no initializer and is not definitely assigned in the constructor.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(111,10)
TS2339: Property ‘addEditorTab’ does not exist on type ‘AlertStatCtrl’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(112,10)
TS2339: Property ‘addEditorTab’ does not exist on type ‘AlertStatCtrl’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(118,10)
TS2339: Property ‘refresh’ does not exist on type ‘AlertStatCtrl’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(141,10)
TS2339: Property ‘render’ does not exist on type ‘AlertStatCtrl’.
[tsl] ERROR in /opt/go/src/github.com/grafana/grafana/data/plugins/divanikus-alertstat-panel/src/module.ts(185,32)
TS2532: Object is possibly ‘undefined’.

When developing a plugin they can not live inside the grafana repo. Choose a directory for you plugin and point to it in custom.ini see this line:

# Directory where grafana will automatically scan and look for plugins

I’m not sure it is the cause of your issue but try that and see if the same error occurs.

Yeah, I am aware of it. So I’m trying to build my plugin without using Grafana’s source tree. But as far as SingleStat actually do use a lot of internal structures, I can’t build it even using 3rd party SDK mocks.