Convert remaining collectors to use ConstMetrics
This commit is contained in:
parent
c53bc168fe
commit
8e50b80d12
17 changed files with 455 additions and 614 deletions
|
|
@ -19,7 +19,6 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -129,36 +128,23 @@ func TestIPVSCollector(t *testing.T) {
|
|||
}
|
||||
sink := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
for {
|
||||
<-sink
|
||||
err = collector.Update(sink)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
err = collector.Update(sink)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, expect := range expectedIPVSBackendStatuses {
|
||||
labels := prometheus.Labels{
|
||||
"local_address": expect.LocalAddress.String(),
|
||||
"local_port": strconv.FormatUint(uint64(expect.LocalPort), 10),
|
||||
"remote_address": expect.RemoteAddress.String(),
|
||||
"remote_port": strconv.FormatUint(uint64(expect.RemotePort), 10),
|
||||
"proto": expect.Proto,
|
||||
}
|
||||
// TODO: Pending prometheus/client_golang#58, check the actual numbers
|
||||
_, err = collector.backendConnectionsActive.GetMetricWith(labels)
|
||||
if err != nil {
|
||||
t.Errorf("Missing active connections metric for label combination: %+v", labels)
|
||||
}
|
||||
_, err = collector.backendConnectionsInact.GetMetricWith(labels)
|
||||
if err != nil {
|
||||
t.Errorf("Missing inactive connections metric for label combination: %+v", labels)
|
||||
}
|
||||
_, err = collector.backendWeight.GetMetricWith(labels)
|
||||
if err != nil {
|
||||
t.Errorf("Missing weight metric for label combination: %+v", labels)
|
||||
for expected, got := range map[string]string{
|
||||
prometheus.NewDesc("node_ipvs_connections_total", "The total number of connections made.", nil, nil).String(): (<-sink).Desc().String(),
|
||||
prometheus.NewDesc("node_ipvs_incoming_packets_total", "The total number of incoming packets.", nil, nil).String(): (<-sink).Desc().String(),
|
||||
prometheus.NewDesc("node_ipvs_outgoing_packets_total", "The total number of outgoing packets.", nil, nil).String(): (<-sink).Desc().String(),
|
||||
prometheus.NewDesc("node_ipvs_incoming_bytes_total", "The total amount of incoming data.", nil, nil).String(): (<-sink).Desc().String(),
|
||||
prometheus.NewDesc("node_ipvs_outgoing_bytes_total", "The total amount of outgoing data.", nil, nil).String(): (<-sink).Desc().String(),
|
||||
prometheus.NewDesc("node_ipvs_backend_connections_active", "The current active connections by local and remote address.", []string{"local_address", "local_port", "remote_address", "remote_port", "proto"}, nil).String(): (<-sink).Desc().String(),
|
||||
prometheus.NewDesc("node_ipvs_backend_connections_inactive", "The current inactive connections by local and remote address.", []string{"local_address", "local_port", "remote_address", "remote_port", "proto"}, nil).String(): (<-sink).Desc().String(),
|
||||
prometheus.NewDesc("node_ipvs_backend_weight", "The current backend weight by local and remote address.", []string{"local_address", "local_port", "remote_address", "remote_port", "proto"}, nil).String(): (<-sink).Desc().String(),
|
||||
} {
|
||||
if expected != got {
|
||||
t.Fatalf("Expected '%s' but got '%s'", expected, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue