From 5cb424dfffd8cc2082931bc59c62a82d4f28388b Mon Sep 17 00:00:00 2001 From: Maksim Paskal Date: Mon, 4 Dec 2023 19:11:58 +0000 Subject: [PATCH] move to otel exporter Signed-off-by: Maksim Paskal --- charts/kubernetes-manager/Chart.yaml | 2 +- .../kubernetes-manager/templates/_helpers.tpl | 7 -- charts/kubernetes-manager/values.yaml | 3 - cmd/main/main.go | 43 ++-------- go.mod | 26 ++++-- go.sum | 74 +++++++++-------- pkg/api/DeletePod.go | 4 + pkg/api/DeleteTemporaryTokens.go | 7 ++ pkg/api/GetClusterInfo.go | 4 + pkg/api/GetCommitsBehind.go | 4 + pkg/api/GetContainerInfo.go | 4 + pkg/api/GetEnvironmentByID.go | 4 + pkg/api/GetEvents.go | 4 + pkg/api/GetGitlabPipelinesStatus.go | 4 + pkg/api/GetHosts.go | 4 + pkg/api/GetKubeconfig.go | 7 ++ pkg/api/GetPodContainerLog.go | 4 + pkg/api/GetPodContainers.go | 4 + pkg/api/GetPodsInfo.go | 13 +++ pkg/api/GetRemoteServers.go | 4 + pkg/api/ScaleDownDelay.go | 4 + pkg/api/SetRemoteServerAction.go | 4 + pkg/api/SetRemoteServerDelay.go | 4 + pkg/api/SetRemoteServerLabels.go | 4 + pkg/api/createGitlabPipeline.go | 4 + pkg/api/createGitlabPipelinesByServices.go | 4 + pkg/api/deleteALL.go | 5 ++ pkg/api/deleteClusterRolesAndBindings.go | 7 ++ pkg/api/deleteNamespace.go | 4 + pkg/api/disableHPA.go | 4 + pkg/api/disableMTLS.go | 4 + pkg/api/environment.go | 13 +++ pkg/api/execContainer.go | 4 + pkg/api/getContainers.go | 4 + pkg/api/getGitlabProjectRefs.go | 4 + pkg/api/getGitlabProjects.go | 4 + pkg/api/getGitlabProjectsInfo.go | 4 + pkg/api/getPodByImage.go | 4 + pkg/api/getServices.go | 4 + pkg/api/saveNamespaceMeta.go | 4 + pkg/api/scaleALL.go | 4 + pkg/api/scaleNamespace.go | 15 +++- pkg/api/startNewEnvironment.go | 10 +++ pkg/batch/batch.go | 32 ++++---- pkg/jira/jira.go | 4 + pkg/modules/autotests/autotests.go | 10 +++ pkg/telemetry/telemetry.go | 79 +++++++++++++++++++ pkg/utils/utils.go | 11 --- pkg/web/handlerAPI.go | 22 +++--- pkg/web/handlerEnvironment.go | 35 +++++--- pkg/web/handlerUser.go | 10 +-- pkg/web/web.go | 13 ++- pkg/webhook/aws/aws.go | 10 +++ pkg/webhook/azure/azure.go | 4 + pkg/webhook/webhook.go | 7 ++ 55 files changed, 438 insertions(+), 147 deletions(-) create mode 100644 pkg/telemetry/telemetry.go diff --git a/charts/kubernetes-manager/Chart.yaml b/charts/kubernetes-manager/Chart.yaml index d93e13c..c7ea18f 100644 --- a/charts/kubernetes-manager/Chart.yaml +++ b/charts/kubernetes-manager/Chart.yaml @@ -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 diff --git a/charts/kubernetes-manager/templates/_helpers.tpl b/charts/kubernetes-manager/templates/_helpers.tpl index ee021c1..c25969c 100644 --- a/charts/kubernetes-manager/templates/_helpers.tpl +++ b/charts/kubernetes-manager/templates/_helpers.tpl @@ -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 }} diff --git a/charts/kubernetes-manager/values.yaml b/charts/kubernetes-manager/values.yaml index 53ca070..bab4075 100644 --- a/charts/kubernetes-manager/values.yaml +++ b/charts/kubernetes-manager/values.yaml @@ -17,9 +17,6 @@ resources: cpu: 100m memory: 200Mi -jaeger: - agentOnHost: false - sentry: enabled: false host: "" diff --git a/cmd/main/main.go b/cmd/main/main.go index 26105d0..ac86b68 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -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" ) @@ -93,13 +88,10 @@ 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() @@ -107,31 +99,6 @@ func main() { 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) } @@ -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() @@ -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() { diff --git a/go.mod b/go.mod index 3b57efa..0fbb7c6 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -34,11 +35,14 @@ 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 @@ -46,11 +50,12 @@ require ( 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 @@ -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 diff --git a/go.sum b/go.sum index 203af26..4269405 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,6 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1. github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.0 h1:hVeq+yCyUi+MsoO/CU95yqCIcdzra5ovzk8Q2BBpV2M= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= -github.com/HdrHistogram/hdrhistogram-go v1.0.1 h1:GX8GAYDuhlFQnI2fRDHQhTlkHMz8bEn0jTI6LJU0mpw= -github.com/HdrHistogram/hdrhistogram-go v1.0.1/go.mod h1:BWJ+nMSHY3L41Zj7CA3uXnloDp7xxV0YvstAE7nKTaM= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= @@ -34,6 +32,8 @@ github.com/aws/aws-sdk-go v1.45.25 h1:c4fLlh5sLdK2DCRTY1z0hyuJZU4ygxX8m1FswL6/nF github.com/aws/aws-sdk-go v1.45.25/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -46,13 +46,18 @@ github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhF github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/getsentry/sentry-go v0.24.0 h1:02b7qEmJ56EHGe9KFgjArjU/vG/aywm7Efgu+iPc01Y= github.com/getsentry/sentry-go v0.24.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= @@ -65,6 +70,8 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= +github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -75,10 +82,9 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -93,6 +99,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gosimple/slug v1.9.0 h1:r5vDcYrFz9BmfIAMC829un9hq7hKM4cHUrsv36LbEqs= github.com/gosimple/slug v1.9.0/go.mod h1:AMZ+sOVe65uByN3kgEyf9WEBKBCSS+dJjMX9x4vDJbg= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= @@ -126,8 +134,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/maksim-paskal/logrus-hook-opentracing v0.0.1 h1:X+6aN/SQwCKkLsU/r5AqCBHh5m6Wa5hmUwqx7UzjzgE= -github.com/maksim-paskal/logrus-hook-opentracing v0.0.1/go.mod h1:zD0d6Bk5rRxC8rjHdzwW28m2BRmh2LuZZQwxutw7WO4= github.com/maksim-paskal/logrus-hook-sentry v0.1.1 h1:9IQ8kn6XwZJ/yDjkIyTLAce7k78J3WfeZtjIh3jA/MY= github.com/maksim-paskal/logrus-hook-sentry v0.1.1/go.mod h1:FpJn8dMDsuG8/lt65HQauZuXIiG2LqAYM+vbKV//Ga0= github.com/maksim-paskal/sluglify v0.0.8 h1:i5OIkx1eDAd68au46t4sXJcDod1rINLB8oQaX04C2Ww= @@ -147,13 +153,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/onsi/ginkgo/v2 v2.9.4 h1:xR7vG4IXt5RWx6FfIjyAtsoMAtnc3C/rFXBBd2AjZwE= github.com/onsi/ginkgo/v2 v2.9.4/go.mod h1:gCQYp2Q+kSoIj7ykSVb9nskRSsR6PUj4AiLywzIhbKM= github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg= -github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= -github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= @@ -174,39 +177,44 @@ github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHV github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= -github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o= -github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= -github.com/uber/jaeger-lib v2.4.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= -github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= -github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/xanzy/go-gitlab v0.93.1 h1:f7J33cw/P9b/8paIOoH0F3H+TFrswvWHs6yUgoTp9LY= github.com/xanzy/go-gitlab v0.93.1/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= -go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo= +go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= +go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0= +go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= +go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= +go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= +go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= +go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= +go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -234,18 +242,16 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210105210732-16f7687f5001/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -273,12 +279,19 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4= +google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q= +google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= @@ -288,7 +301,6 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210105161348-2e78108cf5f8/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= k8s.io/api v0.28.2 h1:9mpl5mOb6vXZvqbQmankOfPIGiudghwCoLl1EYfUZbw= diff --git a/pkg/api/DeletePod.go b/pkg/api/DeletePod.go index dd95aaf..74ee832 100644 --- a/pkg/api/DeletePod.go +++ b/pkg/api/DeletePod.go @@ -15,10 +15,14 @@ package api import ( "context" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (e *Environment) DeletePod(ctx context.Context, podName string) error { + ctx, span := telemetry.Start(ctx, "api.DeletePod") + defer span.End() + err := e.clientset.CoreV1().Pods(e.Namespace).Delete(ctx, podName, metav1.DeleteOptions{}) if err != nil { return err diff --git a/pkg/api/DeleteTemporaryTokens.go b/pkg/api/DeleteTemporaryTokens.go index bfa126f..4029e00 100644 --- a/pkg/api/DeleteTemporaryTokens.go +++ b/pkg/api/DeleteTemporaryTokens.go @@ -16,6 +16,7 @@ import ( "context" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -23,6 +24,9 @@ import ( ) func (e *Environment) DeleteTemporaryTokens(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.DeleteTemporaryTokens") + defer span.End() + if e.IsSystemNamespace() { return errors.Wrap(errIsSystemNamespace, e.Namespace) } @@ -50,6 +54,9 @@ func (e *Environment) DeleteTemporaryTokens(ctx context.Context) error { } func (e *Environment) deleteTemporaryToken(ctx context.Context, name string) error { + ctx, span := telemetry.Start(ctx, "api.deleteTemporaryToken") + defer span.End() + err := e.clientset.RbacV1().RoleBindings(e.Namespace).Delete(ctx, name, metav1.DeleteOptions{}) if err != nil { log.WithError(err).Errorf("error deleting role binding %s", name) diff --git a/pkg/api/GetClusterInfo.go b/pkg/api/GetClusterInfo.go index f4993f5..74da0d7 100644 --- a/pkg/api/GetClusterInfo.go +++ b/pkg/api/GetClusterInfo.go @@ -17,6 +17,7 @@ import ( "fmt" "github.com/maksim-paskal/kubernetes-manager/pkg/client" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -56,6 +57,9 @@ func (c *ClusterInfo) ToHuman() *ClusterInfoHuman { } func GetClusterInfo(ctx context.Context, name string) (*ClusterInfo, error) { + ctx, span := telemetry.Start(ctx, "api.GetClusterInfo") + defer span.End() + clientset, err := client.GetClientset(name) if err != nil { return nil, errors.Wrap(err, "can get clientset") diff --git a/pkg/api/GetCommitsBehind.go b/pkg/api/GetCommitsBehind.go index abbd46d..ea3270f 100644 --- a/pkg/api/GetCommitsBehind.go +++ b/pkg/api/GetCommitsBehind.go @@ -16,6 +16,7 @@ import ( "context" "github.com/maksim-paskal/kubernetes-manager/pkg/client" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" "github.com/xanzy/go-gitlab" ) @@ -28,6 +29,9 @@ type GetCommitsBehindResult struct { } func GetCommitsBehind(ctx context.Context, p *gitlab.Project, projectID, branch string) (*GetCommitsBehindResult, error) { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.GetCommitsBehind") + defer span.End() + gitlabClient := client.GetGitlabClient() if gitlabClient == nil { diff --git a/pkg/api/GetContainerInfo.go b/pkg/api/GetContainerInfo.go index 45de94d..a543004 100644 --- a/pkg/api/GetContainerInfo.go +++ b/pkg/api/GetContainerInfo.go @@ -15,6 +15,7 @@ package api import ( "context" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" @@ -28,6 +29,9 @@ type GetContainerInfoResult struct { } func (e *Environment) GetContainerInfo(ctx context.Context, container string) (*GetContainerInfoResult, error) { + ctx, span := telemetry.Start(ctx, "api.GetContainerInfo") + defer span.End() + containerInfo, err := types.NewContainerInfo(container) if err != nil { return nil, err diff --git a/pkg/api/GetEnvironmentByID.go b/pkg/api/GetEnvironmentByID.go index 02b71c4..8957212 100644 --- a/pkg/api/GetEnvironmentByID.go +++ b/pkg/api/GetEnvironmentByID.go @@ -16,12 +16,16 @@ import ( "context" "github.com/maksim-paskal/kubernetes-manager/pkg/client" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func GetEnvironmentByID(ctx context.Context, id string) (*Environment, error) { + ctx, span := telemetry.Start(ctx, "api.GetEnvironmentByID") + defer span.End() + idInfo, err := types.NewIDInfo(id) if err != nil { return nil, errors.Wrap(err, "can not parse id") diff --git a/pkg/api/GetEvents.go b/pkg/api/GetEvents.go index e3bdc3b..5131f8c 100644 --- a/pkg/api/GetEvents.go +++ b/pkg/api/GetEvents.go @@ -18,6 +18,7 @@ import ( "sort" "time" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -34,6 +35,9 @@ type GetEventsResult struct { } func (e *Environment) GetEvents(ctx context.Context) ([]*GetEventsResult, error) { + ctx, span := telemetry.Start(ctx, "api.GetEvents") + defer span.End() + events, err := e.clientset.CoreV1().Events(e.Namespace).List(ctx, metav1.ListOptions{}) if err != nil { return nil, errors.Wrap(err, "failed to get events") diff --git a/pkg/api/GetGitlabPipelinesStatus.go b/pkg/api/GetGitlabPipelinesStatus.go index d18792e..ed421be 100644 --- a/pkg/api/GetGitlabPipelinesStatus.go +++ b/pkg/api/GetGitlabPipelinesStatus.go @@ -16,6 +16,7 @@ import ( "context" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" "github.com/xanzy/go-gitlab" ) @@ -29,6 +30,9 @@ type GetGitlabPipelinesStatusResults struct { const GetGitlabPipelinesStatusMaxLimit = 20 func (e *Environment) GetGitlabPipelinesStatus(ctx context.Context, projectID string) (*GetGitlabPipelinesStatusResults, error) { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.GetGitlabPipelinesStatus") + defer span.End() + if e.gitlabClient == nil { return nil, errNoGitlabClient } diff --git a/pkg/api/GetHosts.go b/pkg/api/GetHosts.go index 8fe912e..988aea0 100644 --- a/pkg/api/GetHosts.go +++ b/pkg/api/GetHosts.go @@ -17,6 +17,7 @@ import ( "fmt" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,6 +28,9 @@ const ( ) func (e *Environment) GetHosts(ctx context.Context) ([]string, []string, error) { + ctx, span := telemetry.Start(ctx, "api.GetHosts") + defer span.End() + opt := metav1.ListOptions{ LabelSelector: config.FilterLabels, } diff --git a/pkg/api/GetKubeconfig.go b/pkg/api/GetKubeconfig.go index 75ad0fa..87801d4 100644 --- a/pkg/api/GetKubeconfig.go +++ b/pkg/api/GetKubeconfig.go @@ -18,6 +18,7 @@ import ( "fmt" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" @@ -61,6 +62,9 @@ users: } func (e *Environment) GetKubeconfig(ctx context.Context) (*GetClusterKubeconfigResult, error) { + ctx, span := telemetry.Start(ctx, "api.GetKubeconfig") + defer span.End() + temporaryToken, err := e.createTemporaryToken(ctx) if err != nil { return nil, err @@ -85,6 +89,9 @@ func (e *Environment) GetKubeconfig(ctx context.Context) (*GetClusterKubeconfigR // remove old tokens with // kubectl delete sa,role,rolebinding -A -lkubernetes-manager=true. func (e *Environment) createTemporaryToken(ctx context.Context) (*corev1.Secret, error) { + ctx, span := telemetry.Start(ctx, "api.createTemporaryToken") + defer span.End() + if e.IsSystemNamespace() { return nil, errors.New("cannot create temporary token in system namespace") } diff --git a/pkg/api/GetPodContainerLog.go b/pkg/api/GetPodContainerLog.go index ab6fda5..f7fc851 100644 --- a/pkg/api/GetPodContainerLog.go +++ b/pkg/api/GetPodContainerLog.go @@ -17,6 +17,7 @@ import ( "context" "io" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" corev1 "k8s.io/api/core/v1" ) @@ -48,6 +49,9 @@ func (l *GetPodContainerLogRequest) GetTailLines() *int64 { } func (e *Environment) GetPodContainerLog(ctx context.Context, input *GetPodContainerLogRequest) (string, error) { + ctx, span := telemetry.Start(ctx, "api.GetPodContainerLog") + defer span.End() + podLogOptions := corev1.PodLogOptions{ Container: input.Container, Follow: false, diff --git a/pkg/api/GetPodContainers.go b/pkg/api/GetPodContainers.go index 8a5faee..e29c9cf 100644 --- a/pkg/api/GetPodContainers.go +++ b/pkg/api/GetPodContainers.go @@ -15,6 +15,7 @@ package api import ( "context" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -23,6 +24,9 @@ type PodContainer struct { } func (e *Environment) GetPodContainers(ctx context.Context, name string) ([]*PodContainer, error) { + ctx, span := telemetry.Start(ctx, "api.GetPodContainers") + defer span.End() + pod, err := e.clientset.CoreV1().Pods(e.Namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { return nil, err diff --git a/pkg/api/GetPodsInfo.go b/pkg/api/GetPodsInfo.go index 1659906..b9e420d 100644 --- a/pkg/api/GetPodsInfo.go +++ b/pkg/api/GetPodsInfo.go @@ -15,7 +15,9 @@ package api import ( "context" "fmt" + "strconv" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -36,6 +38,9 @@ type PodsInfo struct { } func (e *Environment) GetPodsInfo(ctx context.Context) (*PodsInfo, error) { + ctx, span := telemetry.Start(ctx, "api.GetPodsInfo") + defer span.End() + pods, err := e.clientset.CoreV1().Pods(e.Namespace).List(ctx, metav1.ListOptions{ FieldSelector: "status.phase!=Succeeded", }) @@ -43,6 +48,10 @@ func (e *Environment) GetPodsInfo(ctx context.Context) (*PodsInfo, error) { return nil, errors.Wrap(err, "error list pods") } + telemetry.Event(span, "loaded pods", map[string]string{ + "len": strconv.Itoa(len(pods.Items)), + }) + result := PodsInfo{} result.PodsFailedName = make([]string, 0) @@ -95,6 +104,10 @@ func (e *Environment) GetPodsInfo(ctx context.Context) (*PodsInfo, error) { return nil, errors.Wrap(err, "error list pvc") } + telemetry.Event(span, "loaded pvc", map[string]string{ + "len": strconv.Itoa(len(pvc.Items)), + }) + for _, pvc := range pvc.Items { result.storageRequests += pvc.Status.Capacity.Storage().AsApproximateFloat64() } diff --git a/pkg/api/GetRemoteServers.go b/pkg/api/GetRemoteServers.go index 6c441f4..af9cc8b 100644 --- a/pkg/api/GetRemoteServers.go +++ b/pkg/api/GetRemoteServers.go @@ -22,6 +22,7 @@ import ( "github.com/hetznercloud/hcloud-go/hcloud" "github.com/maksim-paskal/kubernetes-manager/pkg/client" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -93,6 +94,9 @@ var errNoHetznerCloudToken = errors.New("no hetzner cloud token, please set it i // return all remote servers. func GetRemoteServers(ctx context.Context) ([]*GetRemoteServerItem, error) { + ctx, span := telemetry.Start(ctx, "api.GetRemoteServers") + defer span.End() + if len(config.Get().RemoteServer.HetznerToken) == 0 { return nil, errNoHetznerCloudToken } diff --git a/pkg/api/ScaleDownDelay.go b/pkg/api/ScaleDownDelay.go index 57b389a..09e22bb 100644 --- a/pkg/api/ScaleDownDelay.go +++ b/pkg/api/ScaleDownDelay.go @@ -17,10 +17,14 @@ import ( "time" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" ) func (e *Environment) ScaleDownDelay(ctx context.Context, durationTime time.Duration) error { + ctx, span := telemetry.Start(ctx, "api.ScaleDownDelay") + defer span.End() + annotation := e.NamespaceAnnotations if annotation == nil { annotation = make(map[string]string) diff --git a/pkg/api/SetRemoteServerAction.go b/pkg/api/SetRemoteServerAction.go index 44ada62..a4c2713 100644 --- a/pkg/api/SetRemoteServerAction.go +++ b/pkg/api/SetRemoteServerAction.go @@ -20,6 +20,7 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/client" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" ) @@ -51,6 +52,9 @@ type SetRemoteServerActionInput struct { // return all remote servers. func SetRemoteServerAction(ctx context.Context, input SetRemoteServerActionInput) error { + ctx, span := telemetry.Start(ctx, "api.SetRemoteServerAction") + defer span.End() + if input.Cloud != "hcloud" { return errors.New("cloud not supported") } diff --git a/pkg/api/SetRemoteServerDelay.go b/pkg/api/SetRemoteServerDelay.go index bfa7093..1bfc9b0 100644 --- a/pkg/api/SetRemoteServerDelay.go +++ b/pkg/api/SetRemoteServerDelay.go @@ -19,6 +19,7 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/client" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" ) @@ -31,6 +32,9 @@ type SetRemoteServerDelayInput struct { // set autopause date for remote server. func SetRemoteServerDelay(ctx context.Context, input SetRemoteServerDelayInput) error { + ctx, span := telemetry.Start(ctx, "api.SetRemoteServerDelay") + defer span.End() + if input.Cloud != "hcloud" { return errors.New("cloud not supported") } diff --git a/pkg/api/SetRemoteServerLabels.go b/pkg/api/SetRemoteServerLabels.go index 825d703..ed3f911 100644 --- a/pkg/api/SetRemoteServerLabels.go +++ b/pkg/api/SetRemoteServerLabels.go @@ -17,10 +17,14 @@ import ( "github.com/hetznercloud/hcloud-go/hcloud" "github.com/maksim-paskal/kubernetes-manager/pkg/client" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" ) func SetRemoteServerLabels(ctx context.Context, server *hcloud.Server, newLabels map[string]string) error { + ctx, span := telemetry.Start(ctx, "api.SetRemoteServerLabels") + defer span.End() + labels := server.Labels if labels == nil { labels = make(map[string]string) diff --git a/pkg/api/createGitlabPipeline.go b/pkg/api/createGitlabPipeline.go index dbf3d7f..dfc0a23 100644 --- a/pkg/api/createGitlabPipeline.go +++ b/pkg/api/createGitlabPipeline.go @@ -16,6 +16,7 @@ import ( "context" "strconv" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" "github.com/xanzy/go-gitlab" ) @@ -55,6 +56,9 @@ const ( ) func (e *Environment) CreateGitlabPipeline(ctx context.Context, projectID, ref string, op GitlabPipelineOperation) (string, error) { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.CreateGitlabPipeline") + defer span.End() + if e.gitlabClient == nil { return "", errNoGitlabClient } diff --git a/pkg/api/createGitlabPipelinesByServices.go b/pkg/api/createGitlabPipelinesByServices.go index 14c2ee0..04a4cf9 100644 --- a/pkg/api/createGitlabPipelinesByServices.go +++ b/pkg/api/createGitlabPipelinesByServices.go @@ -19,12 +19,16 @@ import ( "sync" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" ) var errCreateGitlabPipelinesByServicesError = errors.New("error creating pipelines") func (e *Environment) CreateGitlabPipelinesByServices(ctx context.Context, projectProfile, services string, op GitlabPipelineOperation) error { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.CreateGitlabPipelinesByServices") + defer span.End() + if len(services) == 0 { return errors.New("no services was selected") } diff --git a/pkg/api/deleteALL.go b/pkg/api/deleteALL.go index b150f6d..fa9827e 100644 --- a/pkg/api/deleteALL.go +++ b/pkg/api/deleteALL.go @@ -16,6 +16,8 @@ import ( "context" "encoding/json" "fmt" + + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" ) type DeleteALLResultOperation struct { @@ -38,6 +40,9 @@ func (t *DeleteALLResult) JSON() string { } func (e *Environment) DeleteALL(ctx context.Context) *DeleteALLResult { + ctx, span := telemetry.Start(ctx, "api.DeleteALL") + defer span.End() + deleteNamespace := make(chan error) deleteClusterRolesAndBindings := make(chan error) diff --git a/pkg/api/deleteClusterRolesAndBindings.go b/pkg/api/deleteClusterRolesAndBindings.go index 195126c..7488760 100644 --- a/pkg/api/deleteClusterRolesAndBindings.go +++ b/pkg/api/deleteClusterRolesAndBindings.go @@ -16,6 +16,7 @@ import ( "context" "strings" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -23,6 +24,9 @@ import ( ) func deleteClusterRoleAndBinding(ctx context.Context, clientset *kubernetes.Clientset, roleName string, roleBindingName string) error { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.deleteClusterRoleAndBinding") + defer span.End() + if strings.HasPrefix(roleName, "system:") || strings.HasPrefix(roleBindingName, "system:") { log.Warnf("role %s or binding %s can not be deleted", roleName, roleBindingName) @@ -46,6 +50,9 @@ func deleteClusterRoleAndBinding(ctx context.Context, clientset *kubernetes.Clie // delete all cluster role and bindings linken to namespace. func (e *Environment) DeleteClusterRolesAndBindings(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.DeleteClusterRolesAndBindings") + defer span.End() + if e.IsSystemNamespace() { return errors.Wrap(errIsSystemNamespace, e.Namespace) } diff --git a/pkg/api/deleteNamespace.go b/pkg/api/deleteNamespace.go index 7533835..3d6719f 100644 --- a/pkg/api/deleteNamespace.go +++ b/pkg/api/deleteNamespace.go @@ -15,12 +15,16 @@ package api import ( "context" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // DeleteNamespace delete kubernetes namespace. func (e *Environment) DeleteNamespace(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.DeleteNamespace") + defer span.End() + if e.IsSystemNamespace() { return errors.Wrap(errIsSystemNamespace, e.Namespace) } diff --git a/pkg/api/disableHPA.go b/pkg/api/disableHPA.go index 4df7211..95ff11e 100644 --- a/pkg/api/disableHPA.go +++ b/pkg/api/disableHPA.go @@ -15,11 +15,15 @@ package api import ( "context" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (e *Environment) DisableHPA(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.DisableHPA") + defer span.End() + if e.IsSystemNamespace() { return errors.Wrap(errIsSystemNamespace, e.Namespace) } diff --git a/pkg/api/disableMTLS.go b/pkg/api/disableMTLS.go index fe77968..b5f5d58 100644 --- a/pkg/api/disableMTLS.go +++ b/pkg/api/disableMTLS.go @@ -15,6 +15,7 @@ package api import ( "context" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -26,6 +27,9 @@ const ( ) func (e *Environment) DisableMTLS(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.DisableMTLS") + defer span.End() + if e.IsSystemNamespace() { return errors.Wrap(errIsSystemNamespace, e.Namespace) } diff --git a/pkg/api/environment.go b/pkg/api/environment.go index 06385c4..9fc5d2d 100644 --- a/pkg/api/environment.go +++ b/pkg/api/environment.go @@ -18,6 +18,7 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/client" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -51,6 +52,9 @@ type Environment struct { // GetEnvironments list all kubernetes-manager environments. func GetEnvironments(ctx context.Context, filter string) ([]*Environment, error) { + ctx, span := telemetry.Start(ctx, "api.GetEnvironments") + defer span.End() + result := make([]*Environment, 0) for cluster := range client.GetAllClientsets() { @@ -66,6 +70,9 @@ func GetEnvironments(ctx context.Context, filter string) ([]*Environment, error) } func getEnvironmentsFromCluster(ctx context.Context, cluster string, filter string) ([]*Environment, error) { + ctx, span := telemetry.Start(ctx, "api.getEnvironmentsFromCluster") + defer span.End() + clientset, err := client.GetClientset(cluster) if err != nil { return nil, errors.Wrap(err, "can not get clientset") @@ -104,6 +111,9 @@ func getEnvironmentsFromCluster(ctx context.Context, cluster string, filter stri } func (e *Environment) loadFromNamespace(ctx context.Context, namespace corev1.Namespace) error { + ctx, span := telemetry.Start(ctx, "api.loadFromNamespace") + defer span.End() + if namespace.Labels == nil || namespace.Labels[config.Namespace] != config.TrueValue { return errors.New("namespace is not managed by kubernetes-manager") } @@ -177,6 +187,9 @@ func (e *Environment) loadFromNamespace(ctx context.Context, namespace corev1.Na } func (e *Environment) ReloadFromNamespace(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.ReloadFromNamespace") + defer span.End() + namespace, err := e.clientset.CoreV1().Namespaces().Get(ctx, e.Namespace, metav1.GetOptions{}) if err != nil { return errors.Wrap(err, "can not get namespace") diff --git a/pkg/api/execContainer.go b/pkg/api/execContainer.go index 3a9b90b..5028867 100644 --- a/pkg/api/execContainer.go +++ b/pkg/api/execContainer.go @@ -17,6 +17,7 @@ import ( "context" "github.com/maksim-paskal/kubernetes-manager/pkg/client" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" @@ -33,6 +34,9 @@ type ExecContainerResults struct { // exec command in container // @container must contains :. func (e *Environment) ExecContainer(ctx context.Context, container string, command string) (*ExecContainerResults, error) { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.ExecContainer") + defer span.End() + containerInfo, err := types.NewContainerInfo(container) if err != nil { return nil, err diff --git a/pkg/api/getContainers.go b/pkg/api/getContainers.go index e840184..ca74b68 100644 --- a/pkg/api/getContainers.go +++ b/pkg/api/getContainers.go @@ -17,6 +17,7 @@ import ( "fmt" "strings" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -28,6 +29,9 @@ type GetContainersItem struct { // returns list of containers // containerInLabels is pod label to store returned containers. func (e *Environment) GetContainers(ctx context.Context, filter string, containerInLabels string) (*GetContainersItem, error) { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.GetContainers") + defer span.End() + opt := metav1.ListOptions{ FieldSelector: runningPodSelector, } diff --git a/pkg/api/getGitlabProjectRefs.go b/pkg/api/getGitlabProjectRefs.go index ab1611f..2d3375d 100644 --- a/pkg/api/getGitlabProjectRefs.go +++ b/pkg/api/getGitlabProjectRefs.go @@ -20,6 +20,7 @@ import ( "time" "github.com/maksim-paskal/kubernetes-manager/pkg/client" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" "github.com/xanzy/go-gitlab" ) @@ -31,6 +32,9 @@ type GetGitlabProjectBranchItem struct { } func GetGitlabProjectRefs(ctx context.Context, projectID string) ([]*GetGitlabProjectBranchItem, error) { + ctx, span := telemetry.Start(ctx, "api.GetGitlabProjectRefs") + defer span.End() + gitlabClient := client.GetGitlabClient() if gitlabClient == nil { diff --git a/pkg/api/getGitlabProjects.go b/pkg/api/getGitlabProjects.go index cd34572..301816d 100644 --- a/pkg/api/getGitlabProjects.go +++ b/pkg/api/getGitlabProjects.go @@ -19,6 +19,7 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/client" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" "github.com/xanzy/go-gitlab" @@ -39,6 +40,9 @@ type GetGitlabProjectsItem struct { // get gitlab project by profile or namespace. func GetGitlabProjects(ctx context.Context, profile string, namespace string) ([]*GetGitlabProjectsItem, error) { + ctx, span := telemetry.Start(ctx, "api.GetGitlabProjects") + defer span.End() + gitlabClient := client.GetGitlabClient() if gitlabClient == nil { diff --git a/pkg/api/getGitlabProjectsInfo.go b/pkg/api/getGitlabProjectsInfo.go index 243afaf..36a7e66 100644 --- a/pkg/api/getGitlabProjectsInfo.go +++ b/pkg/api/getGitlabProjectsInfo.go @@ -15,6 +15,7 @@ package api import ( "context" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" "github.com/xanzy/go-gitlab" ) @@ -28,6 +29,9 @@ type GetGitlabProjectsInfoItem struct { } func (e *Environment) GetGitlabProjectsInfo(ctx context.Context, projectID, branch string) (*GetGitlabProjectsInfoItem, error) { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.GetGitlabProjectsInfo") + defer span.End() + if e.gitlabClient == nil { return nil, errNoGitlabClient } diff --git a/pkg/api/getPodByImage.go b/pkg/api/getPodByImage.go index c550e9d..9d3dadb 100644 --- a/pkg/api/getPodByImage.go +++ b/pkg/api/getPodByImage.go @@ -16,6 +16,7 @@ import ( "context" "strings" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -27,6 +28,9 @@ type GetPodByImageResult struct { } func (e *Environment) GetPodByImage(ctx context.Context, imagePrefix string) (*GetPodByImageResult, error) { + ctx, span := telemetry.Start(ctx, "api.GetPodByImage") + defer span.End() + pods, err := e.clientset.CoreV1().Pods(e.Namespace).List(ctx, metav1.ListOptions{ FieldSelector: runningPodSelector, }) diff --git a/pkg/api/getServices.go b/pkg/api/getServices.go index e8c46bd..367261f 100644 --- a/pkg/api/getServices.go +++ b/pkg/api/getServices.go @@ -18,6 +18,7 @@ import ( "strconv" "strings" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -45,6 +46,9 @@ type GetServicesItem struct { // Return services and pods with port. func (e *Environment) GetServices(ctx context.Context) ([]*GetServicesItem, error) { + ctx, span := telemetry.Start(ctx, "api.GetServices") + defer span.End() + list, err := e.clientset.CoreV1().Services(e.Namespace).List(ctx, metav1.ListOptions{}) if err != nil { return nil, errors.Wrap(err, "error listing services") diff --git a/pkg/api/saveNamespaceMeta.go b/pkg/api/saveNamespaceMeta.go index 51eceee..3fe697c 100644 --- a/pkg/api/saveNamespaceMeta.go +++ b/pkg/api/saveNamespaceMeta.go @@ -16,12 +16,16 @@ import ( "context" "encoding/json" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ) func (e *Environment) SaveNamespaceMeta(ctx context.Context, annotation map[string]string, labels map[string]string) error { //nolint:lll + ctx, span := telemetry.Start(ctx, "api.SaveNamespaceMeta") + defer span.End() + type metadataStringValue struct { Annotations map[string]string `json:"annotations"` Labels map[string]string `json:"labels"` diff --git a/pkg/api/scaleALL.go b/pkg/api/scaleALL.go index 8bc6dd3..7049921 100644 --- a/pkg/api/scaleALL.go +++ b/pkg/api/scaleALL.go @@ -16,6 +16,7 @@ import ( "context" "encoding/json" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" "github.com/maksim-paskal/kubernetes-manager/pkg/webhook" "github.com/pkg/errors" @@ -24,6 +25,9 @@ import ( // ScaleALL scale namespace and process webhooks. func (e *Environment) ScaleALL(ctx context.Context, replicas int32) error { + ctx, span := telemetry.Start(ctx, "api.ScaleALL") + defer span.End() + processWebhook := make(chan error) processScale := make(chan error) diff --git a/pkg/api/scaleNamespace.go b/pkg/api/scaleNamespace.go index c26f0fd..b62cf70 100644 --- a/pkg/api/scaleNamespace.go +++ b/pkg/api/scaleNamespace.go @@ -18,6 +18,7 @@ import ( "time" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -29,6 +30,9 @@ import ( // ScaleNamespace scale deployments and statefullsets. func (e *Environment) ScaleNamespace(ctx context.Context, replicas int32) error { + ctx, span := telemetry.Start(ctx, "api.ScaleNamespace") + defer span.End() + var wg sync.WaitGroup var syncErrors sync.Map @@ -95,6 +99,9 @@ func (e *Environment) ScaleNamespace(ctx context.Context, replicas int32) error // deletes pods with grace-period=0. func (e *Environment) deletePodsNow(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.deletePodsNow") + defer span.End() + opt := metav1.ListOptions{ FieldSelector: runningPodSelector, } @@ -118,7 +125,10 @@ func (e *Environment) deletePodsNow(ctx context.Context) error { return nil } -func (e *Environment) scaleDeployments(ctx context.Context, replicas int32) error { //nolint: dupl +func (e *Environment) scaleDeployments(ctx context.Context, replicas int32) error { //nolint:dupl + ctx, span := telemetry.Start(ctx, "api.scaleDeployments") + defer span.End() + ds, err := e.clientset.AppsV1().Deployments(e.Namespace).List(ctx, metav1.ListOptions{}) if err != nil { return errors.Wrap(err, "error listing deployments") @@ -155,6 +165,9 @@ func (e *Environment) scaleDeployments(ctx context.Context, replicas int32) erro } func (e *Environment) scaleStatefulSets(ctx context.Context, replicas int32) error { //nolint:dupl + ctx, span := telemetry.Start(ctx, "api.scaleStatefulSets") + defer span.End() + sf, err := e.clientset.AppsV1().StatefulSets(e.Namespace).List(ctx, metav1.ListOptions{}) if err != nil { return errors.Wrap(err, "error listing statefullsets") diff --git a/pkg/api/startNewEnvironment.go b/pkg/api/startNewEnvironment.go index a28e95a..d7636ac 100644 --- a/pkg/api/startNewEnvironment.go +++ b/pkg/api/startNewEnvironment.go @@ -20,6 +20,7 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/client" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/maksim-paskal/sluglify" @@ -135,6 +136,9 @@ func ParseEnvironmentServices(services string) ([]*EnvironmentServices, error) { } func StartNewEnvironment(ctx context.Context, input *StartNewEnvironmentInput) (*Environment, error) { + ctx, span := telemetry.Start(ctx, "api.StartNewEnvironment") + defer span.End() + if len(input.Cluster) == 0 { input.Cluster = config.Get().GetKubernetesEndpoints()[0].Name } @@ -148,6 +152,9 @@ func StartNewEnvironment(ctx context.Context, input *StartNewEnvironmentInput) ( } func processCreateNewBranch(ctx context.Context, input *StartNewEnvironmentInput) (*Environment, error) { + ctx, span := telemetry.Start(ctx, "api.processCreateNewBranch") + defer span.End() + if err := input.Validation(); err != nil { return nil, errors.Wrap(err, "error validating") } @@ -207,6 +214,9 @@ func GetNamespaceByServices(profile *config.ProjectProfile, services string) (st } func NewEnvironment(ctx context.Context, input *StartNewEnvironmentInput) (*Environment, error) { + ctx, span := telemetry.Start(ctx, "api.NewEnvironment") + defer span.End() + id, err := input.GetID() if err != nil { return nil, errors.Wrap(err, "error getting id") diff --git a/pkg/batch/batch.go b/pkg/batch/batch.go index eb62178..d559fd7 100644 --- a/pkg/batch/batch.go +++ b/pkg/batch/batch.go @@ -18,18 +18,18 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/api" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" - opentracing "github.com/opentracing/opentracing-go" "github.com/pkg/errors" log "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel/trace" ) const maxScaleDownDuration = 5 * time.Minute func Schedule(ctx context.Context) { - log.Info("starting batch") - - tracer := opentracing.GlobalTracer() + ctx, span := telemetry.Start(ctx, "batch.Schedule") + defer span.End() ticker := time.NewTicker(config.Get().GetBatchShedulePeriod()) @@ -38,10 +38,10 @@ func Schedule(ctx context.Context) { ctx, cancel := context.WithTimeout(ctx, config.Get().GetBatchShedulePeriod()) defer cancel() - span := tracer.StartSpan("scheduleBatch") - defer span.Finish() + ctx, span := telemetry.Start(ctx, "batch.scheduleBatch", trace.WithNewRoot()) + defer span.End() - if err := Execute(ctx, span); err != nil { + if err := Execute(ctx); err != nil { log.WithError(err).Error() } }() @@ -53,11 +53,9 @@ func Schedule(ctx context.Context) { } } -func scaleDownALL(ctx context.Context, rootSpan opentracing.Span) error { - tracer := opentracing.GlobalTracer() - span := tracer.StartSpan("scaleDownALL", opentracing.ChildOf(rootSpan.Context())) - - defer span.Finish() +func scaleDownALL(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.scaleDownALL") + defer span.End() environments, err := api.GetEnvironments(ctx, "") if err != nil { @@ -150,13 +148,11 @@ func scaleDownALL(ctx context.Context, rootSpan opentracing.Span) error { return nil } -func Execute(ctx context.Context, rootSpan opentracing.Span) error { - tracer := opentracing.GlobalTracer() - span := tracer.StartSpan("batch", opentracing.ChildOf(rootSpan.Context())) - - defer span.Finish() +func Execute(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "api.batch") + defer span.End() - if err := scaleDownALL(ctx, span); err != nil { + if err := scaleDownALL(ctx); err != nil { log.WithError(err).Error() } diff --git a/pkg/jira/jira.go b/pkg/jira/jira.go index c2db52d..2f55a48 100644 --- a/pkg/jira/jira.go +++ b/pkg/jira/jira.go @@ -21,6 +21,7 @@ import ( "time" "github.com/maksim-paskal/kubernetes-manager/pkg/metrics" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" ) @@ -45,6 +46,9 @@ type IssueInfo struct { } func GetIssueInfo(ctx context.Context, issue string) (*IssueInfo, error) { + ctx, span := telemetry.Start(ctx, "jira.GetIssueInfo") + defer span.End() + ctx, cancel := context.WithTimeout(ctx, requestTimeout) defer cancel() diff --git a/pkg/modules/autotests/autotests.go b/pkg/modules/autotests/autotests.go index 281a9e6..a9f6391 100644 --- a/pkg/modules/autotests/autotests.go +++ b/pkg/modules/autotests/autotests.go @@ -23,6 +23,7 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/api" "github.com/maksim-paskal/kubernetes-manager/pkg/client" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" "github.com/pkg/errors" gitlab "github.com/xanzy/go-gitlab" @@ -88,6 +89,9 @@ func (d *Details) Normalize(a *config.Autotest) error { } func GetAutotestDetails(ctx context.Context, environment *api.Environment, size int) (*Details, error) { + ctx, span := telemetry.Start(ctx, "autotests.GetAutotestDetails") + defer span.End() + autotestConfig := config.Get().GetAutotestByID(environment.ID) if autotestConfig == nil { @@ -246,6 +250,9 @@ func (s *StartAutotestInput) SetEnvironment(environment *api.Environment) { } func StartAutotest(ctx context.Context, input *StartAutotestInput) error { + ctx, span := telemetry.Start(ctx, "api.StartAutotest") + defer span.End() + if err := input.Validate(); err != nil { return errors.Wrap(err, "error validating input") } @@ -338,6 +345,9 @@ func StartAutotest(ctx context.Context, input *StartAutotestInput) error { } func getReleaseName(ctx context.Context, url string) (string, error) { + ctx, span := telemetry.Start(ctx, "api.getReleaseName") + defer span.End() + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return "", errors.Wrap(err, "error creating request") diff --git a/pkg/telemetry/telemetry.go b/pkg/telemetry/telemetry.go new file mode 100644 index 0000000..dd57fe4 --- /dev/null +++ b/pkg/telemetry/telemetry.go @@ -0,0 +1,79 @@ +/* +Copyright paskal.maksim@gmail.com +Licensed under the Apache License, Version 2.0 (the "License") +you may not use this file except in compliance with the License. +You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package telemetry + +import ( + "context" + + "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/pkg/errors" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.17.0" + "go.opentelemetry.io/otel/trace" +) + +func Init(ctx context.Context) error { + otelExporter, err := otlptracegrpc.New(ctx) + if err != nil { + return errors.Wrap(err, "error creating exporter") + } + + traceResource, err := resource.New(ctx, + resource.WithAttributes( + semconv.ServiceName(config.Namespace), + ), + ) + if err != nil { + return errors.Wrap(err, "error creating resource") + } + + traceProvider := sdktrace.NewTracerProvider( + sdktrace.WithBatcher(otelExporter), + sdktrace.WithResource(traceResource), + ) + + go func() { + <-ctx.Done() + _ = traceProvider.Shutdown(ctx) + }() + + otel.SetTracerProvider(traceProvider) + otel.SetTextMapPropagator(propagation.TraceContext{}) + + return nil //nolint:ireturn +} + +func Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { //nolint:ireturn,lll + return otel.Tracer("").Start(ctx, spanName, opts...) +} + +func Attributes(span trace.Span, att map[string]string) { + for k, v := range att { + span.SetAttributes(attribute.String(k, v)) + } +} + +func Event(span trace.Span, name string, att map[string]string) { + opts := make([]trace.EventOption, 0) + + for k, v := range att { + opts = append(opts, trace.WithAttributes(attribute.String(k, v))) + } + + span.AddEvent(name, opts...) +} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 643b45d..2df2615 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -24,7 +24,6 @@ import ( "github.com/Masterminds/sprig" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) const ( @@ -94,16 +93,6 @@ func StringInSlice(str string, list []string) bool { return false } -type JaegerLogs struct{} - -func (l JaegerLogs) Error(msg string) { - log.Errorf(msg) -} - -func (l JaegerLogs) Infof(msg string, args ...interface{}) { - log.Debugf(msg, args...) -} - func GetTemplatedResult(text string, obj interface{}) ([]byte, error) { t, err := template.New("getTemplatedString").Funcs(sprig.FuncMap()).Parse(text) if err != nil { diff --git a/pkg/web/handlerAPI.go b/pkg/web/handlerAPI.go index f83ebe3..dc83ebe 100644 --- a/pkg/web/handlerAPI.go +++ b/pkg/web/handlerAPI.go @@ -27,27 +27,23 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/config" "github.com/maksim-paskal/kubernetes-manager/pkg/jira" "github.com/maksim-paskal/kubernetes-manager/pkg/metrics" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/utils" - logrushookopentracing "github.com/maksim-paskal/logrus-hook-opentracing" logrushooksentry "github.com/maksim-paskal/logrus-hook-sentry" - opentracing "github.com/opentracing/opentracing-go" - "github.com/opentracing/opentracing-go/ext" "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) func handlerAPI(w http.ResponseWriter, r *http.Request) { - tracer := opentracing.GlobalTracer() - spanCtx, _ := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header)) - span := tracer.StartSpan("apiHandler", ext.RPCServerOption(spanCtx)) - - defer span.Finish() + ctx, span := telemetry.Start(r.Context(), "handlerAPI") + defer span.End() vars := mux.Vars(r) - result, err := apiOperation(r.Context(), r, vars["operation"]) + result, err := apiOperation(ctx, r, vars["operation"]) if err != nil { + span.RecordError(err) w.WriteHeader(http.StatusInternalServerError) if _, err := w.Write([]byte(err.Error())); err != nil { @@ -56,7 +52,6 @@ func handlerAPI(w http.ResponseWriter, r *http.Request) { log. WithError(err). - WithField(logrushookopentracing.SpanKey, span). WithFields(logrushooksentry.AddRequest(r)). Error() } else { @@ -73,6 +68,9 @@ func handlerAPI(w http.ResponseWriter, r *http.Request) { } func apiOperation(ctx context.Context, r *http.Request, operation string) (*HandlerResult, error) { //nolint:gocyclo,maintidx,lll + ctx, span := telemetry.Start(ctx, "web.apiOperation") + defer span.End() + metricsStarts := time.Now() defer metrics.LogRequest(operation, metricsStarts) @@ -86,6 +84,10 @@ func apiOperation(ctx context.Context, r *http.Request, operation string) (*Hand if len(owner) > 0 { log.Infof("user %s request %s", owner[0], operation) + + telemetry.Attributes(span, map[string]string{ + "owner": owner[0], + }) } if err := r.ParseForm(); err != nil { diff --git a/pkg/web/handlerEnvironment.go b/pkg/web/handlerEnvironment.go index 05a85d6..664762e 100644 --- a/pkg/web/handlerEnvironment.go +++ b/pkg/web/handlerEnvironment.go @@ -28,13 +28,12 @@ import ( "github.com/maksim-paskal/kubernetes-manager/pkg/config" "github.com/maksim-paskal/kubernetes-manager/pkg/metrics" "github.com/maksim-paskal/kubernetes-manager/pkg/modules/autotests" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" - logrushookopentracing "github.com/maksim-paskal/logrus-hook-opentracing" logrushooksentry "github.com/maksim-paskal/logrus-hook-sentry" - opentracing "github.com/opentracing/opentracing-go" - "github.com/opentracing/opentracing-go/ext" "github.com/pkg/errors" log "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel/trace" ) const ( @@ -44,16 +43,16 @@ const ( ) func handlerEnvironment(w http.ResponseWriter, r *http.Request) { - tracer := opentracing.GlobalTracer() - spanCtx, _ := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header)) - span := tracer.StartSpan("environmentHandler", ext.RPCServerOption(spanCtx)) - - defer span.Finish() + ctx, span := telemetry.Start(r.Context(), "handlerEnvironment") + defer span.End() vars := mux.Vars(r) - result, err := environmentOperation(r.Context(), r, vars["environmentID"], vars["operation"]) + telemetry.Attributes(span, vars) + + result, err := environmentOperation(ctx, r, vars["environmentID"], vars["operation"]) if err != nil { + span.RecordError(err) w.WriteHeader(http.StatusInternalServerError) if _, err := w.Write([]byte(err.Error())); err != nil { @@ -62,7 +61,6 @@ func handlerEnvironment(w http.ResponseWriter, r *http.Request) { log. WithError(err). - WithField(logrushookopentracing.SpanKey, span). WithFields(logrushooksentry.AddRequest(r)). Error() @@ -104,6 +102,9 @@ func handlerEnvironment(w http.ResponseWriter, r *http.Request) { } func environmentOperation(ctx context.Context, r *http.Request, environmentID string, operation string) (*HandlerResult, error) { //nolint:gocyclo,lll,maintidx + ctx, span := telemetry.Start(ctx, "web.environmentOperation") + defer span.End() + metricsStarts := time.Now() defer metrics.LogRequest(operation, metricsStarts) @@ -117,6 +118,10 @@ func environmentOperation(ctx context.Context, r *http.Request, environmentID st if len(owner) > 0 { log.Infof("user %s request %s", owner[0], operation) + + telemetry.Attributes(span, map[string]string{ + "owner": owner[0], + }) } body, err := io.ReadAll(r.Body) @@ -301,9 +306,12 @@ func environmentOperation(ctx context.Context, r *http.Request, environmentID st result.Result = kubeconfigFile case "make-pause": go func() { - ctx, cancel := context.WithTimeout(backgroudContext, scaleMaxTime) + ctx, cancel := context.WithTimeout(parentContext, scaleMaxTime) defer cancel() + ctx, span := telemetry.Start(ctx, "web.make-pause", trace.WithNewRoot()) + defer span.End() + if err := environment.ScaleALL(ctx, 0); err != nil { log.WithError(err).Error() } @@ -312,9 +320,12 @@ func environmentOperation(ctx context.Context, r *http.Request, environmentID st result.Result = fmt.Sprintf("All pods in namespace %s will be paused next %s", environment.Namespace, scaleMaxTime) case "make-start": go func() { - ctx, cancel := context.WithTimeout(backgroudContext, scaleMaxTime) + ctx, cancel := context.WithTimeout(parentContext, scaleMaxTime) defer cancel() + ctx, span := telemetry.Start(ctx, "web.make-start", trace.WithNewRoot()) + defer span.End() + if err := environment.ScaleALL(ctx, 1); err != nil { log.WithError(err).Error() } diff --git a/pkg/web/handlerUser.go b/pkg/web/handlerUser.go index f2ce8ff..e582764 100644 --- a/pkg/web/handlerUser.go +++ b/pkg/web/handlerUser.go @@ -15,17 +15,13 @@ package web import ( "net/http" - opentracing "github.com/opentracing/opentracing-go" - "github.com/opentracing/opentracing-go/ext" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" log "github.com/sirupsen/logrus" ) func handlerUser(w http.ResponseWriter, r *http.Request) { - tracer := opentracing.GlobalTracer() - spanCtx, _ := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header)) - span := tracer.StartSpan("userHandler", ext.RPCServerOption(spanCtx)) - - defer span.Finish() + _, span := telemetry.Start(r.Context(), "handlerUser") + defer span.End() _, err := w.Write([]byte(`{"user":"kubernetes-manager.test.com","email":"kubernetes-manager@domain.com","groups":["kubernetes-manager-admin"]}`)) //nolint:lll if err != nil { diff --git a/pkg/web/web.go b/pkg/web/web.go index 3864c9c..f621b45 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -24,8 +24,10 @@ import ( "github.com/gorilla/mux" "github.com/maksim-paskal/kubernetes-manager/pkg/config" "github.com/maksim-paskal/kubernetes-manager/pkg/metrics" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/pkg/errors" log "github.com/sirupsen/logrus" + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" ) const ( @@ -112,18 +114,23 @@ func GetHandler() *mux.Router { return mux } -var backgroudContext context.Context +var parentContext context.Context func StartServer(ctx context.Context) { + ctx, span := telemetry.Start(ctx, "web.StartServer") + defer span.End() + log.Info(fmt.Sprintf("Starting on %s...", *config.Get().WebListen)) - backgroudContext = ctx + parentContext = ctx timeoutMessage := fmt.Sprintf("Server timeout after %s", serverRequestTimeout) + traceHandler := otelhttp.NewHandler(GetHandler(), "/") + server := &http.Server{ Addr: *config.Get().WebListen, - Handler: http.TimeoutHandler(GetHandler(), serverRequestTimeout, timeoutMessage), + Handler: http.TimeoutHandler(traceHandler, serverRequestTimeout, timeoutMessage), ReadTimeout: serverReadTimeout, WriteTimeout: serverWriteTimeout, } diff --git a/pkg/webhook/aws/aws.go b/pkg/webhook/aws/aws.go index 880b21a..50ccacc 100644 --- a/pkg/webhook/aws/aws.go +++ b/pkg/webhook/aws/aws.go @@ -24,6 +24,7 @@ import ( "github.com/aws/aws-sdk-go/service/rds" "github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -83,6 +84,9 @@ func (provider *Provider) Init(condition config.WebHook, message types.WebhookMe } func (provider *Provider) Process(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "webhook.aws.Process") + defer span.End() + processInstances := make(chan error) processDatabases := make(chan error) @@ -125,6 +129,9 @@ func (provider *Provider) Process(ctx context.Context) error { } func (provider *Provider) processInstances(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "webhook.aws.processInstances") + defer span.End() + svc := ec2.New(provider.sess, &aws.Config{Region: aws.String(provider.config.Region)}) params := &ec2.DescribeInstancesInput{ @@ -199,6 +206,9 @@ func (provider *Provider) processInstances(ctx context.Context) error { } func (provider *Provider) processDatabases(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "webhook.aws.processDatabases") + defer span.End() + resources := resourcegroupstaggingapi.New(provider.sess, &aws.Config{Region: aws.String(provider.config.Region)}) // list databases by tags, rds.DescribeDBInstances do not use tags for filtering diff --git a/pkg/webhook/azure/azure.go b/pkg/webhook/azure/azure.go index 91de030..6186f09 100644 --- a/pkg/webhook/azure/azure.go +++ b/pkg/webhook/azure/azure.go @@ -24,6 +24,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/mysql/armmysqlflexibleservers" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -103,6 +104,9 @@ func (provider *Provider) Init(condition config.WebHook, message types.WebhookMe } func (provider *Provider) Process(ctx context.Context) error { + ctx, span := telemetry.Start(ctx, "webhook.azure.Process") + defer span.End() + log.Info("process azure provider") newClient, err := armresources.NewClient(provider.config.SubscriptionID, provider.cred, nil) diff --git a/pkg/webhook/webhook.go b/pkg/webhook/webhook.go index f8928c2..9518e4e 100644 --- a/pkg/webhook/webhook.go +++ b/pkg/webhook/webhook.go @@ -16,6 +16,7 @@ import ( "context" "github.com/maksim-paskal/kubernetes-manager/pkg/config" + "github.com/maksim-paskal/kubernetes-manager/pkg/telemetry" "github.com/maksim-paskal/kubernetes-manager/pkg/types" "github.com/maksim-paskal/kubernetes-manager/pkg/webhook/aws" "github.com/maksim-paskal/kubernetes-manager/pkg/webhook/azure" @@ -30,6 +31,9 @@ type Provider interface { // create new webbhok event. func NewEvent(ctx context.Context, message types.WebhookMessage) error { + ctx, span := telemetry.Start(ctx, "webhook.NewEvent") + defer span.End() + for _, condition := range config.Get().WebHooks { if condition.Cluster == message.Cluster && condition.Namespace == message.Namespace { if err := processEvent(ctx, condition, message); err != nil { @@ -62,6 +66,9 @@ func CheckConfig() error { // process event. func processEvent(ctx context.Context, condition config.WebHook, message types.WebhookMessage) error { + ctx, span := telemetry.Start(ctx, "api.processEvent") + defer span.End() + provider, err := NewProvider(condition.Provider) if err != nil { return errors.Wrap(err, "find valid provider")