Chore: Remove live from models (#61711)

This commit is contained in:
idafurjes
2023-01-19 10:03:14 +01:00
committed by GitHub
parent 0d42edddbf
commit cacc55ba06
16 changed files with 216 additions and 129 deletions

View File

@@ -4,8 +4,8 @@ import (
"context"
"errors"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/live/livecontext"
"github.com/grafana/grafana/pkg/services/live/model"
"github.com/grafana/grafana-plugin-sdk-go/backend"
)
@@ -33,7 +33,7 @@ func (s *BuiltinDataOutput) OutputData(ctx context.Context, vars Vars, data []by
if err != nil {
return nil, err
}
_, status, err := handler.OnPublish(ctx, u, models.PublishEvent{
_, status, err := handler.OnPublish(ctx, u, model.PublishEvent{
Channel: vars.Channel,
Data: data,
})

View File

@@ -6,7 +6,7 @@ import (
"fmt"
"os"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/live/model"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana-plugin-sdk-go/backend"
@@ -108,7 +108,7 @@ type FrameOutputter interface {
// Subscriber can handle channel subscribe events.
type Subscriber interface {
Type() string
Subscribe(ctx context.Context, vars Vars, data []byte) (models.SubscribeReply, backend.SubscribeStreamStatus, error)
Subscribe(ctx context.Context, vars Vars, data []byte) (model.SubscribeReply, backend.SubscribeStreamStatus, error)
}
// PublishAuthChecker checks whether current user can publish to a channel.

View File

@@ -3,8 +3,8 @@ package pipeline
import (
"context"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/live/livecontext"
"github.com/grafana/grafana/pkg/services/live/model"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana-plugin-sdk-go/backend"
@@ -16,7 +16,7 @@ type BuiltinSubscriber struct {
}
type ChannelHandlerGetter interface {
GetChannelHandler(ctx context.Context, user *user.SignedInUser, channel string) (models.ChannelHandler, live.Channel, error)
GetChannelHandler(ctx context.Context, user *user.SignedInUser, channel string) (model.ChannelHandler, live.Channel, error)
}
const SubscriberTypeBuiltin = "builtin"
@@ -29,16 +29,16 @@ func (s *BuiltinSubscriber) Type() string {
return SubscriberTypeBuiltin
}
func (s *BuiltinSubscriber) Subscribe(ctx context.Context, vars Vars, data []byte) (models.SubscribeReply, backend.SubscribeStreamStatus, error) {
func (s *BuiltinSubscriber) Subscribe(ctx context.Context, vars Vars, data []byte) (model.SubscribeReply, backend.SubscribeStreamStatus, error) {
u, ok := livecontext.GetContextSignedUser(ctx)
if !ok {
return models.SubscribeReply{}, backend.SubscribeStreamStatusPermissionDenied, nil
return model.SubscribeReply{}, backend.SubscribeStreamStatusPermissionDenied, nil
}
handler, _, err := s.channelHandlerGetter.GetChannelHandler(ctx, u, vars.Channel)
if err != nil {
return models.SubscribeReply{}, 0, err
return model.SubscribeReply{}, 0, err
}
return handler.OnSubscribe(ctx, u, models.SubscribeEvent{
return handler.OnSubscribe(ctx, u, model.SubscribeEvent{
Channel: vars.Channel,
Path: vars.Path,
Data: data,

View File

@@ -5,9 +5,9 @@ import (
"github.com/grafana/grafana/pkg/services/live/livecontext"
"github.com/grafana/grafana/pkg/services/live/managedstream"
"github.com/grafana/grafana/pkg/services/live/model"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/models"
)
type ManagedStreamSubscriber struct {
@@ -24,17 +24,17 @@ func (s *ManagedStreamSubscriber) Type() string {
return SubscriberTypeManagedStream
}
func (s *ManagedStreamSubscriber) Subscribe(ctx context.Context, vars Vars, _ []byte) (models.SubscribeReply, backend.SubscribeStreamStatus, error) {
func (s *ManagedStreamSubscriber) Subscribe(ctx context.Context, vars Vars, _ []byte) (model.SubscribeReply, backend.SubscribeStreamStatus, error) {
stream, err := s.managedStream.GetOrCreateStream(vars.OrgID, vars.Scope, vars.Namespace)
if err != nil {
logger.Error("Error getting managed stream", "error", err)
return models.SubscribeReply{}, 0, err
return model.SubscribeReply{}, 0, err
}
u, ok := livecontext.GetContextSignedUser(ctx)
if !ok {
return models.SubscribeReply{}, backend.SubscribeStreamStatusPermissionDenied, nil
return model.SubscribeReply{}, backend.SubscribeStreamStatusPermissionDenied, nil
}
return stream.OnSubscribe(ctx, u, models.SubscribeEvent{
return stream.OnSubscribe(ctx, u, model.SubscribeEvent{
Channel: vars.Channel,
Path: vars.Path,
})

View File

@@ -4,7 +4,7 @@ import (
"context"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/live/model"
)
type MultipleSubscriber struct {
@@ -21,16 +21,16 @@ func (s *MultipleSubscriber) Type() string {
return SubscriberTypeMultiple
}
func (s *MultipleSubscriber) Subscribe(ctx context.Context, vars Vars, data []byte) (models.SubscribeReply, backend.SubscribeStreamStatus, error) {
finalReply := models.SubscribeReply{}
func (s *MultipleSubscriber) Subscribe(ctx context.Context, vars Vars, data []byte) (model.SubscribeReply, backend.SubscribeStreamStatus, error) {
finalReply := model.SubscribeReply{}
for _, s := range s.Subscribers {
reply, status, err := s.Subscribe(ctx, vars, data)
if err != nil {
return models.SubscribeReply{}, 0, err
return model.SubscribeReply{}, 0, err
}
if status != backend.SubscribeStreamStatusOK {
return models.SubscribeReply{}, status, nil
return model.SubscribeReply{}, status, nil
}
if finalReply.Data == nil {
finalReply.Data = reply.Data