@@ -1429,72 +1429,159 @@ func TestCookieJar(t *testing.T) {
1429
1429
}
1430
1430
1431
1431
func TestSkipResolvePhase (t * testing.T ) {
1432
- if testing .Short () {
1433
- t .Skip ("skipping network dependent test" )
1434
- }
1435
- ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1436
- w .WriteHeader (http .StatusNoContent )
1437
- }))
1438
- defer ts .Close ()
1439
-
1440
- t .Run ("Without Proxy" , func (t * testing.T ) {
1441
- registry := prometheus .NewRegistry ()
1442
- testCTX , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
1443
- defer cancel ()
1444
- result := ProbeHTTP (testCTX , ts .URL ,
1445
- config.Module {Timeout : time .Second , HTTP : config.HTTPProbe {IPProtocolFallback : true , HTTPClientConfig : pconfig .DefaultHTTPClientConfig , SkipResolvePhaseWithProxy : true }}, registry , log .NewNopLogger ())
1446
- if ! result {
1447
- t .Fatalf ("Probe unsuccessful" )
1448
- }
1449
- mfs , err := registry .Gather ()
1450
- if err != nil {
1451
- t .Fatal (err )
1452
- }
1453
- expectedMetrics := map [string ]map [string ]map [string ]struct {}{
1454
- "probe_http_duration_seconds" : {
1455
- "phase" : {
1456
- "connect" : {},
1457
- "processing" : {},
1458
- "resolve" : {},
1459
- "transfer" : {},
1460
- "tls" : {},
1461
- },
1462
- },
1463
- }
1464
-
1465
- checkMetrics (expectedMetrics , mfs , t )
1466
- })
1467
- t .Run ("With Proxy" , func (t * testing.T ) {
1468
- registry := prometheus .NewRegistry ()
1469
- testCTX , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
1470
- defer cancel ()
1471
- httpCfg := pconfig .DefaultHTTPClientConfig
1472
- u , err := url .Parse ("http://127.0.0.1:3128" )
1473
- if err != nil {
1474
- t .Fatalf (err .Error ())
1475
- }
1476
- httpCfg .ProxyURL = pconfig.URL {
1477
- URL : u ,
1478
- }
1479
- ProbeHTTP (testCTX , ts .URL ,
1480
- config.Module {Timeout : time .Second , HTTP : config.HTTPProbe {IPProtocolFallback : true , HTTPClientConfig : httpCfg , SkipResolvePhaseWithProxy : true }}, registry , log .NewNopLogger ())
1481
- mfs , err := registry .Gather ()
1482
- if err != nil {
1483
- t .Fatal (err )
1484
- }
1485
- expectedMetrics := map [string ]map [string ]map [string ]struct {}{
1486
- "probe_http_duration_seconds" : {
1487
- "phase" : {
1488
- "connect" : {},
1489
- "processing" : {},
1490
- "transfer" : {},
1491
- "tls" : {},
1492
- },
1493
- },
1494
- }
1495
-
1496
- checkMetrics (expectedMetrics , mfs , t )
1497
- })
1432
+ if testing .Short () {
1433
+ t .Skip ("skipping network dependent test" )
1434
+ }
1435
+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1436
+ w .WriteHeader (http .StatusNoContent )
1437
+ }))
1438
+ defer ts .Close ()
1439
+
1440
+ // Note: just tested, if local resolve is done or not via metrics. No proxy with diffent resolving available.
1441
+
1442
+ t .Run ("Without Proxy" , func (t * testing.T ) {
1443
+ registry := prometheus .NewRegistry ()
1444
+ testCTX , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
1445
+ defer cancel ()
1446
+ result := ProbeHTTP (testCTX , ts .URL ,
1447
+ config.Module {Timeout : time .Second , HTTP : config.HTTPProbe {IPProtocolFallback : true , HTTPClientConfig : pconfig .DefaultHTTPClientConfig , SkipResolvePhaseWithProxy : true }}, registry , promslog .NewNopLogger ())
1448
+ if ! result {
1449
+ t .Fatalf ("Probe unsuccessful" )
1450
+ }
1451
+ mfs , err := registry .Gather ()
1452
+ if err != nil {
1453
+ t .Fatal (err )
1454
+ }
1455
+ expectedMetrics := map [string ]map [string ]map [string ]struct {}{
1456
+ "probe_http_duration_seconds" : {
1457
+ "phase" : {
1458
+ "connect" : {},
1459
+ "processing" : {},
1460
+ "resolve" : {},
1461
+ "transfer" : {},
1462
+ "tls" : {},
1463
+ },
1464
+ },
1465
+ }
1466
+
1467
+ checkMetrics (expectedMetrics , mfs , t )
1468
+ })
1469
+ t .Run ("With Proxy and resolve" , func (t * testing.T ) {
1470
+ registry := prometheus .NewRegistry ()
1471
+ testCTX , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
1472
+ defer cancel ()
1473
+ httpCfg := pconfig .DefaultHTTPClientConfig
1474
+ u , err := url .Parse ("http://127.0.0.1:3128" )
1475
+ if err != nil {
1476
+ t .Fatal (err .Error ())
1477
+ }
1478
+ httpCfg .ProxyURL = pconfig.URL {
1479
+ URL : u ,
1480
+ }
1481
+ ProbeHTTP (testCTX , ts .URL ,
1482
+ config.Module {Timeout : time .Second , HTTP : config.HTTPProbe {IPProtocolFallback : true , HTTPClientConfig : httpCfg , SkipResolvePhaseWithProxy : false }}, registry , promslog .NewNopLogger ())
1483
+ mfs , err := registry .Gather ()
1484
+ if err != nil {
1485
+ t .Fatal (err )
1486
+ }
1487
+ expectedMetrics := map [string ]map [string ]map [string ]struct {}{
1488
+ "probe_http_duration_seconds" : {
1489
+ "phase" : {
1490
+ "connect" : {},
1491
+ "processing" : {},
1492
+ "resolve" : {},
1493
+ "transfer" : {},
1494
+ "tls" : {},
1495
+ },
1496
+ },
1497
+ }
1498
+
1499
+ checkMetrics (expectedMetrics , mfs , t )
1500
+ })
1501
+ t .Run ("With Proxy and without resolve" , func (t * testing.T ) {
1502
+ registry := prometheus .NewRegistry ()
1503
+ testCTX , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
1504
+ defer cancel ()
1505
+ httpCfg := pconfig .DefaultHTTPClientConfig
1506
+ u , err := url .Parse ("http://127.0.0.1:3128" )
1507
+ if err != nil {
1508
+ t .Fatal (err .Error ())
1509
+ }
1510
+ httpCfg .ProxyURL = pconfig.URL {
1511
+ URL : u ,
1512
+ }
1513
+ ProbeHTTP (testCTX , ts .URL ,
1514
+ config.Module {Timeout : time .Second , HTTP : config.HTTPProbe {IPProtocolFallback : true , HTTPClientConfig : httpCfg , SkipResolvePhaseWithProxy : true }}, registry , promslog .NewNopLogger ())
1515
+ mfs , err := registry .Gather ()
1516
+ if err != nil {
1517
+ t .Fatal (err )
1518
+ }
1519
+ expectedMetrics := map [string ]map [string ]map [string ]struct {}{
1520
+ "probe_http_duration_seconds" : {
1521
+ "phase" : {
1522
+ "connect" : {},
1523
+ "processing" : {},
1524
+ "transfer" : {},
1525
+ "tls" : {},
1526
+ },
1527
+ },
1528
+ }
1529
+
1530
+ checkMetrics (expectedMetrics , mfs , t )
1531
+ })
1532
+ t .Run ("With Proxy from env var and without resolve" , func (t * testing.T ) {
1533
+ registry := prometheus .NewRegistry ()
1534
+ testCTX , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
1535
+ defer cancel ()
1536
+ t .Setenv ("HTTP_PROXY" , "http://127.0.0.1:3128" )
1537
+ httpCfg := pconfig .DefaultHTTPClientConfig
1538
+ httpCfg .ProxyFromEnvironment = true
1539
+ ProbeHTTP (testCTX , ts .URL ,
1540
+ config.Module {Timeout : time .Second , HTTP : config.HTTPProbe {IPProtocolFallback : true , HTTPClientConfig : httpCfg , SkipResolvePhaseWithProxy : true }}, registry , promslog .NewNopLogger ())
1541
+ mfs , err := registry .Gather ()
1542
+ if err != nil {
1543
+ t .Fatal (err )
1544
+ }
1545
+ expectedMetrics := map [string ]map [string ]map [string ]struct {}{
1546
+ "probe_http_duration_seconds" : {
1547
+ "phase" : {
1548
+ "connect" : {},
1549
+ "processing" : {},
1550
+ "transfer" : {},
1551
+ "tls" : {},
1552
+ },
1553
+ },
1554
+ }
1555
+
1556
+ checkMetrics (expectedMetrics , mfs , t )
1557
+ })
1558
+ t .Run ("With Proxy from env var and with resolve" , func (t * testing.T ) {
1559
+ registry := prometheus .NewRegistry ()
1560
+ testCTX , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
1561
+ defer cancel ()
1562
+ t .Setenv ("HTTP_PROXY" , "http://127.0.0.1:3128" )
1563
+ httpCfg := pconfig .DefaultHTTPClientConfig
1564
+ httpCfg .ProxyFromEnvironment = true
1565
+ ProbeHTTP (testCTX , ts .URL ,
1566
+ config.Module {Timeout : time .Second , HTTP : config.HTTPProbe {IPProtocolFallback : true , HTTPClientConfig : httpCfg , SkipResolvePhaseWithProxy : false }}, registry , promslog .NewNopLogger ())
1567
+ mfs , err := registry .Gather ()
1568
+ if err != nil {
1569
+ t .Fatal (err )
1570
+ }
1571
+ expectedMetrics := map [string ]map [string ]map [string ]struct {}{
1572
+ "probe_http_duration_seconds" : {
1573
+ "phase" : {
1574
+ "connect" : {},
1575
+ "processing" : {},
1576
+ "resolve" : {},
1577
+ "transfer" : {},
1578
+ "tls" : {},
1579
+ },
1580
+ },
1581
+ }
1582
+
1583
+ checkMetrics (expectedMetrics , mfs , t )
1584
+ })
1498
1585
}
1499
1586
1500
1587
func TestBody (t * testing.T ) {
0 commit comments