Skip to content

Commit 969b934

Browse files
author
Thibault Gilles
committed
Fix stats after dataplane update
1 parent 3d7d8ae commit 969b934

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/haproxy-connect
1+
/haproxy-connect
2+
/haproxy-consul-connect

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ go 1.12
55
require (
66
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
77
github.com/criteo/haproxy-spoe-go v0.0.0-20190701135820-6e37602c179b
8-
github.com/davecgh/go-spew v1.1.1
98
github.com/docker/go-units v0.4.0 // indirect
109
github.com/go-openapi/analysis v0.19.0 // indirect
1110
github.com/go-openapi/jsonpointer v0.19.0 // indirect
1211
github.com/go-openapi/jsonreference v0.19.0 // indirect
1312
github.com/go-openapi/loads v0.19.0 // indirect
1413
github.com/go-openapi/runtime v0.19.0 // indirect
1514
github.com/go-openapi/spec v0.19.0 // indirect
16-
github.com/haproxytech/models v1.0.1
15+
github.com/haproxytech/models v1.2.0
1716
github.com/hashicorp/consul v1.5.1
1817
github.com/hashicorp/consul/api v1.1.0
1918
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc
198198
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
199199
github.com/haproxytech/models v1.0.1 h1:Eh3YXsec8zZWiabMWreXWLcg2/wKCnYOQcal07A/2MI=
200200
github.com/haproxytech/models v1.0.1/go.mod h1:UXZVErm/XN6z10sM/enmxrdeEnwo7vz1JI+a8ycEvOQ=
201+
github.com/haproxytech/models v1.2.0 h1:E9C6LPxYgd9VfeCbV+UkmJUnsgw006PZSFjIpWUgO5A=
202+
github.com/haproxytech/models v1.2.0/go.mod h1:UXZVErm/XN6z10sM/enmxrdeEnwo7vz1JI+a8ycEvOQ=
201203
github.com/hashicorp/consul v1.5.1 h1:p7tRmQ4m3ZMYkGQkuyjLXKbdU1weeumgZFqZOvw7o4c=
202204
github.com/hashicorp/consul v1.5.1/go.mod h1:QsmgXh2YA9Njv6y3/FHXqHYhsMye++3oBoAZ6SR8R8I=
203205
github.com/hashicorp/consul/api v1.1.0 h1:BNQPM9ytxj6jbjjdRPioQ94T6YXriSopn0i8COv6SRA=

haproxy/dataplane.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func (c *dataplaneClient) Ping() error {
5858
return c.makeReq(http.MethodGet, "/v1/specification", nil, nil)
5959
}
6060

61-
func (c *dataplaneClient) Stats() ([]models.NativeStat, error) {
62-
res := []models.NativeStat{}
61+
func (c *dataplaneClient) Stats() (models.NativeStats, error) {
62+
res := models.NativeStats{}
6363
return res, c.makeReq(http.MethodGet, "/v1/services/haproxy/stats/native", nil, &res)
6464
}
6565

haproxy/stats.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ func (s *Stats) Run() {
8383
log.Error(err)
8484
continue
8585
}
86-
s.handle(stats)
86+
for _, stat := range stats {
87+
s.handle(stat)
88+
}
8789
}
8890
}
8991

90-
func (s *Stats) handle(stats []models.NativeStat) {
91-
for _, stats := range stats {
92+
func (s *Stats) handle(stats *models.NativeStatsCollection) {
93+
for _, stats := range stats.Stats {
9294
switch stats.Type {
9395
case models.NativeStatTypeFrontend:
9496
s.handleFrontend(stats)
@@ -107,7 +109,7 @@ func statVal(i *int64) float64 {
107109
return float64(*i)
108110
}
109111

110-
func (s *Stats) handleFrontend(stats models.NativeStat) {
112+
func (s *Stats) handleFrontend(stats *models.NativeStat) {
111113
targetService := strings.TrimPrefix(stats.Name, "front_")
112114

113115
if targetService == "downstream" {
@@ -137,7 +139,7 @@ func (s *Stats) handleFrontend(stats models.NativeStat) {
137139
}
138140
}
139141

140-
func (s *Stats) handlebackend(stats models.NativeStat) {
142+
func (s *Stats) handlebackend(stats *models.NativeStat) {
141143
targetService := strings.TrimPrefix(stats.Name, "back_")
142144

143145
if targetService == "downstream" {
@@ -147,6 +149,6 @@ func (s *Stats) handlebackend(stats models.NativeStat) {
147149
}
148150
}
149151

150-
func (s *Stats) handleServer(stats models.NativeStat) {
152+
func (s *Stats) handleServer(stats *models.NativeStat) {
151153
resTimeOut.WithLabelValues(s.service, stats.Name).Set(statVal(stats.Stats.Ttime) / 1000)
152154
}

0 commit comments

Comments
 (0)