panelCtrl.refresh() not working

Hi Folks,

So my plugin is borrowing heavily from simple-json-datasource, although my datasource.js is different because I’m using websocket and rxJS.

However query_ctrl.js and partials/query.editor.html are identical except for the class name. Everything goes as expected until onChangeInternal() gets called in my sub-class of QueryCtrl, then everything stops. In simple-json-datasource the query() method on the datasource class gets called after onChangeInternal().

Workflow is:

  • User opens graph data panel
  • User selects Edit
  • User selects new metric from drop-down to display in graph.

Here’s the constructor and query method on my datasource:

export class ABBDatasource {

constructor(instanceSettings, $http, backendSrv, templateSrv) {
    this.type = instanceSettings.type;
    this.url = 'hard coded string containing url for now'; =;
    this.instanceSettings = instanceSettings;
    this.$http = $http;
    this.backendSrv = backendSrv;
    this.templateSrv = templateSrv;
    this.headers = {'Content-Type': 'applications/json'};
    this.streamHandlers = {};

query(options) {
    console.log('query. Options passed in', options);
    var handler = this.streamHandlers[options.panelId];
    if (handler) {
        return Promise.resolve(handler);

    this.streamHandlers[options.panelId] = handler = new StreamHandler(options, this);

    return Promise.resolve(handler);

This is grafana 4.4.1 running on windows 2012.

How do I get the QueryCtrl to refresh from the datasource? As in how do I get ABBDatasource.query() to execute after the datapanel is refreshed?

Not sure, the rxjs stuff is a bit experimental. When you hit dashboard time range refresh, are you seeing any call query datasource query method?

No it doesn’t, it doesn’t get called on Save either. Only when the page is reloaded or refreshed.

But I doesn’t look like this is being caused by rxJS as we aren’t getting that far. Whatever event that’s supposed to be raised when I change or add a value under the Metrics tab isn’t getting raised by the metric-segment-model directive.

<edit> upon further investigations it is the rxjs/websocket stuff, if I comment it out it works. I’m wondering if it’s interfering with the event loop. So I shall continue to dig but if you have any ideas let me know.

I am also trying to write a WebSocket based streaming Datasource plugin and realized that query method is not getting called on any template, dashboard time range and panel query changes, until I reload the dashboard.

In metrics_panel_ctrl.js, we have an explicit check to drop all refresh events if datasource query method returns datastream object. (Rxjs Observer).

This is not letting to change the stream on any template variable changes.

@torkel Can you please comment on the last comment? I am trying to use template variables on my data stream query.