Skip to content

Commit 28f207f

Browse files
committed
Add a test case to detect regression on issue fixed by PR prometheus-community#39.
Related issue is prometheus-community#38. Time to start expanding functional test coverage since the integration tests missed this.
1 parent 8f30886 commit 28f207f

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ vet:
2121
go vet .
2222

2323
test:
24-
go test -v .
24+
go test -v -cover .
2525

2626
test-integration: postgres_exporter postgres_exporter_integration_test
2727
tests/test-smoke ./postgres_exporter ./postgres_exporter_integration_test

postgres_exporter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ func makeDescMap(pgVersion semver.Version, metricMaps map[string]map[string]Colu
508508
// Force to discard if not compatible.
509509
if columnMapping.supportedVersions != nil {
510510
if !columnMapping.supportedVersions(pgVersion) {
511+
// It's very useful to be able to see what columns are being
512+
// rejected.
513+
log.Debugln(columnName, "is being forced to discard due to version incompatibility.")
511514
thisMap[columnName] = MetricMap{
512515
discard: true,
513516
conversion: func(in interface{}) (float64, bool) {

postgres_exporter_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// +build !integration
2+
3+
package main
4+
5+
import (
6+
"testing"
7+
. "gopkg.in/check.v1"
8+
9+
"github.com/blang/semver"
10+
)
11+
12+
// Hook up gocheck into the "go test" runner.
13+
func Test(t *testing.T) { TestingT(t) }
14+
15+
type FunctionalSuite struct{
16+
e *Exporter
17+
}
18+
19+
var _ = Suite(&FunctionalSuite{})
20+
21+
func (s *FunctionalSuite) SetUpSuite(c *C) {
22+
23+
}
24+
25+
func (s *FunctionalSuite) TestSemanticVersionColumnDiscard(c *C) {
26+
testMetricMap := map[string]map[string]ColumnMapping{
27+
"test_namespace" : map[string]ColumnMapping{
28+
"metric_which_stays" : {COUNTER, "This metric should not be eliminated", nil, nil},
29+
"metric_which_discards" : {COUNTER, "This metric should be forced to DISCARD", nil, nil},
30+
},
31+
}
32+
33+
{
34+
// No metrics should be eliminated
35+
resultMap := makeDescMap(semver.MustParse("0.0.1"), testMetricMap)
36+
c.Check(
37+
resultMap["test_namespace"].columnMappings["metric_which_stays"].discard,
38+
Equals,
39+
false,
40+
)
41+
c.Check(
42+
resultMap["test_namespace"].columnMappings["metric_which_discards"].discard,
43+
Equals,
44+
false,
45+
)
46+
}
47+
48+
{
49+
// Update the map so the discard metric should be eliminated
50+
discardable_metric := testMetricMap["test_namespace"]["metric_which_discards"]
51+
discardable_metric.supportedVersions = semver.MustParseRange(">0.0.1")
52+
testMetricMap["test_namespace"]["metric_which_discards"] = discardable_metric
53+
54+
// Discard metric should be discarded
55+
resultMap := makeDescMap(semver.MustParse("0.0.1"), testMetricMap)
56+
c.Check(
57+
resultMap["test_namespace"].columnMappings["metric_which_stays"].discard,
58+
Equals,
59+
false,
60+
)
61+
c.Check(
62+
resultMap["test_namespace"].columnMappings["metric_which_discards"].discard,
63+
Equals,
64+
true,
65+
)
66+
}
67+
68+
{
69+
// Update the map so the discard metric should be kept but has a version
70+
discardable_metric := testMetricMap["test_namespace"]["metric_which_discards"]
71+
discardable_metric.supportedVersions = semver.MustParseRange(">0.0.1")
72+
testMetricMap["test_namespace"]["metric_which_discards"] = discardable_metric
73+
74+
// Discard metric should be discarded
75+
resultMap := makeDescMap(semver.MustParse("0.0.2"), testMetricMap)
76+
c.Check(
77+
resultMap["test_namespace"].columnMappings["metric_which_stays"].discard,
78+
Equals,
79+
false,
80+
)
81+
c.Check(
82+
resultMap["test_namespace"].columnMappings["metric_which_discards"].discard,
83+
Equals,
84+
false,
85+
)
86+
}
87+
}

0 commit comments

Comments
 (0)