Makes the test also work across pg versions
This commit is contained in:
parent
3fa3b2d836
commit
fa5753c579
|
@ -21,6 +21,8 @@ type Postgresql struct {
|
||||||
Servers []*Server
|
Servers []*Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ignoredColumns = map[string]bool{"datid": true, "datname": true, "stats_reset": true}
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
# specify servers via an array of tables
|
# specify servers via an array of tables
|
||||||
[[postgresql.servers]]
|
[[postgresql.servers]]
|
||||||
|
@ -59,8 +61,11 @@ func (p *Postgresql) Description() string {
|
||||||
return "Read metrics from one or many postgresql servers"
|
return "Read metrics from one or many postgresql servers"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Postgresql) IgnoredColumns() map[string]bool {
|
||||||
|
return ignoredColumns
|
||||||
|
}
|
||||||
|
|
||||||
var localhost = &Server{Address: "sslmode=disable"}
|
var localhost = &Server{Address: "sslmode=disable"}
|
||||||
var ignoredColumns = map[string]bool{"datid": true, "datname": true, "stats_reset": true}
|
|
||||||
|
|
||||||
func (p *Postgresql) Gather(acc plugins.Accumulator) error {
|
func (p *Postgresql) Gather(acc plugins.Accumulator) error {
|
||||||
if len(p.Servers) == 0 {
|
if len(p.Servers) == 0 {
|
||||||
|
@ -157,7 +162,8 @@ func (p *Postgresql) accRow(row scanner, acc plugins.Accumulator, serv *Server)
|
||||||
tags := map[string]string{"server": serv.Address, "db": dbname.String()}
|
tags := map[string]string{"server": serv.Address, "db": dbname.String()}
|
||||||
|
|
||||||
for col, val := range columnMap {
|
for col, val := range columnMap {
|
||||||
if !ignoredColumns[col] {
|
_, ignore := ignoredColumns[col]
|
||||||
|
if !ignore {
|
||||||
acc.Add(col, *val, tags)
|
acc.Add(col, *val, tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,11 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
||||||
err := p.Gather(&acc)
|
err := p.Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
availableColumns := make(map[string]bool)
|
||||||
|
for _, col := range p.Servers[0].OrderedColumns {
|
||||||
|
availableColumns[col] = true
|
||||||
|
}
|
||||||
|
|
||||||
intMetrics := []string{
|
intMetrics := []string{
|
||||||
"xact_commit",
|
"xact_commit",
|
||||||
"xact_rollback",
|
"xact_rollback",
|
||||||
|
@ -43,6 +48,7 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
||||||
"temp_files",
|
"temp_files",
|
||||||
"temp_bytes",
|
"temp_bytes",
|
||||||
"deadlocks",
|
"deadlocks",
|
||||||
|
"numbackends",
|
||||||
}
|
}
|
||||||
|
|
||||||
floatMetrics := []string{
|
floatMetrics := []string{
|
||||||
|
@ -50,15 +56,28 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
||||||
"blk_write_time",
|
"blk_write_time",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metricsCounted := 0
|
||||||
|
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
|
_, ok := availableColumns[metric]
|
||||||
|
if ok {
|
||||||
assert.True(t, acc.HasIntValue(metric))
|
assert.True(t, acc.HasIntValue(metric))
|
||||||
|
metricsCounted++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range floatMetrics {
|
for _, metric := range floatMetrics {
|
||||||
|
_, ok := availableColumns[metric]
|
||||||
|
if ok {
|
||||||
assert.True(t, acc.HasFloatValue(metric))
|
assert.True(t, acc.HasFloatValue(metric))
|
||||||
|
metricsCounted++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert.True(t, metricsCounted > 0)
|
||||||
|
assert.Equal(t, len(availableColumns) - len(p.IgnoredColumns()), metricsCounted)
|
||||||
|
}
|
||||||
|
|
||||||
func TestPostgresqlTagsMetricsWithDatabaseName(t *testing.T) {
|
func TestPostgresqlTagsMetricsWithDatabaseName(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
|
|
Loading…
Reference in New Issue