diff --git a/client-ctl.go b/client-ctl.go index f1a7159..31c820e 100644 --- a/client-ctl.go +++ b/client-ctl.go @@ -853,7 +853,7 @@ func (ctl *client_ctl_notices_id) ServeHTTP(w http.ResponseWriter, req *http.Req // no check if noti.Text is empty as i want an empty message to be delivered too. err = cts.psc.Send(MakeConnNoticePacket(noti.Text)) if err != nil { - err = fmt.Errorf("failed to send conn_notice text to %s - %s", noti.Text, cts.remote_addr, err.Error()) + err = fmt.Errorf("failed to send conn_notice text '%s' to %s - %s", noti.Text, cts.remote_addr, err.Error()) status_code = WriteJsonRespHeader(w, http.StatusInternalServerError) je.Encode(JsonErrmsg{Text: err.Error()}) goto oops diff --git a/client-metrics.go b/client-metrics.go index 3d21f86..9b15dc6 100644 --- a/client-metrics.go +++ b/client-metrics.go @@ -1,6 +1,7 @@ package hodu import "runtime" +import "strings" import "github.com/prometheus/client_golang/prometheus" type ClientCollector struct { @@ -15,7 +16,8 @@ type ClientCollector struct { func NewClientCollector(client *Client) ClientCollector { var prefix string - prefix = client.Name() + "_" + // prometheus doesn't like a dash. change it to an underscore + prefix = strings.ReplaceAll(client.Name(), "-", "_") + "_" return ClientCollector{ client: client, diff --git a/client_test.go b/client_test.go new file mode 100644 index 0000000..62a6627 --- /dev/null +++ b/client_test.go @@ -0,0 +1,24 @@ +package hodu_test + +import "context" +import "hodu" +import "testing" + +type TestLogger struct {} + +func (l *TestLogger) Write(id string, level hodu.LogLevel, fmtstr string, args ...interface{}) {} +func (l *TestLogger) WriteWithCallDepth(id string, level hodu.LogLevel, call_depth int, fmtstr string, args ...interface{}) {} +func (l *TestLogger) Rotate() {} +func (l *TestLogger) Close() {} + +func TestClient001(t *testing.T) { + var c *hodu.Client + var r *hodu.ClientRoute + var err error + + c = hodu.NewClient(context.Background(), "test-client", &TestLogger{}, &hodu.ClientConfig{}) + + r, err = c.FindClientRouteByServerPeerSvcPortIdStr("100", "200") + if err == nil { t.Errorf("Search on empty client structure must have failed") } + if r != nil { t.Errorf("Main route must not be nil upon no error") } +} diff --git a/server-ctl.go b/server-ctl.go index 484c8f3..d0bc5e0 100644 --- a/server-ctl.go +++ b/server-ctl.go @@ -629,7 +629,7 @@ func (ctl *server_ctl_notices_id) ServeHTTP(w http.ResponseWriter, req *http.Req // no check if noti.Text is empty as i want an empty message to be delivered too. err = cts.pss.Send(MakeConnNoticePacket(noti.Text)) if err != nil { - err = fmt.Errorf("failed to send conn_notice text to %s - %s", noti.Text, cts.RemoteAddr, err.Error()) + err = fmt.Errorf("failed to send conn_notice text '%s' to %s - %s", noti.Text, cts.RemoteAddr, err.Error()) status_code = WriteJsonRespHeader(w, http.StatusInternalServerError) je.Encode(JsonErrmsg{Text: err.Error()}) goto oops diff --git a/server-metrics.go b/server-metrics.go index 4f915bf..851a1b3 100644 --- a/server-metrics.go +++ b/server-metrics.go @@ -1,6 +1,7 @@ package hodu import "runtime" +import "strings" import "github.com/prometheus/client_golang/prometheus" type ServerCollector struct { @@ -16,7 +17,8 @@ type ServerCollector struct { func NewServerCollector(server *Server) ServerCollector { var prefix string - prefix = server.Name() + "_" + // prometheus doesn't like a dash. change it to an underscore + prefix = strings.ReplaceAll(server.Name(), "-", "_") + "_" return ServerCollector{ server: server,