4
4
package adaptive
5
5
6
6
import (
7
- "context"
8
7
"errors"
9
8
"testing"
10
9
"time"
@@ -20,7 +19,6 @@ import (
20
19
"github.com/jaegertracing/jaeger/pkg/testutils"
21
20
epmocks "github.com/jaegertracing/jaeger/plugin/sampling/leaderelection/mocks"
22
21
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive/calculationstrategy"
23
- "github.com/jaegertracing/jaeger/proto-gen/api_v2"
24
22
smocks "github.com/jaegertracing/jaeger/storage/samplingstore/mocks"
25
23
)
26
24
@@ -405,113 +403,6 @@ func TestRunCalculationLoop_GetThroughputError(t *testing.T) {
405
403
require .NoError (t , agg .Close ())
406
404
}
407
405
408
- func TestLoadProbabilities (t * testing.T ) {
409
- mockStorage := & smocks.Store {}
410
- mockStorage .On ("GetLatestProbabilities" ).Return (make (model.ServiceOperationProbabilities ), nil )
411
-
412
- p := & Provider {storage : mockStorage }
413
- require .Nil (t , p .probabilities )
414
- p .loadProbabilities ()
415
- require .NotNil (t , p .probabilities )
416
- }
417
-
418
- func TestRunUpdateProbabilitiesLoop (t * testing.T ) {
419
- mockStorage := & smocks.Store {}
420
- mockStorage .On ("GetLatestProbabilities" ).Return (make (model.ServiceOperationProbabilities ), nil )
421
- mockEP := & epmocks.ElectionParticipant {}
422
- mockEP .On ("Start" ).Return (nil )
423
- mockEP .On ("Close" ).Return (nil )
424
- mockEP .On ("IsLeader" ).Return (false )
425
-
426
- p := & Provider {
427
- storage : mockStorage ,
428
- shutdown : make (chan struct {}),
429
- followerRefreshInterval : time .Millisecond ,
430
- electionParticipant : mockEP ,
431
- }
432
- defer close (p .shutdown )
433
- require .Nil (t , p .probabilities )
434
- require .Nil (t , p .strategyResponses )
435
- go p .runUpdateProbabilitiesLoop ()
436
-
437
- for i := 0 ; i < 1000 ; i ++ {
438
- p .RLock ()
439
- if p .probabilities != nil && p .strategyResponses != nil {
440
- p .RUnlock ()
441
- break
442
- }
443
- p .RUnlock ()
444
- time .Sleep (time .Millisecond )
445
- }
446
- p .RLock ()
447
- assert .NotNil (t , p .probabilities )
448
- assert .NotNil (t , p .strategyResponses )
449
- p .RUnlock ()
450
- }
451
-
452
- func TestRealisticRunCalculationLoop (t * testing.T ) {
453
- t .Skip ("Skipped realistic calculation loop test" )
454
- logger := zap .NewNop ()
455
- // NB: This is an extremely long test since it uses near realistic (1/6th scale) processor config values
456
- testThroughputs := []* model.Throughput {
457
- {Service : "svcA" , Operation : "GET" , Count : 10 },
458
- {Service : "svcA" , Operation : "POST" , Count : 9 },
459
- {Service : "svcA" , Operation : "PUT" , Count : 5 },
460
- {Service : "svcA" , Operation : "DELETE" , Count : 20 },
461
- }
462
- mockStorage := & smocks.Store {}
463
- mockStorage .On ("GetThroughput" , mock .AnythingOfType ("time.Time" ), mock .AnythingOfType ("time.Time" )).
464
- Return (testThroughputs , nil )
465
- mockStorage .On ("GetLatestProbabilities" ).Return (make (model.ServiceOperationProbabilities ), nil )
466
- mockStorage .On ("InsertProbabilitiesAndQPS" , "host" , mock .AnythingOfType ("model.ServiceOperationProbabilities" ),
467
- mock .AnythingOfType ("model.ServiceOperationQPS" )).Return (nil )
468
- mockEP := & epmocks.ElectionParticipant {}
469
- mockEP .On ("Start" ).Return (nil )
470
- mockEP .On ("Close" ).Return (nil )
471
- mockEP .On ("IsLeader" ).Return (true )
472
- cfg := Options {
473
- TargetSamplesPerSecond : 1.0 ,
474
- DeltaTolerance : 0.2 ,
475
- InitialSamplingProbability : 0.001 ,
476
- CalculationInterval : time .Second * 10 ,
477
- AggregationBuckets : 1 ,
478
- Delay : time .Second * 10 ,
479
- }
480
- s := NewProvider (cfg , logger , mockEP , mockStorage )
481
- s .Start ()
482
-
483
- for i := 0 ; i < 100 ; i ++ {
484
- strategy , _ := s .GetSamplingStrategy (context .Background (), "svcA" )
485
- if len (strategy .OperationSampling .PerOperationStrategies ) != 0 {
486
- break
487
- }
488
- time .Sleep (250 * time .Millisecond )
489
- }
490
- s .Close ()
491
-
492
- strategy , err := s .GetSamplingStrategy (context .Background (), "svcA" )
493
- require .NoError (t , err )
494
- require .Len (t , strategy .OperationSampling .PerOperationStrategies , 4 )
495
- strategies := strategy .OperationSampling .PerOperationStrategies
496
-
497
- for _ , s := range strategies {
498
- switch s .Operation {
499
- case "GET" :
500
- assert .Equal (t , 0.001 , s .ProbabilisticSampling .SamplingRate ,
501
- "Already at 1QPS, no probability change" )
502
- case "POST" :
503
- assert .Equal (t , 0.001 , s .ProbabilisticSampling .SamplingRate ,
504
- "Within epsilon of 1QPS, no probability change" )
505
- case "PUT" :
506
- assert .InEpsilon (t , 0.002 , s .ProbabilisticSampling .SamplingRate , 0.025 ,
507
- "Under sampled, double probability" )
508
- case "DELETE" :
509
- assert .InEpsilon (t , 0.0005 , s .ProbabilisticSampling .SamplingRate , 0.025 ,
510
- "Over sampled, halve probability" )
511
- }
512
- }
513
- }
514
-
515
406
func TestPrependBucket (t * testing.T ) {
516
407
p := & PostAggregator {Options : Options {AggregationBuckets : 1 }}
517
408
p .prependThroughputBucket (& throughputBucket {interval : time .Minute })
@@ -547,41 +438,6 @@ func TestConstructorFailure(t *testing.T) {
547
438
require .EqualError (t , err , "BucketsForCalculation cannot be less than 1" )
548
439
}
549
440
550
- func TestGenerateStrategyResponses (t * testing.T ) {
551
- probabilities := model.ServiceOperationProbabilities {
552
- "svcA" : map [string ]float64 {
553
- "GET" : 0.5 ,
554
- },
555
- }
556
- p := & Provider {
557
- probabilities : probabilities ,
558
- Options : Options {
559
- InitialSamplingProbability : 0.001 ,
560
- MinSamplesPerSecond : 0.0001 ,
561
- },
562
- }
563
- p .generateStrategyResponses ()
564
-
565
- expectedResponse := map [string ]* api_v2.SamplingStrategyResponse {
566
- "svcA" : {
567
- StrategyType : api_v2 .SamplingStrategyType_PROBABILISTIC ,
568
- OperationSampling : & api_v2.PerOperationSamplingStrategies {
569
- DefaultSamplingProbability : 0.001 ,
570
- DefaultLowerBoundTracesPerSecond : 0.0001 ,
571
- PerOperationStrategies : []* api_v2.OperationSamplingStrategy {
572
- {
573
- Operation : "GET" ,
574
- ProbabilisticSampling : & api_v2.ProbabilisticSamplingStrategy {
575
- SamplingRate : 0.5 ,
576
- },
577
- },
578
- },
579
- },
580
- },
581
- }
582
- assert .Equal (t , expectedResponse , p .strategyResponses )
583
- }
584
-
585
441
func TestUsingAdaptiveSampling (t * testing.T ) {
586
442
p := & PostAggregator {}
587
443
throughput := serviceOperationThroughput {
0 commit comments