forked from ydb-platform/jaeger-ydb-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (74 loc) · 2.21 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"io"
"net/http"
"net/http/pprof"
"os"
"strings"
"github.com/hashicorp/go-hclog"
jaegerGrpc "github.com/jaegertracing/jaeger/plugin/storage/grpc"
"github.com/jaegertracing/jaeger/plugin/storage/grpc/shared"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/viper"
jaegerCfg "github.com/uber/jaeger-client-go/config"
localViper "github.com/yandex-cloud/jaeger-ydb-store/internal/viper"
"github.com/yandex-cloud/jaeger-ydb-store/plugin"
)
var (
logger hclog.Logger
)
func init() {
viper.SetDefault("plugin_http_listen_address", ":15000")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
viper.AutomaticEnv()
logger = hclog.New(&hclog.LoggerOptions{
Name: "ydb",
JSONFormat: true,
})
}
func main() {
localViper.ConfigureViperFromFlag(viper.GetViper())
ydbPlugin := plugin.NewYdbStorage()
ydbPlugin.InitFromViper(viper.GetViper())
go serveHttp(ydbPlugin.Registry())
closer := initTracer()
defer closer.Close()
logger.Warn("starting plugin")
jaegerGrpc.Serve(&shared.PluginServices{
Store: ydbPlugin,
ArchiveStore: ydbPlugin,
})
logger.Warn("stopped")
}
func serveHttp(gatherer prometheus.Gatherer) {
mux := http.NewServeMux()
logger.Warn("serving metrics", "addr", viper.GetString("plugin_http_listen_address"))
mux.Handle("/metrics", promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{}))
mux.HandleFunc("/ping", func(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusOK)
})
if viper.GetBool("ENABLE_PPROF") {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
err := http.ListenAndServe(viper.GetString("plugin_http_listen_address"), mux)
if err != nil {
logger.Error("failed to start http listener", "err", err)
os.Exit(1)
}
}
func initTracer() io.Closer {
cfg, err := jaegerCfg.FromEnv()
if err != nil {
logger.Error("cfg from env fail", "err", err)
os.Exit(1)
}
closer, err := cfg.InitGlobalTracer("jaeger-ydb-query")
if err != nil {
logger.Error("tracer create failed", "err", err)
os.Exit(1)
}
return closer
}