This repository has been archived by the owner on Sep 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
63 lines (51 loc) · 1.65 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"flag"
"net/http"
"github.com/rewe-digital/cortex-gateway/gateway"
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/opentracing-contrib/go-stdlib/nethttp"
"github.com/opentracing/opentracing-go"
"github.com/weaveworks/common/middleware"
"github.com/weaveworks/common/server"
"github.com/weaveworks/common/tracing"
"google.golang.org/grpc"
)
func main() {
operationNameFunc := nethttp.OperationNameFunc(func(r *http.Request) string {
return r.URL.RequestURI()
})
var (
serverCfg = server.Config{
MetricsNamespace: "cortex_gateway",
HTTPMiddleware: []middleware.Interface{
middleware.Func(func(handler http.Handler) http.Handler {
return nethttp.Middleware(opentracing.GlobalTracer(), handler, operationNameFunc)
}),
},
GRPCMiddleware: []grpc.UnaryServerInterceptor{
middleware.ServerUserHeaderInterceptor,
},
}
gatewayCfg gateway.Config
)
flagext.RegisterFlags(&serverCfg, &gatewayCfg)
flag.Parse()
util.InitLogger(&serverCfg)
// Must be done after initializing the logger, otherwise no log message is printed
err := gatewayCfg.Validate()
util.CheckFatal("validating gateway config", err)
// Setting the environment variable JAEGER_AGENT_HOST enables tracing
trace, err := tracing.NewFromEnv("cortex-gateway")
util.CheckFatal("initializing tracing", err)
defer trace.Close()
svr, err := server.New(serverCfg)
util.CheckFatal("initializing server", err)
defer svr.Shutdown()
// Setup proxy and register routes
gateway, err := gateway.New(gatewayCfg, svr)
util.CheckFatal("initializing gateway", err)
gateway.Start()
svr.Run()
}