Skip to content

Commit

Permalink
Feature/jaeger agent (#27)
Browse files Browse the repository at this point in the history
* added jaeger agent

* Merged collector URL to Jaeger config section

* simplified jaeger config watcher

* private tace provider ctor function
  • Loading branch information
fraliv13 authored Nov 24, 2021
1 parent 3a966ef commit 3279b6a
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 46 deletions.
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
"mode": "auto",
"program": "./cmd/rusid",
"args": ["--app-id", "rusi-vs-code-debug", "--config", "../../examples/components/config-node-pipeline.yaml", "--components-path", "../../examples/components", "--v", "4"]
},
{
"name": "Test Current File",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${relativeFileDirname}",
"args": []
}

]
Expand Down
5 changes: 3 additions & 2 deletions examples/components/config-node-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ spec:
enabled: true
tracing:
samplingRate: '1'
zipkin:
endpointAddress: 'http://kube-worker1.totalsoft.local:31034/api/traces'
jaeger:
useAgent: true
collectorEndpointAddress: 'http://kube-worker1.totalsoft.local:31034/api/traces'
subscriberPipeline:
handlers:
- name: pubsub-uppercase
Expand Down
13 changes: 8 additions & 5 deletions helm/crds/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,18 @@ spec:
tracing:
description: TracingSpec is the spec object in ConfigurationSpec
properties:
zipkin:
jaeger:
type: object
description: Defines the Zipkin trace configurations
description: Defines the Jaeger trace configurations
properties:
endpointAddress:
description: The endpoint address of Zipkin server to receive traces
useAgent:
description: Determines if a Jaeger agent is used
type: boolean
collectorEndpointAddress:
description: The endpoint address of Jaeger collector to receive traces. Ignored if 'useAgent' is set.
type: string
required:
- zipkin
- jaeger
type: object
pubSub:
description: Defines the default pubSub
Expand Down
13 changes: 8 additions & 5 deletions internal/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package diagnostics

import (
"context"
"k8s.io/klog/v2"
"rusi/pkg/custom-resource/configuration"
configuration_loader "rusi/pkg/custom-resource/configuration/loader"

"k8s.io/klog/v2"
)

