-
Notifications
You must be signed in to change notification settings - Fork 329
fix(postgresql): mark up=0 and return when Ping fails #1356
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a database connectivity check using Ping() to the PostgreSQL input plugin. When the Ping fails, the plugin sets the up metric to 0 and returns early, preventing attempts to query a non-responsive database.
Key Changes:
- Added
Ping()check after opening database connection to verify connectivity before proceeding with queries - Sets
up=0metric when Ping fails to indicate database is unreachable
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err := ins.db.Ping(); err != nil { | ||
| slist.PushSample(inputName, "up", 0, tags) | ||
| log.Println("E! failed to ping postgresql:", err) | ||
| return | ||
| } |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Ping check should be performed after setting the connection pool parameters (SetMaxOpenConns, SetMaxIdleConns, SetConnMaxLifetime).
The MySQL input plugin (lines 213-221 in inputs/mysql/mysql.go) follows this pattern:
- Opens database connection
- Sets connection pool parameters
- Performs Ping check
- Sets up=1
This is the recommended order because the connection pool settings should be configured before attempting to use the connection. Consider moving this Ping check to after line 172 (after SetConnMaxLifetime).
No description provided.