@@ -87,7 +87,7 @@ func TestInvalidConfig(t *testing.T) {
8787}
8888
8989func TestServerWithoutChecks (t * testing.T ) {
90- h := newHaproxy ([]byte ("test,127.0.0.1:8080,0,0,0,0,0,0,0,0,,0,,0,0,0,0,no check,1,1,0,0,,,0,,1,1,1,,0,,2,0,,0,,,,0,0,0,0,0,0,0,,,,0,0," ))
90+ h := newHaproxy ([]byte ("test,127.0.0.1:8080,0,0,0,0,0,0,0,0,,0,,0,0,0,0,no check,1,1,0,0,,,0,,1,1,1,,0,,2,0,,0,,,,0,0,0,0,0,0,0,,,,0,0,,,,,,,,,,, " ))
9191 defer h .Close ()
9292
9393 e , _ := NewExporter (h .URL , serverMetrics , 5 * time .Second )
@@ -125,10 +125,10 @@ func TestServerWithoutChecks(t *testing.T) {
125125// * http://permalink.gmane.org/gmane.comp.web.haproxy/26561
126126//
127127func TestServerBrokenCSV (t * testing.T ) {
128- 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,0,,0,L4OK,,0,,,,,,,0,,,,0,0,
129- foo,bug-missing-comma,0,0,0,0,,0,0,0,,0,,0,0,0,0,DRAIN (agent)1,1,0,0,0,5007,0,,1,8,1,,0,,2,0,,0,L4OK,,0,,,,,,,0,,,,0,0,
130- 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,0,,0,L4OK,,0,,,,,,,0,,,,0,0,
131- 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,L4OK,,0,,,,,,,0,,,,0,0,
128+ 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,0,,0,L4OK,,0,,,,,,,0,,,,0,0,,,,,,,,,,,
129+ foo,bug-missing-comma,0,0,0,0,,0,0,0,,0,,0,0,0,0,DRAIN (agent)1,1,0,0,0,5007,0,,1,8,1,,0,,2,0,,0,L4OK,,0,,,,,,,0,,,,0,0,,,,,,,,,,,
130+ 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,0,,0,L4OK,,0,,,,,,,0,,,,0,0,,,,,,,,,,,
131+ 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,L4OK,,0,,,,,,,0,,,,0,0,,,,,,,,,,,
132132`
133133 h := newHaproxy ([]byte (data ))
134134 defer h .Close ()
@@ -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+
166200func TestConfigChangeDetection (t * testing.T ) {
167201 h := newHaproxy ([]byte ("" ))
168202 defer h .Close ()
@@ -285,7 +319,7 @@ func TestUnixDomain(t *testing.T) {
285319 t .Skip ("not on windows" )
286320 return
287321 }
288- srv , err := newHaproxyUnix (testSocket , "test,127.0.0.1:8080,0,0,0,0,0,0,0,0,,0,,0,0,0,0,no check,1,1,0,0,,,0,,1,1,1,,0,,2,0,,0,,,,0,0,0,0,0,0,0,,,,0,0,\n " )
322+ srv , err := newHaproxyUnix (testSocket , "test,127.0.0.1:8080,0,0,0,0,0,0,0,0,,0,,0,0,0,0,no check,1,1,0,0,,,0,,1,1,1,,0,,2,0,,0,,,,0,0,0,0,0,0,0,,,,0,0,,,,,,,,,,, \n " )
289323 if err != nil {
290324 t .Fatalf ("can't start test server: %v" , err )
291325 }
0 commit comments