Skip to content

Fix PostgreSQL health check connection string parsing#3083

Open
Copilot wants to merge 9 commits intomainfrom
copilot/fix-health-check-postgres
Open

Fix PostgreSQL health check connection string parsing#3083
Copilot wants to merge 9 commits intomainfrom
copilot/fix-health-check-postgres

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Fix PostgreSQL health check connection string handling

  • Understand the issue: Health check fails for PostgreSQL with "Keyword not supported: 'host'" error
  • Identify root cause: Connection string not properly parsed through NpgsqlConnectionStringBuilder
  • Update ExecuteDbQueryAsync to use connection string builder for PostgreSQL, MSSQL, and MySQL
  • Add NormalizeConnectionString helper method in Utilities.cs
  • Add exception handling to NormalizeConnectionString to handle malformed connection strings
  • Add MySQL connection string normalization support
  • Add logging for connection string parsing failures
  • Create comprehensive unit tests (10 test cases covering all database types)
  • Refactor tests to use DataRow attributes for better organization
  • Mask passwords in test connection strings
  • Build succeeds with no errors
  • All unit tests pass (10/10)
  • Code review feedback addressed
  • Run CodeQL security check (0 vulnerabilities found)
  • Final verification complete

Summary

This PR fixes the health check endpoint failure for PostgreSQL data sources and adds comprehensive support for all database types.

Changes (4 files, 156 lines added, 3 lines modified):

  1. Utilities.cs:
    • Added MySQL connection string normalization support using MySqlConnectionStringBuilder
    • Added optional ILogger parameter for logging exceptions
    • Logs warnings when connection string parsing fails
  2. HttpUtilities.cs: Updated to pass logger to NormalizeConnectionString
  3. HealthCheckHelper.cs: Updated to pass DatabaseType parameter through the call chain
  4. HealthCheckUtilitiesUnitTests.cs (NEW): Added comprehensive unit tests with DataRow attributes:
    • PostgreSQL, MSSQL, DWSQL, MySQL normalization (consolidated with DataRow)
    • PostgreSQL lowercase keywords (the specific bug reported)
    • Unsupported database types
    • Malformed connection strings with/without logger (consolidated with DataRow)
    • Empty connection strings
    • All passwords masked as "XXXX" in test data

Review Feedback Addressed

  • ✅ Added MySQL connection string normalization for completeness
  • ✅ Added logging instead of silently swallowing exceptions
  • ✅ Added comprehensive unit test coverage (10 tests, all passing)
  • ✅ Refactored tests to use DataRow attributes for better maintainability
  • ✅ Masked passwords in test connection strings for security best practices

Security Summary

  • No security vulnerabilities detected by CodeQL
  • Changes follow existing patterns in the codebase
  • Exception handling prevents health check failures from malformed connection strings
  • Logging provides visibility into connection string parsing issues without exposing sensitive data
  • Test data uses masked passwords ("XXXX") instead of actual passwords
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Health check fails to check postgres data-source</issue_title>
<issue_description>## What

When the health check attempts to check a Postgres data-source, it gets an error.

Image

Image</issue_description>

<agent_instructions>Fix this with as few lines of new code as possible.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@JerryNixon # Solution

https://youtu.be/Js06lpu_YsM @ 5:00 time

#2797</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix health check error for postgres data-source Fix PostgreSQL health check connection string parsing Jan 27, 2026
Copilot AI requested a review from JerryNixon January 27, 2026 16:59
@JerryNixon JerryNixon marked this pull request as ready for review January 27, 2026 20:12
Copilot AI review requested due to automatic review settings January 27, 2026 20:12
@JerryNixon JerryNixon added pgsql an issue thats specific to pgsql cri Customer Reported issue labels Jan 27, 2026
@JerryNixon JerryNixon moved this from Todo to Review In Progress in Data API builder Jan 27, 2026
@JerryNixon JerryNixon added this to the Feb 2026 milestone Jan 27, 2026
@JerryNixon JerryNixon moved this from Review In Progress to In Progress in Data API builder Jan 27, 2026
@JerryNixon
Copy link
Contributor

@copilot apply changes based on the comments in this thread

Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

@copilot apply changes based on the comments in this thread

Changes applied in commit d858f2d. Added exception handling to the NormalizeConnectionString method to gracefully handle malformed connection strings.

@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@souvikghosh04
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link
Contributor

@souvikghosh04 souvikghosh04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address the review comments from my side. also add some unit test coverage.

Co-authored-by: souvikghosh04 <210500244+souvikghosh04@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 11, 2026

@copilot please address the review comments from my side. also add some unit test coverage.

Added comprehensive unit test coverage in commit d94b703. Created HealthCheckUtilitiesUnitTests.cs with 9 test cases covering:

  • PostgreSQL, MSSQL, DWSQL, and MySQL normalization
  • PostgreSQL lowercase keywords (the specific bug reported)
  • Unsupported database types
  • Malformed connection strings with/without logger
  • Empty connection strings

All tests pass successfully (9/9).

Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cri Customer Reported issue pgsql an issue thats specific to pgsql

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[Bug]: Health check fails to check postgres data-source

4 participants