Skip to content

Commit 64f04c7

Browse files
authored
Merge pull request #358 from jfontan/improvement/add-tracing-flag
cmd/server: add trace parameters to enable jaeger tracing
2 parents c200a39 + 6ff18ae commit 64f04c7

File tree

249 files changed

+34052
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+34052
-25
lines changed

Gopkg.lock

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@
5454
[[constraint]]
5555
name = "gopkg.in/bblfsh/sdk.v1"
5656
version = "1.16.0"
57+
58+
[[constraint]]
59+
name = "github.com/uber/jaeger-client-go"
60+
version = "^2.7.0"

cmd/gitbase/command/server.go

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import (
1010
"github.com/src-d/gitbase/internal/function"
1111
"github.com/src-d/gitbase/internal/rule"
1212

13+
"github.com/opentracing/opentracing-go"
1314
gopilosa "github.com/pilosa/go-pilosa"
1415
"github.com/sirupsen/logrus"
16+
"github.com/uber/jaeger-client-go/config"
1517
sqle "gopkg.in/src-d/go-mysql-server.v0"
1618
"gopkg.in/src-d/go-mysql-server.v0/server"
1719
"gopkg.in/src-d/go-mysql-server.v0/sql/analyzer"
@@ -22,9 +24,10 @@ import (
2224
const (
2325
ServerDescription = "Starts a gitbase server instance"
2426
ServerHelp = ServerDescription + "\n\n" +
25-
"By default when gitbase encounters and error in a repository it\n" +
27+
"By default when gitbase encounters an error in a repository it\n" +
2628
"stops the query. With GITBASE_SKIP_GIT_ERRORS variable it won't\n" +
2729
"complain and just skip those rows or repositories."
30+
TracerServiceName = "gitbase"
2831
)
2932

3033
// Server represents the `server` command of gitbase cli tool.
@@ -39,16 +42,24 @@ type Server struct {
3942
PilosaURL string `long:"pilosa" default:"http://localhost:10101" description:"URL to your pilosa server" env:"PILOSA_ENDPOINT"`
4043
IndexDir string `short:"i" long:"index" default:"/var/lib/gitbase/index" description:"Directory where the gitbase indexes information will be persisted." env:"GITBASE_INDEX_DIR"`
4144
DisableSquash bool `long:"no-squash" description:"Disables the table squashing."`
42-
// IgnoreGitErrors by default when gitbase encounters and error in a
43-
// repository it stops the query. With this parameter it won't complain and
44-
// just skip those rows or repositories.
45+
TraceEnabled bool `long:"trace" env:"GITBASE_TRACE" description:"Enables jaeger tracing"`
46+
47+
// SkipGitErrors disables failing when Git errors are found.
4548
SkipGitErrors bool
4649

4750
engine *sqle.Engine
4851
pool *gitbase.RepositoryPool
4952
name string
5053
}
5154

55+
type jaegerLogrus struct {
56+
*logrus.Entry
57+
}
58+
59+
func (l *jaegerLogrus) Error(s string) {
60+
l.Entry.Error(s)
61+
}
62+
5263
// Execute starts a new gitbase server based on provided configuration, it
5364
// honors the go-flags.Commander interface.
5465
func (c *Server) Execute(args []string) error {
@@ -66,12 +77,43 @@ func (c *Server) Execute(args []string) error {
6677
{Password: c.Password},
6778
}
6879

80+
var tracer opentracing.Tracer
81+
if c.TraceEnabled {
82+
cfg, err := config.FromEnv()
83+
if err != nil {
84+
logrus.WithField("error", err).
85+
Fatal("unable to read jaeger environment")
86+
return err
87+
}
88+
89+
if cfg.ServiceName == "" {
90+
cfg.ServiceName = TracerServiceName
91+
}
92+
93+
logger := &jaegerLogrus{logrus.WithField("subsystem", "jaeger")}
94+
95+
t, closer, err := cfg.NewTracer(
96+
config.Logger(logger),
97+
)
98+
99+
if err != nil {
100+
logrus.WithField("error", err).Fatal("unable to initialize tracer")
101+
return err
102+
}
103+
104+
tracer = t
105+
defer closer.Close()
106+
107+
logrus.Info("tracing enabled")
108+
}
109+
69110
hostString := net.JoinHostPort(c.Host, strconv.Itoa(c.Port))
70111
s, err := server.NewServer(
71112
server.Config{
72113
Protocol: "tcp",
73114
Address: hostString,
74115
Auth: auth,
116+
Tracer: tracer,
75117
},
76118
c.engine,
77119
gitbase.NewSessionBuilder(c.pool,

docs/using-gitbase/configuration.md

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,40 @@
22

33
## Environment variables
44

5-
| Name | Description |
6-
|:---------------------------------|:----------------------------------------------------|
7-
| `BBLFSH_ENDPOINT` | bblfshd endpoint, default "127.0.0.1:9432" |
8-
| `PILOSA_ENDPOINT` | pilosa endpoint, default "http://localhost:10101" |
9-
| `GITBASE_BLOBS_MAX_SIZE` | maximum blob size to return in MiB, default 5 MiB |
10-
| `GITBASE_BLOBS_ALLOW_BINARY` | enable retrieval of binary blobs, default `false` |
11-
| `GITBASE_SKIP_GIT_ERRORS` | do not stop queries on git errors, default disabled |
5+
| Name | Description |
6+
|:-----------------------------|:------------------------------------------------------------|
7+
| `BBLFSH_ENDPOINT` | bblfshd endpoint, default "127.0.0.1:9432" |
8+
| `PILOSA_ENDPOINT` | pilosa endpoint, default "http://localhost:10101" |
9+
| `GITBASE_BLOBS_MAX_SIZE` | maximum blob size to return in MiB, default 5 MiB |
10+
| `GITBASE_BLOBS_ALLOW_BINARY` | enable retrieval of binary blobs, default `false` |
11+
| `GITBASE_SKIP_GIT_ERRORS` | do not stop queries on git errors, default disabled |
12+
| `GITBASE_INDEX_DIR` | directory to save indexes, default `/var/lib/gitbase/index` |
13+
| `GITBASE_TRACE` | enable jaeger tracing, default disabled |
14+
15+
### Jaeger tracing variables
16+
17+
*Extracted from https://github.com/jaegertracing/jaeger-client-go/blob/master/README.md*
18+
19+
Property| Description
20+
--- | ---
21+
JAEGER_SERVICE_NAME | The service name
22+
JAEGER_AGENT_HOST | The hostname for communicating with agent via UDP
23+
JAEGER_AGENT_PORT | The port for communicating with agent via UDP
24+
JAEGER_REPORTER_LOG_SPANS | Whether the reporter should also log the spans
25+
JAEGER_REPORTER_MAX_QUEUE_SIZE | The reporter's maximum queue size
26+
JAEGER_REPORTER_FLUSH_INTERVAL | The reporter's flush interval (ms)
27+
JAEGER_SAMPLER_TYPE | The sampler type
28+
JAEGER_SAMPLER_PARAM | The sampler parameter (number)
29+
JAEGER_SAMPLER_MANAGER_HOST_PORT | The host name and port when using the remote controlled sampler
30+
JAEGER_SAMPLER_MAX_OPERATIONS | The maximum number of operations that the sampler will keep track of
31+
JAEGER_SAMPLER_REFRESH_INTERVAL | How often the remotely controlled sampler will poll jaeger-agent for the appropriate sampling strategy
32+
JAEGER_TAGS | A comma separated list of `name = value` tracer level tags, which get added to all reported spans. The value can also refer to an environment variable using the format `${envVarName:default}`, where the `:default` is optional, and identifies a value to be used if the environment variable cannot be found
33+
JAEGER_DISABLED | Whether the tracer is disabled or not. If true, the default `opentracing.NoopTracer` is used.
34+
JAEGER_RPC_METRICS | Whether to store RPC metrics
1235

1336
## Command line arguments
1437

15-
```bash
38+
```
1639
Please specify one command of: server or version
1740
Usage:
1841
gitbase [OPTIONS] <server | version>
@@ -27,7 +50,7 @@ Available commands:
2750

2851
`server` command contains the following options:
2952

30-
```bash
53+
```
3154
Usage:
3255
gitbase [OPTIONS] server [server-OPTIONS]
3356
@@ -38,17 +61,22 @@ stops the query. With GITBASE_SKIP_GIT_ERRORS variable it won't
3861
complain and just skip those rows or repositories.
3962
4063
Help Options:
41-
-h, --help Show this help message
64+
-h, --help Show this help message
4265
4366
[server command options]
44-
-v Activates the verbose mode
45-
-g, --git= Path where the git repositories are located, multiple directories can be defined. Accepts globs.
46-
--siva= Path where the siva repositories are located, multiple directories can be defined. Accepts globs.
47-
-h, --host= Host where the server is going to listen (default: localhost)
48-
-p, --port= Port where the server is going to listen (default: 3306)
49-
-u, --user= User name used for connection (default: root)
50-
-P, --password= Password used for connection
51-
--pilosa= URL to your pilosa server (default: http://localhost:10101)
52-
-i, --index= Directory where the gitbase indexes information will be persisted. (default: /var/lib/gitbase/index)
53-
--no-squash Disables the table squashing.
67+
-v Activates the verbose mode
68+
-g, --git= Path where the git repositories are located, multiple directories can
69+
be defined. Accepts globs.
70+
--siva= Path where the siva repositories are located, multiple directories can
71+
be defined. Accepts globs.
72+
-h, --host= Host where the server is going to listen (default: localhost)
73+
-p, --port= Port where the server is going to listen (default: 3306)
74+
-u, --user= User name used for connection (default: root)
75+
-P, --password= Password used for connection
76+
--pilosa= URL to your pilosa server (default: http://localhost:10101)
77+
[$PILOSA_ENDPOINT]
78+
-i, --index= Directory where the gitbase indexes information will be persisted.
79+
(default: /var/lib/gitbase/index) [$GITBASE_INDEX_DIR]
80+
--no-squash Disables the table squashing.
81+
--trace Enables jaeger tracing [$GITBASE_TRACE]
5482
```

vendor/github.com/codahale/hdrhistogram/.travis.yml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/codahale/hdrhistogram/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/codahale/hdrhistogram/README.md

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)