mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
add opentracing spans for metrics
This commit is contained in:
committed by
Travis Reeder
parent
1cc1a5ad49
commit
dc5e67b6d2
@@ -1,16 +1,26 @@
|
||||
package mqs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"gitlab-odx.oracle.com/odx/functions/api/models"
|
||||
)
|
||||
|
||||
// New will parse the URL and return the correct MQ implementation.
|
||||
func New(mqURL string) (models.MessageQueue, error) {
|
||||
mq, err := newmq(mqURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &metricMQ{mq}, nil
|
||||
}
|
||||
|
||||
func newmq(mqURL string) (models.MessageQueue, error) {
|
||||
// Play with URL schemes here: https://play.golang.org/p/xWAf9SpCBW
|
||||
u, err := url.Parse(mqURL)
|
||||
if err != nil {
|
||||
@@ -31,3 +41,25 @@ func New(mqURL string) (models.MessageQueue, error) {
|
||||
|
||||
return nil, fmt.Errorf("mq type not supported %v", u.Scheme)
|
||||
}
|
||||
|
||||
type metricMQ struct {
|
||||
mq models.MessageQueue
|
||||
}
|
||||
|
||||
func (m *metricMQ) Push(ctx context.Context, t *models.Task) (*models.Task, error) {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "mq_push")
|
||||
defer span.Finish()
|
||||
return m.mq.Push(ctx, t)
|
||||
}
|
||||
|
||||
func (m *metricMQ) Reserve(ctx context.Context) (*models.Task, error) {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "mq_reserve")
|
||||
defer span.Finish()
|
||||
return m.mq.Reserve(ctx)
|
||||
}
|
||||
|
||||
func (m *metricMQ) Delete(ctx context.Context, t *models.Task) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "mq_delete")
|
||||
defer span.Finish()
|
||||
return m.mq.Delete(ctx, t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user