RunStream implementation inside Grafana backend datasource for Streaming data

  • What Grafana version and what operating system are you using?
    Grafana 9.x

  • What are you trying to achieve?
    I am trying to stream data from my backend plugin (written in Go). I am not able to cancel the channel once I have streamed all the data.

  • How are you trying to achieve it?
    Using the Publish Stream and RunStream method

  • What happened?
    It is not cancelling the channel once I have streamed all data

  • What did you expect to happen?
    I want the exact mechanism by which inside the second case statement when the condition becomes true I want to cancel the channel and return out of the RunStream method.

  • Can you copy/paste the configuration(s) that you are having problems with?
    The below is Pseudo code:

func (d *RMFClient) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error {
var pnlfuncs pnlf.PanelFunctions
matchedQueryModel := pnlfuncs.GetMatchedQueryModelFromCache(d.Cache, req.Path)
var waitTime time.Duration
for {
select {
case <-ctx.Done():
return nil
case <-time.After(waitTime):
if matchedQueryModel.AbsoluteTimeSelected &&
matchedQueryModel.TimeSeriesTimeRangeTo.After(matchedQueryModel.TimeRangeTo) {
<-ctx.Done()
} else {
// Send new data periodically.
var tq qf.TimeSeriesQuery
newFrame, err := tq.GetMetricsDataFrame(matchedQueryModel, d.EndpointModel)
if newFrame != nil {
matchedQueryModel.Frame = newFrame
}
err = sender.SendFrame(matchedQueryModel.Frame, data.IncludeAll)
if err != nil {
return fmt.Errorf(“error sending frame in method RunStream(). error:%v”, err)
}
}
}
}
}

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    NA
  • Did you follow any online instructions? If so, what is the URL?
    No