5
5
"context"
6
6
"errors"
7
7
"fmt"
8
+ "math/rand"
8
9
"net/http"
9
10
"net/http/httptest"
10
11
"os"
@@ -789,6 +790,7 @@ func TestPush_ShuffleSharding(t *testing.T) {
789
790
}
790
791
791
792
func TestPush_Aggregation (t * testing.T ) {
793
+ const maxSessions = 16
792
794
ingesterClient := newFakeIngester (t , false )
793
795
d , err := New (
794
796
Config {DistributorRing : ringConfig , PushTimeout : time .Second * 10 },
@@ -798,6 +800,7 @@ func TestPush_Aggregation(t *testing.T) {
798
800
l := validation .MockDefaultLimits ()
799
801
l .DistributorAggregationPeriod = model .Duration (time .Second )
800
802
l .DistributorAggregationWindow = model .Duration (time .Second )
803
+ l .MaxSessionsPerSeries = maxSessions
801
804
tenantLimits ["user-1" ] = l
802
805
}),
803
806
nil , log .NewLogfmtLogger (os .Stdout ),
@@ -824,6 +827,10 @@ func TestPush_Aggregation(t *testing.T) {
824
827
{Name : "cluster" , Value : "us-central1" },
825
828
{Name : "client" , Value : strconv .Itoa (i )},
826
829
{Name : "__name__" , Value : "cpu" },
830
+ {
831
+ Name : phlaremodel .LabelNameSessionID ,
832
+ Value : phlaremodel .SessionID (rand .Uint64 ()).String (),
833
+ },
827
834
},
828
835
Samples : []* distributormodel.ProfileSample {
829
836
{
@@ -844,11 +851,13 @@ func TestPush_Aggregation(t *testing.T) {
844
851
d .asyncRequests .Wait ()
845
852
846
853
var sum int64
854
+ sessions := make (map [string ]struct {})
847
855
assert .GreaterOrEqual (t , len (ingesterClient .requests ), 20 )
848
856
assert .Less (t , len (ingesterClient .requests ), 100 )
849
857
for _ , r := range ingesterClient .requests {
850
858
for _ , s := range r .Series {
851
- require .Len (t , s .Samples , 1 )
859
+ sessionID := phlaremodel .Labels (s .Labels ).Get (phlaremodel .LabelNameSessionID )
860
+ sessions [sessionID ] = struct {}{}
852
861
p , err := pprof2 .RawFromBytes (s .Samples [0 ].RawProfile )
853
862
require .NoError (t , err )
854
863
for _ , x := range p .Sample {
@@ -859,6 +868,8 @@ func TestPush_Aggregation(t *testing.T) {
859
868
860
869
// RF * samples_per_profile * clients * requests
861
870
assert .Equal (t , int64 (3 * 2 * clients * requests ), sum )
871
+ assert .GreaterOrEqual (t , len (sessions ), clients )
872
+ assert .LessOrEqual (t , len (sessions ), maxSessions + 1 )
862
873
}
863
874
864
875
func testProfile (t int64 ) * profilev1.Profile {
0 commit comments