@@ -3428,6 +3428,45 @@ func TestHTTPSendMetrics(t *testing.T) {
34283428 t .Fatalf ("expected %d cache hits, got %d" , exp , act )
34293429 }
34303430 })
3431+
3432+ t .Run ("network requests" , func (t * testing.T ) {
3433+ // Test that network requests counter is incremented correctly
3434+ m := metrics .New ()
3435+
3436+ // Test 1: Single request - verify counter increments
3437+ q := NewQuery (ast .MustParseBody (fmt .Sprintf (`http.send({"method": "get", "url": %q})` , ts .URL ))).WithMetrics (m )
3438+ _ , err := q .Run (context .Background ())
3439+ if err != nil {
3440+ t .Fatal (err )
3441+ }
3442+
3443+ if exp , act := uint64 (1 ), m .Counter (httpSendNetworkRequests ).Value (); exp != act {
3444+ t .Fatalf ("expected %d network requests, got %d" , exp , act )
3445+ }
3446+
3447+ // Test 2: Another request to different URL
3448+ q2 := NewQuery (ast .MustParseBody (fmt .Sprintf (`http.send({"method": "get", "url": %q})` , ts .URL + "/other" ))).WithMetrics (m )
3449+ _ , err = q2 .Run (context .Background ())
3450+ if err != nil {
3451+ t .Fatal (err )
3452+ }
3453+
3454+ if exp , act := uint64 (2 ), m .Counter (httpSendNetworkRequests ).Value (); exp != act {
3455+ t .Fatalf ("expected %d network requests, got %d" , exp , act )
3456+ }
3457+
3458+ // Test 3: Request with error should still increment counter
3459+ badURL := "http://localhost:1" // Port 1 should fail quickly
3460+ q3 := NewQuery (ast .MustParseBody (fmt .Sprintf (`http.send({"method": "get", "url": %q, "raise_error": false})` , badURL ))).WithMetrics (m )
3461+ _ , err = q3 .Run (context .Background ())
3462+ if err != nil {
3463+ t .Fatal (err )
3464+ }
3465+
3466+ if exp , act := uint64 (3 ), m .Counter (httpSendNetworkRequests ).Value (); exp != act {
3467+ t .Fatalf ("expected %d network requests including failed one, got %d" , exp , act )
3468+ }
3469+ })
34313470}
34323471
34333472// Warning(philipc): This test cannot be run in parallel with other tests, due
0 commit comments