Live: update Streaming plugin definitions, put frame schema in subscribe result data (#32561)

Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Alexander Emelin
2021-04-02 19:41:45 +03:00
committed by GitHub
parent 7fcb6ecb91
commit 93292f6eef
21 changed files with 408 additions and 205 deletions

View File

@ -4,40 +4,54 @@ import (
"context"
"encoding/json"
"time"
"github.com/grafana/grafana-plugin-sdk-go/backend"
)
// ChannelPublisher writes data into a channel. Note that pemissions are not checked.
// ChannelPublisher writes data into a channel. Note that permissions are not checked.
type ChannelPublisher func(channel string, data []byte) error
// SubscribeEvent contains subscription data.
type SubscribeEvent struct {
Channel string
Path string
}
// SubscribeReply is a reaction to SubscribeEvent.
type SubscribeReply struct {
Presence bool
JoinLeave bool
Recover bool
Data json.RawMessage
}
// PublishEvent contains publication data.
type PublishEvent struct {
Channel string
Path string
Data json.RawMessage
}
// PublishReply is a reaction to PublishEvent.
type PublishReply struct {
// By default, it's a handler responsibility to publish data
// into a stream upon OnPublish but setting Fallthrough to true
// will make Grafana Live publish data itself (i.e. stream handler
// just works as permission proxy in this case).
Data json.RawMessage
// HistorySize sets a stream history size.
HistorySize int
HistoryTTL time.Duration
// HistoryTTL is a time that messages will live in stream history.
HistoryTTL time.Duration
}
// ChannelHandler defines the core channel behavior
type ChannelHandler interface {
// OnSubscribe is called when a client wants to subscribe to a channel
OnSubscribe(ctx context.Context, user *SignedInUser, e SubscribeEvent) (SubscribeReply, bool, error)
OnSubscribe(ctx context.Context, user *SignedInUser, e SubscribeEvent) (SubscribeReply, backend.SubscribeStreamStatus, error)
// OnPublish is called when a client writes a message to the channel websocket.
OnPublish(ctx context.Context, user *SignedInUser, e PublishEvent) (PublishReply, bool, error)
OnPublish(ctx context.Context, user *SignedInUser, e PublishEvent) (PublishReply, backend.PublishStreamStatus, error)
}
// ChannelHandlerFactory should be implemented by all core features.