#41993: make it possible to create N random60hz channels (#43295)

pull/43309/head
Artur Wierzbicki 3 years ago committed by GitHub
parent 70c0a9d117
commit 197f4f81f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      pkg/services/live/pipeline/devdata.go
  2. 21
      pkg/tsdb/testdatasource/stream_handler.go

@ -99,7 +99,7 @@ type DevRuleBuilder struct {
func (f *DevRuleBuilder) BuildRules(_ context.Context, _ int64) ([]*LiveChannelRule, error) {
return []*LiveChannelRule{
{
Pattern: "plugin/testdata/random-20Hz-stream",
Pattern: "plugin/testdata/random-20Hz-stream:rest",
DataOutputters: []DataOutputter{
NewLokiDataOutput(
os.Getenv("GF_LIVE_LOKI_ENDPOINT"),

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/rand"
"regexp"
"strings"
"time"
@ -11,6 +12,8 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data"
)
var random20HzStreamRegex = regexp.MustCompile(`random-20Hz-stream(-\d+)?`)
func (s *Service) SubscribeStream(_ context.Context, req *backend.SubscribeStreamRequest) (*backend.SubscribeStreamResponse, error) {
s.logger.Debug("Allowing access to stream", "path", req.Path, "user", req.PluginContext.User)
initialData, err := backend.NewInitialFrame(s.frame, data.IncludeSchemaOnly)
@ -55,31 +58,31 @@ func (s *Service) PublishStream(_ context.Context, req *backend.PublishStreamReq
func (s *Service) RunStream(ctx context.Context, request *backend.RunStreamRequest, sender *backend.StreamSender) error {
s.logger.Debug("New stream call", "path", request.Path)
var conf testStreamConfig
switch request.Path {
case "random-2s-stream":
switch {
case request.Path == "random-2s-stream":
conf = testStreamConfig{
Interval: 2 * time.Second,
}
case "random-flakey-stream":
case request.Path == "random-flakey-stream":
conf = testStreamConfig{
Interval: 100 * time.Millisecond,
Drop: 0.75, // keep 25%
}
case "random-labeled-stream":
case request.Path == "random-labeled-stream":
conf = testStreamConfig{
Interval: 200 * time.Millisecond,
Drop: 0.2, // keep 80%
Labeled: true,
}
case "random-20Hz-stream":
conf = testStreamConfig{
Interval: 50 * time.Millisecond,
}
case "flight-5hz-stream":
case request.Path == "flight-5hz-stream":
conf = testStreamConfig{
Interval: 200 * time.Millisecond,
Flight: newFlightConfig(),
}
case random20HzStreamRegex.MatchString(request.Path):
conf = testStreamConfig{
Interval: 50 * time.Millisecond,
}
default:
return fmt.Errorf("testdata plugin does not support path: %s", request.Path)
}

Loading…
Cancel
Save