Skip to content

Commit ec070b7

Browse files
committed
use client timeout
1 parent 1bdc156 commit ec070b7

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

internal/collector/nginxossreceiver/internal/scraper/stubstatus/stub_status_scraper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func (s *NginxStubStatusScraper) ID() component.ID {
5959

6060
func (s *NginxStubStatusScraper) Start(_ context.Context, _ component.Host) error {
6161
httpClient := http.DefaultClient
62+
httpClient.Timeout = s.cfg.ClientConfig.Timeout
63+
6264
if strings.HasPrefix(s.cfg.APIDetails.Listen, "unix:") {
6365
httpClient.Transport = &http.Transport{
6466
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {

internal/collector/nginxplusreceiver/scraper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func newNginxPlusScraper(
4949
endpoint := strings.TrimPrefix(cfg.APIDetails.URL, "unix:")
5050
logger := settings.Logger
5151
logger.Info("Creating NGINX Plus scraper")
52+
5253
httpClient := http.DefaultClient
54+
httpClient.Timeout = cfg.ClientConfig.Timeout
5355

5456
mb := metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings)
5557
rb := mb.NewResourceBuilder()

internal/watcher/instance/nginx_config_parser.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,14 @@ func (ncp *NginxConfigParser) apiCallback(ctx context.Context, parent,
479479
func (ncp *NginxConfigParser) pingAPIEndpoint(ctx context.Context, statusAPIDetail *model.APIDetails,
480480
apiType string,
481481
) bool {
482-
httpClient := http.Client{}
482+
httpClient := http.DefaultClient
483483
listen := statusAPIDetail.Listen
484484
statusAPI := statusAPIDetail.URL
485485

486486
if strings.HasPrefix(listen, "unix:") {
487487
httpClient = ncp.SocketClient(strings.TrimPrefix(listen, "unix:"))
488488
} else {
489-
httpClient = http.Client{Timeout: ncp.agentConfig.Client.Grpc.KeepAlive.Timeout}
489+
httpClient.Timeout = ncp.agentConfig.Client.HTTP.Timeout
490490
}
491491
req, err := http.NewRequestWithContext(ctx, http.MethodGet, statusAPI, nil)
492492
if err != nil {
@@ -676,8 +676,8 @@ func (ncp *NginxConfigParser) isPort(value string) bool {
676676
return err == nil && port >= 1 && port <= 65535
677677
}
678678

679-
func (ncp *NginxConfigParser) SocketClient(socketPath string) http.Client {
680-
return http.Client{
679+
func (ncp *NginxConfigParser) SocketClient(socketPath string) *http.Client {
680+
return &http.Client{
681681
Timeout: ncp.agentConfig.Client.Grpc.KeepAlive.Timeout,
682682
Transport: &http.Transport{
683683
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {

0 commit comments

Comments
 (0)