fix(inputs.postgresql_extensible): Restore outputaddress behavior (#13972)
This commit is contained in:
parent
3b00b1da95
commit
ebb20bfa4c
|
|
@ -175,7 +175,12 @@ func (p *Service) SanitizedAddress() (sanitizedAddress string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConnectDatabase utility function for getting the database to which the connection was made
|
// GetConnectDatabase utility function for getting the database to which the connection was made
|
||||||
|
// If the user set the output address use that before parsing anything else.
|
||||||
func (p *Service) GetConnectDatabase(connectionString string) (string, error) {
|
func (p *Service) GetConnectDatabase(connectionString string) (string, error) {
|
||||||
|
if p.OutputAddress != "" {
|
||||||
|
return p.OutputAddress, nil
|
||||||
|
}
|
||||||
|
|
||||||
connConfig, err := pgx.ParseConfig(connectionString)
|
connConfig, err := pgx.ParseConfig(connectionString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("connection string parsing failed: %w", err)
|
return "", fmt.Errorf("connection string parsing failed: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -294,21 +294,48 @@ func TestPostgresqlIgnoresUnwantedColumnsIntegration(t *testing.T) {
|
||||||
func TestAccRow(t *testing.T) {
|
func TestAccRow(t *testing.T) {
|
||||||
p := Postgresql{
|
p := Postgresql{
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
|
Service: postgresql.Service{
|
||||||
|
OutputAddress: "server",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
columns := []string{"datname", "cat"}
|
columns := []string{"datname", "cat"}
|
||||||
|
|
||||||
testRows := []fakeRow{
|
tests := []struct {
|
||||||
{fields: []interface{}{1, "gato"}},
|
fields fakeRow
|
||||||
{fields: []interface{}{nil, "gato"}},
|
dbName string
|
||||||
{fields: []interface{}{"name", "gato"}},
|
server string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
fields: fakeRow{
|
||||||
|
fields: []interface{}{1, "gato"},
|
||||||
|
},
|
||||||
|
dbName: "server",
|
||||||
|
server: "server",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: fakeRow{
|
||||||
|
fields: []interface{}{nil, "gato"},
|
||||||
|
},
|
||||||
|
dbName: "server",
|
||||||
|
server: "server",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: fakeRow{
|
||||||
|
fields: []interface{}{"name", "gato"},
|
||||||
|
},
|
||||||
|
dbName: "name",
|
||||||
|
server: "server",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i := range testRows {
|
for _, tt := range tests {
|
||||||
err := p.accRow("pgTEST", testRows[i], &acc, columns)
|
require.NoError(t, p.accRow("pgTEST", tt.fields, &acc, columns))
|
||||||
if err != nil {
|
require.Equal(t, 1, len(acc.Metrics))
|
||||||
t.Fatalf("Scan failed: %s", err)
|
metric := acc.Metrics[0]
|
||||||
}
|
require.Equal(t, tt.dbName, metric.Tags["db"])
|
||||||
|
require.Equal(t, tt.server, metric.Tags["server"])
|
||||||
|
acc.ClearMetrics()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue