Skip to content

Commit

Permalink
Make it a single binary.
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
  • Loading branch information
tomwilkie committed Nov 19, 2018
1 parent 0421973 commit 0182f84
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 207 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ vendor/github.com/cortexproject/cortex/pkg/ingester/client/cortex.pb.go
vendor/github.com/cortexproject/cortex/pkg/ring/ring.pb.go
.pkg
.cache
cmd/distributor/distributor
cmd/ingester/ingester
cmd/querier/querier
cmd/tempo/tempo
cmd/promtail/promtail
*.output
/images/
Expand Down
4 changes: 0 additions & 4 deletions cmd/distributor/Dockerfile

This file was deleted.

66 changes: 0 additions & 66 deletions cmd/distributor/main.go

This file was deleted.

4 changes: 0 additions & 4 deletions cmd/ingester/Dockerfile

This file was deleted.

57 changes: 0 additions & 57 deletions cmd/ingester/main.go

This file was deleted.

4 changes: 0 additions & 4 deletions cmd/querier/Dockerfile

This file was deleted.

69 changes: 0 additions & 69 deletions cmd/querier/main.go

This file was deleted.

4 changes: 4 additions & 0 deletions cmd/tempo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine:3.4
COPY tempo /bin/tempo
EXPOSE 80
ENTRYPOINT [ "/bin/tempo" ]
158 changes: 158 additions & 0 deletions cmd/tempo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package main

import (
"flag"
"net/http"
"os"

"github.com/opentracing-contrib/go-stdlib/nethttp"
opentracing "github.com/opentracing/opentracing-go"
log "github.com/sirupsen/logrus"
"github.com/weaveworks/common/middleware"
"github.com/weaveworks/common/server"

"github.com/cortexproject/cortex/pkg/ring"
"github.com/cortexproject/cortex/pkg/util"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"

"github.com/grafana/tempo/pkg/distributor"
"github.com/grafana/tempo/pkg/flagext"
"github.com/grafana/tempo/pkg/ingester"
"github.com/grafana/tempo/pkg/logproto"
"github.com/grafana/tempo/pkg/querier"
)

type target struct {
deps []string
init func() error
stop func()
}

func main() {
var (
flagset = flag.NewFlagSet("", flag.ExitOnError)
serverConfig = server.Config{
MetricsNamespace: "tempo",
GRPCMiddleware: []grpc.UnaryServerInterceptor{
middleware.ServerUserHeaderInterceptor,
},
}
ringConfig ring.Config
distributorConfig distributor.Config
ingesterConfig ingester.Config
querierConfig querier.Config
)
flagext.RegisterConfigs(flagset, &serverConfig, &ringConfig, &distributorConfig,
&ingesterConfig, &querierConfig)
flagset.Parse(os.Args[1:])
util.InitLogger(&serverConfig)

server, err := server.New(serverConfig)
if err != nil {
log.Fatalf("Error initializing server: %v", err)
}
defer server.Shutdown()

var (
r *ring.Ring
d *distributor.Distributor
i *ingester.Ingester
q *querier.Querier

mods = map[string]target{
"ring": target{
init: func() (err error) {
r, err = ring.New(ringConfig)
return
},
stop: func() {
r.Stop()
},
},
"distributor": target{
deps: []string{"ring"},
init: func() (err error) {
d, err = distributor.New(distributorConfig, r)
if err != nil {
return
}
operationNameFunc := nethttp.OperationNameFunc(func(r *http.Request) string {
return r.URL.RequestURI()
})
server.HTTP.Handle("/api/prom/push", middleware.Merge(
middleware.Func(func(handler http.Handler) http.Handler {
return nethttp.Middleware(opentracing.GlobalTracer(), handler, operationNameFunc)
}),
middleware.AuthenticateUser,
).Wrap(http.HandlerFunc(d.PushHandler)))
server.HTTP.Handle("/ring", r)
return
},
stop: func() {},
},
"ingester": target{
deps: []string{"ring"},
init: func() (err error) {
ingesterConfig.LifecyclerConfig.ListenPort = &serverConfig.GRPCListenPort
i, err = ingester.New(ingesterConfig)
if err != nil {
return
}
logproto.RegisterPusherServer(server.GRPC, i)
logproto.RegisterQuerierServer(server.GRPC, i)
grpc_health_v1.RegisterHealthServer(server.GRPC, i)
server.HTTP.Path("/ready").Handler(http.HandlerFunc(i.ReadinessHandler))
return
},
stop: func() {
i.Shutdown()
},
},
"querier": target{
deps: []string{"ring"},
init: func() (err error) {
q, err = querier.New(querierConfig, r)
if err != nil {
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)
}),
middleware.AuthenticateUser,
)
server.HTTP.Handle("/api/prom/query", httpMiddleware.Wrap(http.HandlerFunc(q.QueryHandler)))
server.HTTP.Handle("/api/prom/label", httpMiddleware.Wrap(http.HandlerFunc(q.LabelHandler)))
server.HTTP.Handle("/api/prom/label/{name}/values", httpMiddleware.Wrap(http.HandlerFunc(q.LabelHandler)))
return
},
stop: func() {},
},
"lite": target{
deps: []string{"querier", "ingester", "distributor"},
init: func() (err error) {
return
},
stop: func() {},
},
}
)

var run func(mod string)
run = func(mod string) {
for _, dep := range mods[mod].deps {
run(dep)
}
if err := mods[mod].init(); err != nil {
log.Fatalf("Error initializing %s: %v", mod, err)
}
}

run(flagset.Arg(0))

server.Run()
}

0 comments on commit 0182f84

Please sign in to comment.