forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
104 lines (88 loc) · 2.95 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"fmt"
"net/http"
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
"github.com/jaegertracing/jaeger/cmd/agent/app"
"github.com/jaegertracing/jaeger/cmd/agent/app/reporter/tchannel"
"github.com/jaegertracing/jaeger/cmd/flags"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/version"
)
func main() {
v := viper.New()
var command = &cobra.Command{
Use: "jaeger-agent",
Short: "Jaeger agent is a local daemon program which collects tracing data.",
Long: `Jaeger agent is a daemon program that runs on every host and receives tracing data submitted by Jaeger client libraries.`,
RunE: func(cmd *cobra.Command, args []string) error {
err := flags.TryLoadConfigFile(v)
if err != nil {
return err
}
sFlags := new(flags.SharedFlags).InitFromViper(v)
logger, err := sFlags.NewLogger(zap.NewProductionConfig())
if err != nil {
return err
}
tchanRep := tchannel.NewBuilder().InitFromViper(v, logger)
builder := new(app.Builder).InitFromViper(v)
mBldr := new(metrics.Builder).InitFromViper(v)
mFactory, err := mBldr.CreateMetricsFactory("jaeger")
if err != nil {
logger.Fatal("Could not create metrics", zap.Error(err))
}
mFactory = mFactory.Namespace("agent", nil)
cp, err := tchannel.NewCollectorProxy(tchanRep, mFactory, logger)
if err != nil {
logger.Fatal("Could not create collector proxy", zap.Error(err))
}
// TODO illustrate discovery service wiring
agent, err := builder.CreateAgent(cp, logger, mFactory)
if err != nil {
return errors.Wrap(err, "Unable to initialize Jaeger Agent")
}
if h := mBldr.Handler(); mFactory != nil && h != nil {
logger.Info("Registering metrics handler with HTTP server", zap.String("route", mBldr.HTTPRoute))
agent.GetServer().Handler.(*http.ServeMux).Handle(mBldr.HTTPRoute, h)
}
logger.Info("Starting agent")
if err := agent.Run(); err != nil {
return errors.Wrap(err, "Failed to run the agent")
}
select {}
},
}
command.AddCommand(version.Command())
config.AddFlags(
v,
command,
flags.AddConfigFileFlag,
flags.AddLoggingFlag,
app.AddFlags,
tchannel.AddFlags,
metrics.AddFlags,
)
if err := command.Execute(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}