Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable tracing #376

Merged
merged 1 commit into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func RunServe(version, build, date string) func(cmd *cobra.Command, args []strin
adminmw.Use(metrics)
publicmw.Use(metrics)

if tracer := d.Registry().Tracer(); tracer.IsLoaded() {
adminmw.Use(tracer)
publicmw.Use(tracer)
}

var wg sync.WaitGroup
tasks := []func(){
runAPI(d, adminmw, logger),
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,25 @@ services:
- "4456:4456"
command:
serve --config=/etc/config/oathkeeper/config.yaml
environment:
- TRACING_PROVIDER=jaeger
- TRACING_PROVIDER_JAEGER_SAMPLING_SERVER_URL=http://jaeger:5778/sampling
- TRACING_PROVIDER_JAEGER_LOCAL_AGENT_ADDRESS=jaeger:6831
- TRACING_PROVIDER_JAEGER_SAMPLING_TYPE=const
- TRACING_PROVIDER_JAEGER_SAMPLING_VALUE=1
volumes:
- type: bind
source: ./.docker_compose
target: /etc/config/oathkeeper
restart: on-failure
jaeger:
image: jaegertracing/all-in-one
ports:
- "16686:16686" # The UI port
# These are ports for collecting, sampling, agents, ...
# - "5775:5775/udp"
# - "6831:6831/udp"
# - "6832:6832/udp"
# - "5778:5778"
# - "14268:14268"
# - "9411:9411"
5 changes: 5 additions & 0 deletions driver/configuration/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/sirupsen/logrus"

"github.com/ory/fosite"
"github.com/ory/x/tracing"

"github.com/rs/cors"
)
Expand Down Expand Up @@ -51,6 +52,10 @@ type Provider interface {
ToScopeStrategy(value string, key string) fosite.ScopeStrategy
ParseURLs(sources []string) ([]url.URL, error)
JSONWebKeyURLs() []string

TracingServiceName() string
TracingProvider() string
TracingJaegerConfig() *tracing.JaegerConfig
}

type ProviderErrorHandlers interface {
Expand Down
22 changes: 22 additions & 0 deletions driver/configuration/provider_viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ory/fosite"
"github.com/ory/gojsonschema"
"github.com/ory/x/corsx"
"github.com/ory/x/tracing"
"github.com/ory/x/urlx"
"github.com/ory/x/viperx"

Expand Down Expand Up @@ -373,3 +374,24 @@ func (v *ViperProvider) MutatorConfig(id string, override json.RawMessage, dest
func (v *ViperProvider) JSONWebKeyURLs() []string {
return viperx.GetStringSlice(v.l, ViperKeyMutatorIDTokenJWKSURL, []string{})
}

func (v *ViperProvider) TracingServiceName() string {
return viperx.GetString(v.l, "tracing.service_name", "ORY Oathkeeper")
}

func (v *ViperProvider) TracingProvider() string {
return viperx.GetString(v.l, "tracing.provider", "", "TRACING_PROVIDER")
}

func (v *ViperProvider) TracingJaegerConfig() *tracing.JaegerConfig {
return &tracing.JaegerConfig{
LocalAgentHostPort: viperx.GetString(v.l, "tracing.providers.jaeger.local_agent_address", "", "TRACING_PROVIDER_JAEGER_LOCAL_AGENT_ADDRESS"),
SamplerType: viperx.GetString(v.l, "tracing.providers.jaeger.sampling.type", "const", "TRACING_PROVIDER_JAEGER_SAMPLING_TYPE"),
SamplerValue: viperx.GetFloat64(v.l, "tracing.providers.jaeger.sampling.value", float64(1), "TRACING_PROVIDER_JAEGER_SAMPLING_VALUE"),
SamplerServerURL: viperx.GetString(v.l, "tracing.providers.jaeger.sampling.server_url", "", "TRACING_PROVIDER_JAEGER_SAMPLING_SERVER_URL"),
Propagation: stringsx.Coalesce(
viper.GetString("JAEGER_PROPAGATION"), // Standard Jaeger client config
viperx.GetString(v.l, "tracing.providers.jaeger.propagation", "", "TRACING_PROVIDER_JAEGER_PROPAGATION"),
),
}
}
2 changes: 2 additions & 0 deletions driver/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ory/oathkeeper/rule"
"github.com/ory/oathkeeper/x"
"github.com/ory/x/healthx"
"github.com/ory/x/tracing"
)

type Registry interface {
Expand All @@ -34,6 +35,7 @@ type Registry interface {
CredentialHandler() *api.CredentialsHandler

Proxy() *proxy.Proxy
Tracer() *tracing.Tracer

authn.Registry
authz.Registry
Expand Down
19 changes: 19 additions & 0 deletions driver/registry_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ory/oathkeeper/proxy"

"github.com/ory/x/logrusx"
"github.com/ory/x/tracing"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -38,6 +39,7 @@ type RegistryMemory struct {
logger logrus.FieldLogger
writer herodot.Writer
c configuration.Provider
trc *tracing.Tracer

ch *api.CredentialsHandler

Expand Down Expand Up @@ -390,3 +392,20 @@ func (r *RegistryMemory) prepareMutators() {
}
}
}

func (r *RegistryMemory) Tracer() *tracing.Tracer {
if r.trc == nil {
r.trc = &tracing.Tracer{
ServiceName: r.c.TracingServiceName(),
JaegerConfig: r.c.TracingJaegerConfig(),
Provider: r.c.TracingProvider(),
Logger: r.Logger(),
}

if err := r.trc.Setup(); err != nil {
r.Logger().WithError(err).Fatalf("Unable to initialize Tracer.")
}
}

return r.trc
}