Skip to content

Commit

Permalink
move to otel exporter
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Paskal <paskal.maksim@gmail.com>
  • Loading branch information
maksim-paskal committed Dec 4, 2023
1 parent 4560dec commit 5cb424d
Show file tree
Hide file tree
Showing 55 changed files with 438 additions and 147 deletions.
2 changes: 1 addition & 1 deletion charts/kubernetes-manager/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
icon: https://helm.sh/img/helm.svg
name: kubernetes-manager
version: 1.1.0
version: 1.1.1
description: Kubernetes GUI for trunc development
maintainers:
- name: maksim-paskal # Maksim Paskal
Expand Down
7 changes: 0 additions & 7 deletions charts/kubernetes-manager/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{ if .Values.jaeger.agentOnHost }}
- name: JAEGER_AGENT_HOST
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
{{ end }}
{{ if .Values.sentry.enabled }}
- name: "SENTRY_DSN"
value: {{ .Values.sentry.host }}
Expand Down
3 changes: 0 additions & 3 deletions charts/kubernetes-manager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ resources:
cpu: 100m
memory: 200Mi

jaeger:
agentOnHost: false

sentry:
enabled: false
host: ""
Expand Down
43 changes: 8 additions & 35 deletions cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ import (
"github.com/maksim-paskal/kubernetes-manager/pkg/batch"
"github.com/maksim-paskal/kubernetes-manager/pkg/client"
"github.com/maksim-paskal/kubernetes-manager/pkg/config"
"github.com/maksim-paskal/kubernetes-manager/pkg/utils"
"github.com/maksim-paskal/kubernetes-manager/pkg/telemetry"
"github.com/maksim-paskal/kubernetes-manager/pkg/web"
"github.com/maksim-paskal/kubernetes-manager/pkg/webhook"
logrushookopentracing "github.com/maksim-paskal/logrus-hook-opentracing"
logrushooksentry "github.com/maksim-paskal/logrus-hook-sentry"
opentracing "github.com/opentracing/opentracing-go"
log "github.com/sirupsen/logrus"
"github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-lib/metrics"
"k8s.io/client-go/tools/leaderelection"
)

Expand Down Expand Up @@ -93,45 +88,17 @@ func main() {

log.AddHook(hookSentry)

hookTracing, err := logrushookopentracing.NewHook(logrushookopentracing.Options{})
if err != nil {
if err := telemetry.Init(ctx); err != nil {
log.WithError(err).Fatal()
}

log.AddHook(hookTracing)

log.Infof("Starting %s %s...", config.Namespace, config.GetVersion())

err = client.Init()
if err != nil {
log.WithError(err).Fatal()
}

cfg, err := jaegercfg.FromEnv()
if err != nil {
log.WithError(err).Fatal("Could not parse Jaeger env vars")
}

cfg.ServiceName = config.Namespace
cfg.Sampler.Type = jaeger.SamplerTypeConst
cfg.Sampler.Param = 1
cfg.Reporter.LogSpans = true

jLogger := utils.JaegerLogs{}
jMetricsFactory := metrics.NullFactory

tracer, closer, err := cfg.NewTracer(
jaegercfg.Logger(jLogger),
jaegercfg.Metrics(jMetricsFactory),
)

opentracing.SetGlobalTracer(tracer)

if err != nil {
log.WithError(err).Fatal("Could not initialize jaeger tracer")
}
defer closer.Close()

if *config.Get().BatchEnabled {
go RunLeaderElection(ctx)
}
Expand Down Expand Up @@ -164,6 +131,9 @@ func main() {
}

func RunLeaderElection(ctx context.Context) {
ctx, span := telemetry.Start(ctx, "api.RunLeaderElection")
defer span.End()

lock, err := api.GetLeaseLock(*config.Get().PodNamespace, *config.Get().PodName)
if err != nil {
log.WithError(err).Fatal()
Expand All @@ -182,6 +152,9 @@ func RunLeaderElection(ctx context.Context) {
RetryPeriod: defaultRetryPeriod,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(ctx context.Context) {
ctx, span := telemetry.Start(ctx, "api.OnStartedLeading")
defer span.End()

batch.Schedule(ctx)
},
OnStoppedLeading: func() {
Expand Down
26 changes: 18 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ require (
github.com/aws/aws-sdk-go v1.45.25
github.com/gorilla/mux v1.8.0
github.com/hetznercloud/hcloud-go v1.52.0
github.com/maksim-paskal/logrus-hook-opentracing v0.0.1
github.com/maksim-paskal/logrus-hook-sentry v0.1.1
github.com/maksim-paskal/sluglify v0.0.8
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
github.com/sirupsen/logrus v1.9.3
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/uber/jaeger-lib v2.4.1+incompatible
github.com/xanzy/go-gitlab v0.93.1
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0
go.opentelemetry.io/otel/sdk v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.2
Expand All @@ -34,23 +35,27 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/getsentry/sentry-go v0.24.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gosimple/slug v1.9.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
Expand All @@ -74,15 +79,20 @@ require (
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 5cb424d

Please sign in to comment.