The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/services/live/pipeline/frame_output_local_subscrib...

44 lines
1.2 KiB

package pipeline
import (
"context"
"encoding/json"
"fmt"
"github.com/centrifugal/centrifuge"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/services/live/orgchannel"
)
type LocalSubscribersFrameOutput struct {
// TODO: refactor to depend on interface (avoid Centrifuge dependency here).
node *centrifuge.Node
}
func NewLocalSubscribersFrameOutput(node *centrifuge.Node) *LocalSubscribersFrameOutput {
return &LocalSubscribersFrameOutput{node: node}
}
const FrameOutputTypeLocalSubscribers = "localSubscribers"
func (out *LocalSubscribersFrameOutput) Type() string {
return FrameOutputTypeLocalSubscribers
}
func (out *LocalSubscribersFrameOutput) OutputFrame(_ context.Context, vars Vars, frame *data.Frame) ([]*ChannelFrame, error) {
channelID := vars.Channel
channel := orgchannel.PrependOrgID(vars.OrgID, channelID)
frameJSON, err := json.Marshal(frame)
if err != nil {
return nil, err
}
pub := &centrifuge.Publication{
Data: frameJSON,
}
err = out.node.Hub().BroadcastPublication(channel, pub, centrifuge.StreamPosition{})
if err != nil {
return nil, fmt.Errorf("error publishing %s: %w", string(frameJSON), err)
}
return nil, nil
}