Sending both live and historical data


I’m trying to develop a small backend datasource plugin using the resources found in the documentation. The goal is to retrieve data (logs for now) from a custom component offering a REST API to retrieve historical data and a websocket for live data, and display both seamlessly in Grafana.

So far, I can either get historical data or stream, but I cannot make them work together properly. As far as I can see, the most straightforward way to achieve this is to implement the query method on Datasource as follows :

func (d *Datasource) query(_ context.Context, pCtx backend.PluginContext, query backend.DataQuery) backend.DataResponse {
	var response backend.DataResponse

	// Unmarshal the JSON into our queryModel.
	var qm queryModel
	response.Error = json.Unmarshal(query.JSON, &qm)
	if response.Error != nil {
		return response

	frame := data.NewFrame("")

	// add streaming capabilities (if requested)
	if qm.WithStreaming {
		log.DefaultLogger.Info("Got request for streaming")
		channel := live.Channel{
			Scope:     live.ScopeDatasource,
			Namespace: pCtx.DataSourceInstanceSettings.UID,
			Path:      "stream",
		frame.SetMeta(&data.FrameMeta{Channel: channel.String()})
	} else {
		log.DefaultLogger.Info("Got request for historical data only")

	// request my historical data and add it in the data frame (request processing removed for the sake of clarity)
        frame.Fields = append(frame.Fields, ...)

	// add the frames to the response.
	response.Frames = append(response.Frames, frame)

	return response

But when doing this, I can see the historical data for a fraction of a second before it disappears and shows only the live data. If someone has any hint on how to solve this, that would be much appreciated.

Hello, I want to re-open this since I’m having a very similar issue. Did you end up seeing both live and historical data on the same panel here?