Skip to content

Commit 107f51b

Browse files
committed
Add test for older Haproxy versions.
Signed-off-by: Vitor Arins <vitorarins@gmail.com>
1 parent 9ac80d3 commit 107f51b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

haproxy_exporter_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,40 @@ foo,BACKEND,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,5007,0,,1,8,1,,0,,2,0,,0,L4O
163163
}
164164
}
165165

166+
func TestOlderHaproxyVersions(t *testing.T) {
167+
const data = `foo,FRONTEND,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,5007,0,,1,8,1,,0,,2,
168+
foo,foo-instance-0,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,5007,0,,1,8,1,,0,,2,
169+
foo,BACKEND,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,5007,0,,1,8,1,,0,,2,
170+
`
171+
h := newHaproxy([]byte(data))
172+
defer h.Close()
173+
174+
e, _ := NewExporter(h.URL, serverMetrics, 5*time.Second)
175+
ch := make(chan prometheus.Metric)
176+
177+
go func() {
178+
defer close(ch)
179+
e.Collect(ch)
180+
}()
181+
182+
if expect, got := 1., readGauge((<-ch).(prometheus.Gauge)); expect != got {
183+
// up
184+
t.Errorf("expected %f up, got %f", expect, got)
185+
}
186+
if expect, got := 1., readCounter((<-ch).(prometheus.Counter)); expect != got {
187+
// totalScrapes
188+
t.Errorf("expected %f recorded scrape, got %f", expect, got)
189+
}
190+
if expect, got := 0., readCounter((<-ch).(prometheus.Counter)); expect != got {
191+
// csvParseFailures
192+
t.Errorf("expected %f csv parse failures, got %f", expect, got)
193+
}
194+
195+
// Suck up the remaining metrics.
196+
for range ch {
197+
}
198+
}
199+
166200
func TestConfigChangeDetection(t *testing.T) {
167201
h := newHaproxy([]byte(""))
168202
defer h.Close()

0 commit comments

Comments
 (0)