@@ -13,6 +13,8 @@ import (
1313
1414 "github.com/stretchr/testify/assert"
1515 "github.com/stretchr/testify/require"
16+
17+ "github.com/grafana/pyroscope/pkg/pprof/testhelper"
1618)
1719
1820type Request struct {
@@ -851,7 +853,7 @@ func TestStatusCodes(t *testing.T) {
851853 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
852854 "end" : time .Now ().UnixMilli (),
853855 }),
854- WantV1StatusCode : http .StatusOK ,
856+ WantV1StatusCode : http .StatusInternalServerError ,
855857 },
856858 {
857859 Name : "invalid_json" ,
@@ -1044,7 +1046,7 @@ func TestStatusCodes(t *testing.T) {
10441046 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
10451047 "end" : time .Now ().UnixMilli (),
10461048 }),
1047- WantV1StatusCode : http .StatusOK ,
1049+ WantV1StatusCode : http .StatusInternalServerError ,
10481050 },
10491051 },
10501052 http .StatusMethodNotAllowed : {
@@ -1198,7 +1200,7 @@ func TestStatusCodes(t *testing.T) {
11981200 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
11991201 "end" : time .Now ().UnixMilli (),
12001202 }),
1201- WantV1StatusCode : http .StatusOK ,
1203+ WantV1StatusCode : http .StatusInternalServerError ,
12021204 },
12031205 },
12041206 http .StatusMethodNotAllowed : {
@@ -2307,7 +2309,7 @@ func TestStatusCodes(t *testing.T) {
23072309 "labelSelector" : "{}" ,
23082310 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
23092311 "end" : time .Now ().UnixMilli (),
2310- "spanSelector" : []string {"span1 " , "span2 " },
2312+ "spanSelector" : []string {"0123456789012345 " , "0123456789012346 " },
23112313 }),
23122314 },
23132315 {
@@ -2321,7 +2323,7 @@ func TestStatusCodes(t *testing.T) {
23212323 "labelSelector" : "{}" ,
23222324 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
23232325 "end" : time .Now ().UnixMilli (),
2324- "spanSelector" : []string {"span1 " },
2326+ "spanSelector" : []string {"0123456789012345 " },
23252327 "maxNodes" : 1024 ,
23262328 }),
23272329 },
@@ -2336,7 +2338,7 @@ func TestStatusCodes(t *testing.T) {
23362338 "labelSelector" : "{}" ,
23372339 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
23382340 "end" : time .Now ().UnixMilli (),
2339- "spanSelector" : []string {"span1 " },
2341+ "spanSelector" : []string {"0123456789012345 " },
23402342 "format" : 2 ,
23412343 }),
23422344 },
@@ -2352,7 +2354,7 @@ func TestStatusCodes(t *testing.T) {
23522354 "labelSelector" : "{}" ,
23532355 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
23542356 "end" : time .Now ().UnixMilli (),
2355- "spanSelector" : []string {"span1 " },
2357+ "spanSelector" : []string {"0123456789012345 " },
23562358 }),
23572359 },
23582360 {
@@ -2366,7 +2368,7 @@ func TestStatusCodes(t *testing.T) {
23662368 "labelSelector" : "{}" ,
23672369 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
23682370 "end" : time .Now ().UnixMilli (),
2369- "spanSelector" : []string {"span1 " },
2371+ "spanSelector" : []string {"0123456789012345 " },
23702372 }),
23712373 },
23722374 {
@@ -2380,7 +2382,7 @@ func TestStatusCodes(t *testing.T) {
23802382 "labelSelector" : "{}" ,
23812383 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
23822384 "end" : time .Now ().UnixMilli (),
2383- "spanSelector" : []string {"span1 " },
2385+ "spanSelector" : []string {"0123456789012345 " },
23842386 }),
23852387 },
23862388 {
@@ -2393,7 +2395,7 @@ func TestStatusCodes(t *testing.T) {
23932395 "profileTypeID" : profileTypeProcessCPU ,
23942396 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
23952397 "end" : time .Now ().UnixMilli (),
2396- "spanSelector" : []string {"span1 " },
2398+ "spanSelector" : []string {"0123456789012345 " },
23972399 }),
23982400 },
23992401 {
@@ -2407,7 +2409,7 @@ func TestStatusCodes(t *testing.T) {
24072409 "labelSelector" : "!bad_syntax!" ,
24082410 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
24092411 "end" : time .Now ().UnixMilli (),
2410- "spanSelector" : []string {"span1 " },
2412+ "spanSelector" : []string {"0123456789012345 " },
24112413 }),
24122414 },
24132415 {
@@ -2437,7 +2439,7 @@ func TestStatusCodes(t *testing.T) {
24372439 "labelSelector" : "{}" ,
24382440 "start" : time .Now ().UnixMilli (),
24392441 "end" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
2440- "spanSelector" : []string {"span1 " },
2442+ "spanSelector" : []string {"0123456789012345 " },
24412443 }),
24422444 },
24432445 {
@@ -2449,7 +2451,7 @@ func TestStatusCodes(t *testing.T) {
24492451 Body : toJSON (map [string ]any {
24502452 "profileTypeID" : profileTypeProcessCPU ,
24512453 "labelSelector" : "{}" ,
2452- "spanSelector" : []string {"span1 " },
2454+ "spanSelector" : []string {"0123456789012345 " },
24532455 }),
24542456 },
24552457 },
@@ -2472,7 +2474,7 @@ func TestStatusCodes(t *testing.T) {
24722474 "labelSelector" : "{}" ,
24732475 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
24742476 "end" : time .Now ().UnixMilli (),
2475- "spanSelector" : []string {"span1 " },
2477+ "spanSelector" : []string {"0123456789012345 " },
24762478 }),
24772479 },
24782480 {
@@ -2486,7 +2488,7 @@ func TestStatusCodes(t *testing.T) {
24862488 "labelSelector" : "{}" ,
24872489 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
24882490 "end" : time .Now ().UnixMilli (),
2489- "spanSelector" : []string {"span1 " },
2491+ "spanSelector" : []string {"0123456789012345 " },
24902492 }),
24912493 },
24922494 {
@@ -2500,7 +2502,7 @@ func TestStatusCodes(t *testing.T) {
25002502 "labelSelector" : "{}" ,
25012503 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
25022504 "end" : time .Now ().UnixMilli (),
2503- "spanSelector" : []string {"span1 " },
2505+ "spanSelector" : []string {"0123456789012345 " },
25042506 }),
25052507 },
25062508 },
@@ -2516,7 +2518,7 @@ func TestStatusCodes(t *testing.T) {
25162518 "labelSelector" : "{}" ,
25172519 "start" : time .Now ().Add (- 1 * time .Hour ).UnixMilli (),
25182520 "end" : time .Now ().UnixMilli (),
2519- "spanSelector" : []string {"span1 " },
2521+ "spanSelector" : []string {"0123456789012345 " },
25202522 }),
25212523 },
25222524 },
@@ -2538,6 +2540,18 @@ func TestStatusCodes(t *testing.T) {
25382540 }
25392541
25402542 EachPyroscopeTest (t , func (p * PyroscopeTest , t * testing.T ) {
2543+ // Ingest a minimal profile so the head's time range covers [now-1h, now].
2544+ // Without this, the head has Bounds() = (0,0) and ForTimeRange excludes it,
2545+ // meaning invalid matchers are never parsed and always return 200.
2546+ rb := p .NewRequestBuilder (t )
2547+ profileBytes , err := testhelper .NewProfileBuilder (time .Now ().Add (- time .Second ).UnixNano ()).
2548+ CPUProfile ().
2549+ ForStacktraceString ("foo" , "bar" ).
2550+ AddSamples (1 ).
2551+ MarshalVT ()
2552+ require .NoError (t , err )
2553+ rb .Push (rb .PushPPROFRequestFromBytes (profileBytes , "process_cpu" ), 200 , "" )
2554+
25412555 client := http .DefaultClient
25422556 isV1Test := strings .HasSuffix (t .Name (), "v1" )
25432557
0 commit comments