Postgres: Config diagnostics / logging update (#105666)
* config diagnostics update * update tests * fix typo
This commit is contained in:
@@ -3,5 +3,6 @@ package sqleng
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrInvalidPortSpecified error = errors.New("invalid port in host specifier")
|
||||
ErrParsingPostgresURL error = errors.New("error parsing postgres url")
|
||||
ErrCertFileNotExist error = errors.New("certificate file doesn't exist")
|
||||
)
|
||||
|
||||
@@ -81,8 +81,8 @@ func ErrToHealthCheckResult(err error) (*backend.CheckHealthResult, error) {
|
||||
details["verboseMessage"] = pqErr.Message
|
||||
}
|
||||
}
|
||||
if errors.Is(err, ErrInvalidPortSpecified) {
|
||||
res.Message = fmt.Sprintf("Connection string error: %s", ErrInvalidPortSpecified.Error())
|
||||
if errors.Is(err, ErrParsingPostgresURL) {
|
||||
res.Message = fmt.Sprintf("Connection string error: %s", ErrParsingPostgresURL.Error())
|
||||
if unwrappedErr := errors.Unwrap(err); unwrappedErr != nil {
|
||||
details["verboseMessage"] = unwrappedErr.Error()
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ func TestErrToHealthCheckResult(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "invalid port specifier error",
|
||||
err: fmt.Errorf("%w %q: %w", ErrInvalidPortSpecified, `"foo.bar.co"`, errors.New(`strconv.Atoi: parsing "foo.bar.co": invalid syntax`)),
|
||||
err: fmt.Errorf("%w %q: %w", ErrParsingPostgresURL, `"foo.bar.co"`, errors.New(`strconv.Atoi: parsing "foo.bar.co": invalid syntax`)),
|
||||
want: &backend.CheckHealthResult{
|
||||
Status: backend.HealthStatusError,
|
||||
Message: "Connection string error: invalid port in host specifier",
|
||||
JSONDetails: []byte(`{"errorDetailsLink":"https://grafana.com/docs/grafana/latest/datasources/postgres","verboseMessage":"invalid port in host specifier \"\\\"foo.bar.co\\\"\": strconv.Atoi: parsing \"foo.bar.co\": invalid syntax"}`),
|
||||
Message: "Connection string error: error parsing postgres url",
|
||||
JSONDetails: []byte(`{"errorDetailsLink":"https://grafana.com/docs/grafana/latest/datasources/postgres","verboseMessage":"error parsing postgres url \"\\\"foo.bar.co\\\"\": strconv.Atoi: parsing \"foo.bar.co\": invalid syntax"}`),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user