From 8c3f0d2c642657f491fba796899be265d6f3b4c4 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 22 Jan 2021 18:22:17 +0300 Subject: [PATCH] meter: remove wrapper Signed-off-by: Vasiliy Tolstov --- meter/wrapper/metrics_wrapper.go | 50 -------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 meter/wrapper/metrics_wrapper.go diff --git a/meter/wrapper/metrics_wrapper.go b/meter/wrapper/metrics_wrapper.go deleted file mode 100644 index 8ed756a9..00000000 --- a/meter/wrapper/metrics_wrapper.go +++ /dev/null @@ -1,50 +0,0 @@ -package wrapper - -import ( - "context" - "time" - - "github.com/unistack-org/micro/v3/metadata" - "github.com/unistack-org/micro/v3/meter" - "github.com/unistack-org/micro/v3/server" -) - -// Wrapper provides a HandlerFunc for meter.Meter implementations -type Wrapper struct { - meter meter.Meter -} - -// New returns a *Wrapper configured with the given meter.Meter -func New(meter meter.Meter) *Wrapper { - return &Wrapper{ - meter: meter, - } -} - -// HandlerFunc instruments handlers registered to a service: -func (w *Wrapper) HandlerFunc(handlerFunction server.HandlerFunc) server.HandlerFunc { - return func(ctx context.Context, req server.Request, rsp interface{}) error { - - // Build some tags to describe the call: - tags := metadata.New(2) - tags.Set("method", req.Method()) - - // Start the clock: - callTime := time.Now() - - // Run the handlerFunction: - err := handlerFunction(ctx, req, rsp) - - // Add a result tag: - if err != nil { - tags["status"] = "failure" - } else { - tags["status"] = "success" - } - - // Instrument the result (if the DefaultClient has been configured): - w.meter.Summary("service.handler", tags).Update(float64(time.Since(callTime).Seconds())) - - return err - } -}