fixed an issue of missing parameters to fmt.Errorf()
fixed the name composition for prometheus
This commit is contained in:
parent
5c2695e46b
commit
97885bcae1
@ -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
|
||||
|
@ -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,
|
||||
|
||||
|
24
client_test.go
Normal file
24
client_test.go
Normal file
@ -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") }
|
||||
}
|
@ -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
|
||||
|
@ -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,
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user