nginxinc/nginx-prometheus-exporter

createClientWithRetries should be revised

Pamir opened this issue · 2 comments

Pamir commented

Is your feature request related to a problem? Please describe.
Nginx + nginx prometheus exporter is not working in kubernets when you configure exporter as a sidecar.

Describe the solution you'd like
There should be an infinite number of retries to connect nginx.

Describe alternatives you've considered
when NGINX_RETRIES is 0, we can loop nginx connection retry mechanism nfinitely.

func createClientWithRetries(getClient func() (interface{}, error), retries uint, retryInterval time.Duration) (interface{}, error) {
	var err error
	var nginxClient interface{}
	var i = 0

	for ;; {
		nginxClient, err = getClient()
		if err == nil {
			return nginxClient, nil
		}
		if i <= int(retries) {
			log.Printf("Could not create Nginx Client. Retrying in %v...", retryInterval)
			time.Sleep(retryInterval)
		}else {
			break
		}
		if retries != 0 {
			i++
		}

	}
	return nil, err
}

Additional context
If you are ok i can create a PR for this.

Aha! Link: https://nginx.aha.io/features/IC-292

If you are willing to create the PR, please do so.

Hi @Pamir I opened #504 that removes the entire retry logic and doesn't kill the exporter if nginx is not available. Do you think that would work for you?