You've already forked nginx_exporter
mirror of
https://github.com/nginxinc/nginx-prometheus-exporter.git
synced 2025-08-06 17:42:38 +03:00
Add ctx to http request
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -43,7 +44,14 @@ func NewNginxClient(httpClient *http.Client, apiEndpoint string) (*NginxClient,
|
|||||||
|
|
||||||
// GetStubStats fetches the stub_status metrics.
|
// GetStubStats fetches the stub_status metrics.
|
||||||
func (client *NginxClient) GetStubStats() (*StubStats, error) {
|
func (client *NginxClient) GetStubStats() (*StubStats, error) {
|
||||||
resp, err := client.httpClient.Get(client.apiEndpoint)
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, client.apiEndpoint, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create a get request: %w", err)
|
||||||
|
}
|
||||||
|
resp, err := client.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get %v: %w", client.apiEndpoint, err)
|
return nil, fmt.Errorf("failed to get %v: %w", client.apiEndpoint, err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user