func WatchConfig(ctx context.Context, configLoader configuration_loader.ConfigurationLoader,
tracerFunc func(url string) (func(), error)) {
tracerFunc func(url string, useAgent bool) (func(), error)) {

var (
prevConf configuration.Spec
Expand All @@ -21,13 +22,15 @@ func WatchConfig(ctx context.Context, configLoader configuration_loader.Configur
}

for cfg := range configChan {
if prevConf.TracingSpec.Zipkin.EndpointAddresss != cfg.TracingSpec.Zipkin.EndpointAddresss {
changed := cfg.TracingSpec != prevConf.TracingSpec
validConfig := cfg.TracingSpec.Jaeger.UseAgent || cfg.TracingSpec.Jaeger.CollectorEndpointAddress != ""
if changed {
if tracingStopper != nil {
//flush prev logs
tracingStopper()
}
if cfg.TracingSpec.Zipkin.EndpointAddresss != "" {
tracingStopper, err = tracerFunc(cfg.TracingSpec.Zipkin.EndpointAddresss)
if validConfig {
tracingStopper, err = tracerFunc(cfg.TracingSpec.Jaeger.CollectorEndpointAddress, cfg.TracingSpec.Jaeger.UseAgent)
if err != nil {
klog.ErrorS(err, "error creating tracer")
}
Expand Down
17 changes: 12 additions & 5 deletions internal/tracing/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ import (
// the Jaeger exporter that will send spans to the provided url. The returned
// TracerProvider will also use a Resource configured with all the information
// about the application.
func JaegerTracerProvider(url, serviceName string) (*tracesdk.TracerProvider, error) {
func jaegerTracerProvider(url string, useAgent bool, serviceName string) (*tracesdk.TracerProvider, error) {
// Create the Jaeger exporter
exp, err := jaeger_exporters.New(jaeger_exporters.WithCollectorEndpoint(jaeger_exporters.WithEndpoint(url)))
var exp *jaeger_exporters.Exporter
var err error

if useAgent {
exp, err = jaeger_exporters.New(jaeger_exporters.WithAgentEndpoint())
} else {
exp, err = jaeger_exporters.New(jaeger_exporters.WithCollectorEndpoint(jaeger_exporters.WithEndpoint(url)))
}
if err != nil {
return nil, err
}
Expand All @@ -36,9 +43,9 @@ func JaegerTracerProvider(url, serviceName string) (*tracesdk.TracerProvider, er
return tp, nil
}

func SetJaegerTracing(serviceName string) func(url string) (func(), error) {
return func(url string) (func(), error) {
tp, err := JaegerTracerProvider(url, serviceName)
func SetJaegerTracing(serviceName string) func(url string, useAgent bool) (func(), error) {
return func(url string, useAgent bool) (func(), error) {
tp, err := jaegerTracerProvider(url, useAgent, serviceName)
if err != nil {
return nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/custom-resource/configuration/loader/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ metadata:
name: secretappconfig
spec:
tracing:
zipkin:
endpointAddress: "${RUSI_ZIPKIN_ENDPOINT}" `)
jaeger:
collectorEndpointAddress: "${RUSI_JAEGER_COLLECTOR_ENDPOINT}"
useAgent: false `)

defer os.Remove("config.yaml")
defer os.Remove("env_variables_config.yaml")
Expand Down Expand Up @@ -69,12 +70,12 @@ spec:
}

t.Run("Parse environment variables", func(t *testing.T) {
os.Setenv("RUSI_ZIPKIN_ENDPOINT", "http://localhost:42323")
os.Setenv("RUSI_JAEGER_COLLECTOR_ENDPOINT", "http://localhost:42323")
configChan, err := LoadStandaloneConfiguration("env_variables_config.yaml")(ctx)
config := <-configChan
assert.NoError(t, err, "Unexpected error")
assert.NotNil(t, config, "Config not loaded as expected")
assert.Equal(t, "http://localhost:42323", config.TracingSpec.Zipkin.EndpointAddresss)
assert.Equal(t, "http://localhost:42323", config.TracingSpec.Jaeger.CollectorEndpointAddress)
})

t.Run("Load config file", func(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions pkg/custom-resource/configuration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ type HandlerSpec struct {

// TracingSpec defines distributed tracing configuration.
type TracingSpec struct {
Zipkin ZipkinSpec `json:"zipkin" yaml:"zipkin"`
Jaeger JaegerSpec `json:"jaeger" yaml:"jaeger"`
}

// ZipkinSpec defines Zipkin trace configurations.
type ZipkinSpec struct {
EndpointAddresss string `json:"endpointAddress" yaml:"endpointAddress"`
// JaegerSpec defines Jaeger trace configurations.
type JaegerSpec struct {
UseAgent bool `json:"useAgent" yaml:"useAgent"`
CollectorEndpointAddress string `json:"collectorEndpointAddress" yaml:"collectorEndpointAddress"`
}

// FeatureSpec defines the features that are enabled/disabled.
Expand Down
9 changes: 5 additions & 4 deletions pkg/operator/apis/rusi/v1alpha1/configurationTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ type HandlerSpec struct {

// TracingSpec defines distributed tracing configuration.
type TracingSpec struct {
Zipkin ZipkinSpec `json:"zipkin"`
Jaeger JaegerSpec `json:"jaeger"`
}

// ZipkinSpec defines Zipkin trace configurations.
type ZipkinSpec struct {
EndpointAddresss string `json:"endpointAddress"`
// JaegerSpec defines Jaeger trace configurations.
type JaegerSpec struct {
UseAgent bool `json:"useAgent"`
CollectorEndpointAddress string `json:"collectorEndpointAddress"`
}

// FeatureSpec defines the features that are enabled/disabled.
Expand Down
34 changes: 17 additions & 17 deletions pkg/operator/apis/rusi/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3279b6a

Please sign in to comment.