Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not exit if pgpool is not reachable on startup #20

Closed
AnirudhGoel opened this issue Oct 20, 2022 · 6 comments
Closed

Do not exit if pgpool is not reachable on startup #20

AnirudhGoel opened this issue Oct 20, 2022 · 6 comments
Assignees

Comments

@AnirudhGoel
Copy link
Contributor

Currently on startup, if the exporter cannot connect to pgpool it throws an error and exits. This is okay if the pgpool connection parameters are incorrect but if the parameters are correct and pgpool is down, the exporter should just print the metric up = 0 and wait for pgpool to be back up and not exit with an error.
This behaviour causes an issue if the exporter is run as a sidecar container with pgpool and pgpool is waiting for searching a primary (search_primary_node_timeout = 0) for a few minutes. Then, after ~30 seconds, the exporter not being able to find the pgpool exits with an error and because one of the sidecar container is down, the orchestrator kills the whole job to restart it.

@AnirudhGoel
Copy link
Contributor Author

I patched this problem in my local installation by replacing the following snippet in pgpool2_exporter.go:

if err != nil {
    level.Error(Logger).Log("err", err)
    os.Exit(1)
}

With this:

for err != nil {
    level.Error(Logger).Log("err", err)
    level.Info(Logger).Log("info", "sleeping for 5 seconds before trying to connect again")
    time.Sleep(5 * time.Second)

    db, err = getDBConn(dsn)
}

Let me know if I can make a MR with this patch. :)

@pengbo0328
Copy link
Collaborator

@AnirudhGoel Thank you for reporting this issue.
I am going to review your patch.

@pengbo0328
Copy link
Collaborator

@AnirudhGoel Sorry for the late reply.
Yes. You are correct. I have tested your patch and it works well.
Could you create a Pull request?

@pengbo0328 pengbo0328 self-assigned this Mar 8, 2023
@AnirudhGoel
Copy link
Contributor Author

Thank you @pengbo0328 for the test. Yes, I am creating a PR.

@AnirudhGoel
Copy link
Contributor Author

#26

Here it is.

@pengbo0328
Copy link
Collaborator

Thank you! @AnirudhGoel
I have merged your pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants