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
|
||||
}
|
||||
|
||||
var ignoredColumns = map[string]bool{"datid": true, "datname": true, "stats_reset": true}
|
||||
|
||||
var sampleConfig = `
|
||||
# specify servers via an array of tables
|
||||
[[postgresql.servers]]
|
||||
|
@ -59,8 +61,11 @@ func (p *Postgresql) Description() string {
|
|||
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 ignoredColumns = map[string]bool{"datid": true, "datname": true, "stats_reset": true}
|
||||
|
||||
func (p *Postgresql) Gather(acc plugins.Accumulator) error {
|
||||
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()}
|
||||
|
||||
for col, val := range columnMap {
|
||||
if !ignoredColumns[col] {
|
||||
_, ignore := ignoredColumns[col]
|
||||
if !ignore {
|
||||
acc.Add(col, *val, tags)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,11 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
|||
err := p.Gather(&acc)
|
||||
require.NoError(t, err)
|
||||
|
||||
availableColumns := make(map[string]bool)
|
||||
for _, col := range p.Servers[0].OrderedColumns {
|
||||
availableColumns[col] = true
|
||||
}
|
||||
|
||||
intMetrics := []string{
|
||||
"xact_commit",
|
||||
"xact_rollback",
|
||||
|
@ -43,6 +48,7 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
|||
"temp_files",
|
||||
"temp_bytes",
|
||||
"deadlocks",
|
||||
"numbackends",
|
||||
}
|
||||
|
||||
floatMetrics := []string{
|
||||
|
@ -50,13 +56,26 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
|||
"blk_write_time",
|
||||
}
|
||||
|
||||
metricsCounted := 0
|
||||
|
||||
for _, metric := range intMetrics {
|
||||
assert.True(t, acc.HasIntValue(metric))
|
||||
_, ok := availableColumns[metric]
|
||||
if ok {
|
||||
assert.True(t, acc.HasIntValue(metric))
|
||||
metricsCounted++
|
||||
}
|
||||
}
|
||||
|
||||
for _, metric := range floatMetrics {
|
||||
assert.True(t, acc.HasFloatValue(metric))
|
||||
_, ok := availableColumns[metric]
|
||||
if ok {
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue