Skip to content

Commit

Permalink
Add consistent ndt5 protocol metric labels (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-soltesz committed Jun 30, 2020
1 parent 896731c commit cbf5000
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ndt5/c2s/c2s.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ManageTest(ctx context.Context, controlConn protocol.Connection, s ndt.Serv
record = &ArchivalData{}

m := controlConn.Messager()
connType := s.ConnectionType().String()
connType := s.ConnectionType().Label()

srv, err := s.SingleServingServer("c2s")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ndt5/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ManageTest(ctx context.Context, m protocol.Messager, s ndt.Server) ([]metad
var err error
var message []byte
results := []metadata.NameValue{}
connType := s.ConnectionType().String()
connType := s.ConnectionType().Label()

err = m.SendMessage(protocol.TestPrepare, []byte{})
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions ndt5/ndt/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@ import (
// websockets, or secure websockets.
type ConnectionType string

// String returns the connection type named used in archival data.
func (c ConnectionType) String() string {
return string(c)
}

// Label returns the connection type name used in monitoring metrics.
func (c ConnectionType) Label() string {
switch c {
case WSS:
return "ndt5+wss"
case WS:
return "ndt5+ws"
case Plain:
return "ndt5+plain"
default:
return "ndt5+unknown"
}
}

// The types of connections we support.
var (
WS = ConnectionType("WS")
Expand Down
23 changes: 4 additions & 19 deletions ndt5/ndt5.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func panicMsgToErrType(msg string) string {
// only needs a connection, and a factory for making single-use servers for
// connections of that same type.
func HandleControlChannel(conn protocol.Connection, s ndt.Server, isMon string) {
connType := s.ConnectionType().String()
connType := s.ConnectionType().Label()
metrics.ActiveTests.WithLabelValues(connType).Inc()
defer metrics.ActiveTests.WithLabelValues(connType).Dec()
defer func(start time.Time) {
Expand All @@ -115,21 +115,6 @@ func HandleControlChannel(conn protocol.Connection, s ndt.Server, isMon string)
handleControlChannel(conn, s, isMon)
}

// connToProtocol accepts a ConnectionType string and returns a suitable label
// for montitoring metrics.
func connToProtocol(connType string) string {
switch connType {
case ndt.WSS.String():
return "ndt5+wss"
case ndt.WS.String():
return "ndt5+ws"
case ndt.Plain.String():
return "ndt5+plain"
default:
return "ndt5+unknown"
}
}

func handleControlChannel(conn protocol.Connection, s ndt.Server, isMon string) {
// Nothing should take more than 45 seconds, and exiting this method should
// cause all resources used by the test to be reclaimed.
Expand All @@ -138,7 +123,7 @@ func handleControlChannel(conn protocol.Connection, s ndt.Server, isMon string)

log.Println("Handling connection", conn)
defer warnonerror.Close(conn, "Could not close "+conn.String())
connType := s.ConnectionType().String()
connType := s.ConnectionType().Label()
sIP, sPort := conn.ServerIPAndPort()
cIP, cPort := conn.ClientIPAndPort()
record := &data.NDT5Result{
Expand Down Expand Up @@ -221,7 +206,7 @@ func handleControlChannel(conn protocol.Connection, s ndt.Server, isMon string)
record.C2S, err = c2s.ManageTest(ctx, conn, s)
if record.C2S != nil && record.C2S.MeanThroughputMbps != 0 {
c2sRate = record.C2S.MeanThroughputMbps
metrics.TestRate.WithLabelValues(connToProtocol(connType), "c2s", isMon).Observe(c2sRate)
metrics.TestRate.WithLabelValues(connType, "c2s", isMon).Observe(c2sRate)
}
r := metrics.GetResultLabel(err, record.C2S.MeanThroughputMbps)
ndt5metrics.ClientTestResults.WithLabelValues(connType, "c2s", r).Inc()
Expand All @@ -231,7 +216,7 @@ func handleControlChannel(conn protocol.Connection, s ndt.Server, isMon string)
record.S2C, err = s2c.ManageTest(ctx, conn, s)
if record.S2C != nil && record.S2C.MeanThroughputMbps != 0 {
s2cRate = record.S2C.MeanThroughputMbps
metrics.TestRate.WithLabelValues(connToProtocol(connType), "s2c", isMon).Observe(s2cRate)
metrics.TestRate.WithLabelValues(connType, "s2c", isMon).Observe(s2cRate)
}
r := metrics.GetResultLabel(err, record.S2C.MeanThroughputMbps)
ndt5metrics.ClientTestResults.WithLabelValues(connType, "s2c", r).Inc()
Expand Down
2 changes: 1 addition & 1 deletion ndt5/s2c/s2c.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func ManageTest(ctx context.Context, controlConn protocol.Connection, s ndt.Serv
}
}()

connType := s.ConnectionType().String()
connType := s.ConnectionType().Label()

srv, err := s.SingleServingServer("s2c")
if err != nil {
Expand Down

0 comments on commit cbf5000

Please sign in to comment.