Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
27e1c674
Unverified
Commit
27e1c674
authored
May 10, 2018
by
Torkel Ödegaard
Committed by
GitHub
May 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: tracing service refactoring (#11907)
parent
bc647543
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
50 deletions
+56
-50
pkg/cmd/grafana-server/server.go
+1
-7
pkg/tracing/tracing.go
+55
-43
No files found.
pkg/cmd/grafana-server/server.go
View file @
27e1c674
...
...
@@ -27,7 +27,6 @@ import (
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social"
"github.com/grafana/grafana/pkg/tracing"
// self registering services
_
"github.com/grafana/grafana/pkg/extensions"
...
...
@@ -38,6 +37,7 @@ import (
_
"github.com/grafana/grafana/pkg/services/notifications"
_
"github.com/grafana/grafana/pkg/services/provisioning"
_
"github.com/grafana/grafana/pkg/services/search"
_
"github.com/grafana/grafana/pkg/tracing"
)
func
NewGrafanaServer
()
*
GrafanaServerImpl
{
...
...
@@ -77,12 +77,6 @@ func (g *GrafanaServerImpl) Run() error {
login
.
Init
()
social
.
NewOAuthService
()
tracingCloser
,
err
:=
tracing
.
Init
(
g
.
cfg
.
Raw
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Tracing settings is not valid. error: %v"
,
err
)
}
defer
tracingCloser
.
Close
()
serviceGraph
:=
inject
.
Graph
{}
serviceGraph
.
Provide
(
&
inject
.
Object
{
Value
:
bus
.
GetBus
()})
serviceGraph
.
Provide
(
&
inject
.
Object
{
Value
:
g
.
cfg
})
...
...
pkg/tracing/tracing.go
View file @
27e1c674
package
tracing
import
(
"context"
"io"
"strings"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/registry"
"github.com/grafana/grafana/pkg/setting"
opentracing
"github.com/opentracing/opentracing-go"
jaegercfg
"github.com/uber/jaeger-client-go/config"
ini
"gopkg.in/ini.v1"
)
var
(
logger
log
.
Logger
=
log
.
New
(
"tracing"
)
)
type
TracingSettings
struct
{
Enabled
bool
Address
string
CustomTags
map
[
string
]
string
SamplerType
string
SamplerParam
float64
func
init
()
{
registry
.
RegisterService
(
&
TracingService
{})
}
func
Init
(
file
*
ini
.
File
)
(
io
.
Closer
,
error
)
{
settings
:=
parseSettings
(
file
)
return
internalInit
(
settings
)
type
TracingService
struct
{
enabled
bool
address
string
customTags
map
[
string
]
string
samplerType
string
samplerParam
float64
log
log
.
Logger
closer
io
.
Closer
Cfg
*
setting
.
Cfg
`inject:""`
}
func
parseSettings
(
file
*
ini
.
File
)
*
TracingSettings
{
settings
:=
&
TracingSettings
{}
func
(
ts
*
TracingService
)
Init
()
error
{
ts
.
log
=
log
.
New
(
"tracing"
)
ts
.
parseSettings
()
var
section
,
err
=
setting
.
Raw
.
GetSection
(
"tracing.jaeger"
)
if
err
!=
nil
{
return
settings
if
ts
.
enabled
{
ts
.
initGlobalTracer
()
}
settings
.
Address
=
section
.
Key
(
"address"
)
.
MustString
(
""
)
if
settings
.
Address
!=
""
{
settings
.
Enabled
=
true
return
nil
}
func
(
ts
*
TracingService
)
parseSettings
()
{
var
section
,
err
=
ts
.
Cfg
.
Raw
.
GetSection
(
"tracing.jaeger"
)
if
err
!=
nil
{
return
}
settings
.
CustomTags
=
splitTagSettings
(
section
.
Key
(
"always_included_tag"
)
.
MustString
(
""
))
settings
.
SamplerType
=
section
.
Key
(
"sampler_type"
)
.
MustString
(
""
)
settings
.
SamplerParam
=
section
.
Key
(
"sampler_param"
)
.
MustFloat64
(
1
)
ts
.
address
=
section
.
Key
(
"address"
)
.
MustString
(
""
)
if
ts
.
address
!=
""
{
ts
.
enabled
=
true
}
return
settings
ts
.
customTags
=
splitTagSettings
(
section
.
Key
(
"always_included_tag"
)
.
MustString
(
""
))
ts
.
samplerType
=
section
.
Key
(
"sampler_type"
)
.
MustString
(
""
)
ts
.
samplerParam
=
section
.
Key
(
"sampler_param"
)
.
MustFloat64
(
1
)
}
func
internalInit
(
settings
*
TracingSettings
)
(
io
.
Closer
,
error
)
{
if
!
settings
.
Enabled
{
return
&
nullCloser
{},
nil
}
func
(
ts
*
TracingService
)
initGlobalTracer
()
error
{
cfg
:=
jaegercfg
.
Configuration
{
Disabled
:
!
settings
.
E
nabled
,
Disabled
:
!
ts
.
e
nabled
,
Sampler
:
&
jaegercfg
.
SamplerConfig
{
Type
:
settings
.
S
amplerType
,
Param
:
settings
.
S
amplerParam
,
Type
:
ts
.
s
amplerType
,
Param
:
ts
.
s
amplerParam
,
},
Reporter
:
&
jaegercfg
.
ReporterConfig
{
LogSpans
:
false
,
LocalAgentHostPort
:
settings
.
A
ddress
,
LocalAgentHostPort
:
ts
.
a
ddress
,
},
}
...
...
@@ -71,18 +74,31 @@ func internalInit(settings *TracingSettings) (io.Closer, error) {
options
:=
[]
jaegercfg
.
Option
{}
options
=
append
(
options
,
jaegercfg
.
Logger
(
jLogger
))
for
tag
,
value
:=
range
settings
.
C
ustomTags
{
for
tag
,
value
:=
range
ts
.
c
ustomTags
{
options
=
append
(
options
,
jaegercfg
.
Tag
(
tag
,
value
))
}
tracer
,
closer
,
err
:=
cfg
.
New
(
"grafana"
,
options
...
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
opentracing
.
InitGlobalTracer
(
tracer
)
logger
.
Info
(
"Initializing Jaeger tracer"
,
"address"
,
settings
.
Address
)
return
closer
,
nil
ts
.
closer
=
closer
return
nil
}
func
(
ts
*
TracingService
)
Run
(
ctx
context
.
Context
)
error
{
<-
ctx
.
Done
()
if
ts
.
closer
!=
nil
{
ts
.
log
.
Info
(
"Closing tracing"
)
ts
.
closer
.
Close
()
}
return
nil
}
func
splitTagSettings
(
input
string
)
map
[
string
]
string
{
...
...
@@ -110,7 +126,3 @@ func (jlw *jaegerLogWrapper) Error(msg string) {
func
(
jlw
*
jaegerLogWrapper
)
Infof
(
msg
string
,
args
...
interface
{})
{
jlw
.
logger
.
Info
(
msg
,
args
)
}
type
nullCloser
struct
{}
func
(
*
nullCloser
)
Close
()
error
{
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment