Skip to content

Commit

Permalink
Add tracing to Loki (#328)
Browse files Browse the repository at this point in the history
* Add tracing to loki

Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>

* Use the op names from common/server

We don't need to the tracing middleware again. Further, the op names are
not sanitised here.

Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
  • Loading branch information
gouthamve authored Mar 15, 2019
1 parent ddddd14 commit b8d81ab
Show file tree
Hide file tree
Showing 255 changed files with 93,894 additions and 17,117 deletions.
103 changes: 68 additions & 35 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 12 additions & 24 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
name = "gopkg.in/fsnotify.v1"
source = "https://github.com/fsnotify/fsnotify.git"

[[override]]
name = "github.com/uber/jaeger-lib"
version = "2.0.0"

[[override]]
name = "github.com/uber/jaeger-client-go"
branch = "master"

# For Prometheus

[[constraint]]
Expand All @@ -47,32 +55,12 @@
name = "github.com/prometheus/common"

[[override]]
name = "github.com/prometheus/tsdb"
revision = "6d489a1004dc"

[[override]]
name = "k8s.io/api"
revision = "05914d821849"

[[override]]
name = "k8s.io/apimachinery"
revision = "2b1284ed4c93"

[[override]]
name = "k8s.io/client-go"
revision = "a47917edff34"

[[override]]
name = "github.com/Azure/azure-sdk-for-go"
revision = "bd73d950fa44"

[[override]]
name = "github.com/Azure/go-autorest"
version = "10.8.1"
branch = "master"
name = "github.com/prometheus/client_golang"

[[override]]
version = "=v1.0.4"
name = "github.com/miekg/dns"
name = "github.com/prometheus/tsdb"
version = "0.6.1"

[prune]
go-tests = true
Expand Down
11 changes: 11 additions & 0 deletions cmd/loki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package main

import (
"flag"
"fmt"
"os"

"github.com/go-kit/kit/log/level"
"github.com/grafana/loki/pkg/helpers"
"github.com/grafana/loki/pkg/loki"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/version"
"github.com/weaveworks/common/tracing"

"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/flagext"
Expand Down Expand Up @@ -36,6 +38,15 @@ func main() {
}
}

// Setting the environment variable JAEGER_AGENT_HOST enables tracing
trace := tracing.NewFromEnv(fmt.Sprintf("loki-%s", cfg.Target))
defer func() {
if err := trace.Close(); err != nil {
level.Error(util.Logger).Log("msg", "error closing tracing", "err", err)
os.Exit(1)
}
}()

t, err := loki.New(cfg)
if err != nil {
level.Error(util.Logger).Log("msg", "error initialising loki", "err", err)
Expand Down
14 changes: 0 additions & 14 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"net/http"
"strings"

"github.com/opentracing-contrib/go-stdlib/nethttp"
opentracing "github.com/opentracing/opentracing-go"
"google.golang.org/grpc/health/grpc_health_v1"

"github.com/cortexproject/cortex/pkg/chunk/storage"
Expand Down Expand Up @@ -114,13 +112,7 @@ func (t *Loki) initDistributor() (err error) {
return
}

operationNameFunc := nethttp.OperationNameFunc(func(r *http.Request) string {
return r.URL.RequestURI()
})
t.server.HTTP.Handle("/api/prom/push", middleware.Merge(
middleware.Func(func(handler http.Handler) http.Handler {
return nethttp.Middleware(opentracing.GlobalTracer(), handler, operationNameFunc)
}),
t.httpAuthMiddleware,
).Wrap(http.HandlerFunc(t.distributor.PushHandler)))

Expand All @@ -133,13 +125,7 @@ func (t *Loki) initQuerier() (err error) {
return
}

operationNameFunc := nethttp.OperationNameFunc(func(r *http.Request) string {
return r.URL.RequestURI()
})
httpMiddleware := middleware.Merge(
middleware.Func(func(handler http.Handler) http.Handler {
return nethttp.Middleware(opentracing.GlobalTracer(), handler, operationNameFunc)
}),
t.httpAuthMiddleware,
)
t.server.HTTP.Handle("/api/prom/query", httpMiddleware.Wrap(http.HandlerFunc(t.querier.QueryHandler)))
Expand Down
17 changes: 17 additions & 0 deletions vendor/contrib.go.opencensus.io/exporter/ocagent/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b8d81ab

Please sign in to comment.