1
0
mirror of https://github.com/nginxinc/nginx-prometheus-exporter.git synced 2025-07-31 21:04:21 +03:00

Use timeout flag for context cancelation

This commit is contained in:
Luca Comellini
2024-09-30 19:48:43 -07:00
parent 9cd3941e7c
commit 487aac4b2a
4 changed files with 25 additions and 19 deletions

View File

@ -47,10 +47,7 @@ func NewNginxClient(httpClient *http.Client, apiEndpoint string) *NginxClient {
}
// GetStubStats fetches the stub_status metrics.
func (client *NginxClient) GetStubStats() (*StubStats, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
func (client *NginxClient) GetStubStats(ctx context.Context) (*StubStats, error) {
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)