From e2959d506de6067afe494315c3621b33613b5414 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Mon, 15 Mar 2021 20:18:29 +0100 Subject: added option to run with unregistered namespaces Also a few minor fixes such that server binary starts again. --- instance.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'instance.go') diff --git a/instance.go b/instance.go index 6f1314b..67336f8 100644 --- a/instance.go +++ b/instance.go @@ -41,16 +41,21 @@ type Handler struct { Handler func(context.Context, *Instance, http.ResponseWriter, *http.Request) (int, error) } +// Path returns a path that should be configured for this handler +func (h Handler) Path() string { + return h.Endpoint.Path("", h.Instance.LogParameters.Prefix) +} + // ServeHTTP is part of the http.Handler interface func (a Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // export prometheus metrics var now time.Time = time.Now() var statusCode int defer func() { - rspcnt.Inc(string(a.Instance.LogParameters.LogIdBytes), string(a.Endpoint), fmt.Sprintf("%d", statusCode)) - latency.Observe(time.Now().Sub(now).Seconds(), string(a.Instance.LogParameters.LogIdBytes), string(a.Endpoint), fmt.Sprintf("%d", statusCode)) + rspcnt.Inc(a.Instance.LogParameters.LogIdStr, string(a.Endpoint), fmt.Sprintf("%d", statusCode)) + latency.Observe(time.Now().Sub(now).Seconds(), a.Instance.LogParameters.LogIdStr, string(a.Endpoint), fmt.Sprintf("%d", statusCode)) }() - reqcnt.Inc(string(a.Instance.LogParameters.LogIdBytes), string(a.Endpoint)) + reqcnt.Inc(a.Instance.LogParameters.LogIdStr, string(a.Endpoint)) ctx, cancel := context.WithDeadline(r.Context(), now.Add(a.Instance.LogParameters.Deadline)) defer cancel() -- cgit v1.2.3