Testdata: add random labeled stream (#41932)
This commit is contained in:
@@ -27,6 +27,13 @@ func (s *Service) SubscribeStream(_ context.Context, req *backend.SubscribeStrea
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(req.Path, "-labeled") {
|
||||
initialData, err = backend.NewInitialFrame(s.labelFrame, data.IncludeSchemaOnly)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if s.cfg.FeatureToggles["live-pipeline"] {
|
||||
// While developing Live pipeline avoid sending initial data.
|
||||
initialData = nil
|
||||
@@ -58,6 +65,12 @@ func (s *Service) RunStream(ctx context.Context, request *backend.RunStreamReque
|
||||
Interval: 100 * time.Millisecond,
|
||||
Drop: 0.75, // keep 25%
|
||||
}
|
||||
case "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,
|
||||
@@ -77,6 +90,7 @@ type testStreamConfig struct {
|
||||
Interval time.Duration
|
||||
Drop float64
|
||||
Flight *flightConfig
|
||||
Labeled bool
|
||||
}
|
||||
|
||||
func (s *Service) runTestStream(ctx context.Context, path string, conf testStreamConfig, sender *backend.StreamSender) error {
|
||||
@@ -92,6 +106,12 @@ func (s *Service) runTestStream(ctx context.Context, path string, conf testStrea
|
||||
flight.append(conf.Flight.getNextPoint(time.Now()))
|
||||
}
|
||||
|
||||
labelFrame := data.NewFrame("labeled",
|
||||
data.NewField("labels", nil, make([]string, 2)),
|
||||
data.NewField("Time", nil, make([]time.Time, 2)),
|
||||
data.NewField("Value", nil, make([]float64, 2)),
|
||||
)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -116,12 +136,28 @@ func (s *Service) runTestStream(ctx context.Context, path string, conf testStrea
|
||||
delta := rand.Float64() - 0.5
|
||||
walker += delta
|
||||
|
||||
s.frame.Fields[0].Set(0, t)
|
||||
s.frame.Fields[1].Set(0, walker) // Value
|
||||
s.frame.Fields[2].Set(0, walker-((rand.Float64()*spread)+0.01)) // Min
|
||||
s.frame.Fields[3].Set(0, walker+((rand.Float64()*spread)+0.01)) // Max
|
||||
if err := sender.SendFrame(s.frame, mode); err != nil {
|
||||
return err
|
||||
if conf.Labeled {
|
||||
secA := t.Second() / 3
|
||||
secB := t.Second() / 7
|
||||
|
||||
labelFrame.Fields[0].Set(0, fmt.Sprintf("s=A,s=p%d,x=X", secA))
|
||||
labelFrame.Fields[1].Set(0, t)
|
||||
labelFrame.Fields[2].Set(0, walker)
|
||||
|
||||
labelFrame.Fields[0].Set(1, fmt.Sprintf("s=B,s=p%d,x=X", secB))
|
||||
labelFrame.Fields[1].Set(1, t)
|
||||
labelFrame.Fields[2].Set(1, walker+10)
|
||||
if err := sender.SendFrame(labelFrame, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
s.frame.Fields[0].Set(0, t)
|
||||
s.frame.Fields[1].Set(0, walker) // Value
|
||||
s.frame.Fields[2].Set(0, walker-((rand.Float64()*spread)+0.01)) // Min
|
||||
s.frame.Fields[3].Set(0, walker+((rand.Float64()*spread)+0.01)) // Max
|
||||
if err := sender.SendFrame(s.frame, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user