diff --git a/agent/container/main.go b/agent/container/main.go index 3e684f3e..56b6958a 100755 --- a/agent/container/main.go +++ b/agent/container/main.go @@ -1,16 +1,29 @@ package main import ( + "context" "log" "os" "os/signal" "syscall" "github.com/intelops/kubviz/agent/container/pkg/application" + "github.com/intelops/kubviz/pkg/opentelemetry" ) func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) + + tp, err := opentelemetry.InitTracer() + if err != nil { + log.Fatal(err) + } + defer func() { + if err := tp.Shutdown(context.Background()); err != nil { + log.Printf("Error shutting down tracer provider: %v", err) + } + }() + app := application.New() go app.GithubContainerWatch() go app.Start() diff --git a/agent/container/pkg/application/application.go b/agent/container/pkg/application/application.go index 136fa332..7cabbbcd 100755 --- a/agent/container/pkg/application/application.go +++ b/agent/container/pkg/application/application.go @@ -11,7 +11,9 @@ import ( "github.com/intelops/kubviz/agent/container/pkg/clients" "github.com/intelops/kubviz/agent/container/pkg/config" "github.com/intelops/kubviz/agent/container/pkg/handler" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/kelseyhightower/envconfig" + "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" ) type Application struct { @@ -43,6 +45,14 @@ func New() *Application { } r := gin.Default() + + config, err := opentelemetry.GetConfigurations() + if err != nil { + log.Println("Unable to read open telemetry configurations") + } + + r.Use(otelgin.Middleware(config.ServiceName)) + apiServer.BindRequest(r) httpServer := &http.Server{ diff --git a/agent/container/pkg/application/handlers.go b/agent/container/pkg/application/handlers.go index 28dfe829..cca3a95d 100755 --- a/agent/container/pkg/application/handlers.go +++ b/agent/container/pkg/application/handlers.go @@ -1,14 +1,26 @@ package application import ( + "context" "io" "log" "net/http" + + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) //githubHandler handles the github webhooks post requests. func (app *Application) localRegistryHandler(w http.ResponseWriter, r *http.Request) { + + ctx:=context.Background() + tracer := otel.Tracer("container-gitlab") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "localRegistryHandler") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + event, err := io.ReadAll(r.Body) if err != nil { log.Printf("Event body read failed: %v", err) diff --git a/agent/container/pkg/clients/nats_client.go b/agent/container/pkg/clients/nats_client.go index f42185cc..342fb2ea 100755 --- a/agent/container/pkg/clients/nats_client.go +++ b/agent/container/pkg/clients/nats_client.go @@ -1,11 +1,15 @@ package clients import ( + "context" "fmt" "log" "time" "github.com/intelops/kubviz/agent/container/pkg/config" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "github.com/nats-io/nats.go" ) @@ -112,6 +116,13 @@ func (n *NATSContext) Close() { // The repository information in the header can be used by subscribers to filter or route the event based on its origin or destination. // An error is returned if the publishing process fails, such as if the connection is lost or if there are issues with the JetStream. func (n *NATSContext) Publish(event []byte, repo string) error { + + ctx:=context.Background() + tracer := otel.Tracer("container-nats-client") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "ContainerPublish") + span.SetAttributes(attribute.String("repo-name", repo)) + defer span.End() + msg := nats.NewMsg(eventSubject) msg.Data = event msg.Header.Set("REPO_NAME", repo) diff --git a/agent/container/pkg/handler/api_handler.go b/agent/container/pkg/handler/api_handler.go index 531fd461..0e6bdd01 100755 --- a/agent/container/pkg/handler/api_handler.go +++ b/agent/container/pkg/handler/api_handler.go @@ -1,11 +1,14 @@ package handler import ( + "log" "net/http" "github.com/gin-gonic/gin" "github.com/intelops/kubviz/agent/container/api" "github.com/intelops/kubviz/agent/container/pkg/clients" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" ) type APIHandler struct { @@ -29,6 +32,14 @@ func NewAPIHandler(conn *clients.NATSContext) (*APIHandler, error) { } func (ah *APIHandler) BindRequest(r *gin.Engine) { + + config, err := opentelemetry.GetConfigurations() + if err != nil { + log.Println("Unable to read open telemetry configurations") + } + + r.Use(otelgin.Middleware(config.ServiceName)) + apiGroup := r.Group("/") { apiGroup.GET("/api-docs", ah.GetApiDocs) diff --git a/agent/container/pkg/handler/azure_container.go b/agent/container/pkg/handler/azure_container.go index 106d92e0..5e881703 100644 --- a/agent/container/pkg/handler/azure_container.go +++ b/agent/container/pkg/handler/azure_container.go @@ -9,6 +9,8 @@ import ( "github.com/gin-gonic/gin" "github.com/intelops/kubviz/model" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) var ErrInvalidPayload = errors.New("invalid or malformed Azure Container Registry webhook payload") @@ -19,6 +21,12 @@ var ErrInvalidPayload = errors.New("invalid or malformed Azure Container Registr // application to subscribe to these events and respond to changes in the container registry. // If the payload is invalid or the publishing process fails, an error response is returned. func (ah *APIHandler) PostEventAzureContainer(c *gin.Context) { + + tracer := otel.Tracer("azure-container") + _, span := tracer.Start(c.Request.Context(), "PostEventAzureContainer") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer func() { _, _ = io.Copy(io.Discard, c.Request.Body) _ = c.Request.Body.Close() diff --git a/agent/container/pkg/handler/docker_event_dockerhub.go b/agent/container/pkg/handler/docker_event_dockerhub.go index d022d9a7..9066c947 100644 --- a/agent/container/pkg/handler/docker_event_dockerhub.go +++ b/agent/container/pkg/handler/docker_event_dockerhub.go @@ -7,6 +7,8 @@ import ( "net/http" "github.com/gin-gonic/gin" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) // parse errors @@ -16,6 +18,12 @@ var ( ) func (ah *APIHandler) PostEventDockerHub(c *gin.Context) { + + tracer := otel.Tracer("dockerhub-container") + _, span := tracer.Start(c.Request.Context(), "PostEventDockerHub") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer func() { _, _ = io.Copy(io.Discard, c.Request.Body) _ = c.Request.Body.Close() diff --git a/agent/container/pkg/handler/jfrog_container.go b/agent/container/pkg/handler/jfrog_container.go index 5655026c..77b0451f 100644 --- a/agent/container/pkg/handler/jfrog_container.go +++ b/agent/container/pkg/handler/jfrog_container.go @@ -9,11 +9,19 @@ import ( "github.com/gin-gonic/gin" "github.com/intelops/kubviz/model" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) var ErrInvalidPayloads = errors.New("invalid or malformed jfrog Container Registry webhook payload") func (ah *APIHandler) PostEventJfrogContainer(c *gin.Context) { + + tracer := otel.Tracer("jfrog-container") + _, span := tracer.Start(c.Request.Context(), "PostEventJfrogContainer") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer func() { _, _ = io.Copy(io.Discard, c.Request.Body) _ = c.Request.Body.Close() diff --git a/agent/container/pkg/handler/quay_handler.go b/agent/container/pkg/handler/quay_handler.go index a002e05d..b675658f 100644 --- a/agent/container/pkg/handler/quay_handler.go +++ b/agent/container/pkg/handler/quay_handler.go @@ -8,9 +8,17 @@ import ( "github.com/gin-gonic/gin" "github.com/intelops/kubviz/model" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) func (ah *APIHandler) PostEventQuayContainer(c *gin.Context) { + + tracer := otel.Tracer("quay-container") + _, span := tracer.Start(c.Request.Context(), "PostEventQuayContainer") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer func() { _, _ = io.Copy(io.Discard, c.Request.Body) _ = c.Request.Body.Close() diff --git a/agent/git/main.go b/agent/git/main.go index 9fd6a682..c1d22c27 100644 --- a/agent/git/main.go +++ b/agent/git/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "log" "os" "os/signal" @@ -9,6 +10,7 @@ import ( "github.com/intelops/kubviz/agent/git/pkg/application" "github.com/intelops/kubviz/agent/git/pkg/clients" "github.com/intelops/kubviz/agent/git/pkg/config" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/kelseyhightower/envconfig" ) @@ -20,6 +22,16 @@ func main() { log.Fatalf("Could not parse env Config: %v", err) } + tp, err := opentelemetry.InitTracer() + if err != nil { + log.Fatal(err) + } + defer func() { + if err := tp.Shutdown(context.Background()); err != nil { + log.Printf("Error shutting down tracer provider: %v", err) + } + }() + // Connect to NATS natsContext, err := clients.NewNATSContext(cfg) if err != nil { diff --git a/agent/git/pkg/application/application.go b/agent/git/pkg/application/application.go index 8af7ba95..0ea3b17e 100644 --- a/agent/git/pkg/application/application.go +++ b/agent/git/pkg/application/application.go @@ -11,6 +11,8 @@ import ( "github.com/intelops/kubviz/agent/git/api" "github.com/intelops/kubviz/agent/git/pkg/clients" "github.com/intelops/kubviz/agent/git/pkg/config" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" "github.com/gin-gonic/gin" ) @@ -41,6 +43,14 @@ func New(conf *config.Config, conn *clients.NATSContext) *Application { func (app *Application) Routes() *gin.Engine { router := gin.New() + + config, err := opentelemetry.GetConfigurations() + if err != nil { + log.Println("Unable to read open telemetry configurations") + } + + router.Use(otelgin.Middleware(config.ServiceName)) + api.RegisterHandlers(router, app) return router } diff --git a/agent/git/pkg/application/handlers.go b/agent/git/pkg/application/handlers.go index b865c380..cb2c7cfe 100644 --- a/agent/git/pkg/application/handlers.go +++ b/agent/git/pkg/application/handlers.go @@ -9,10 +9,18 @@ import ( "github.com/intelops/kubviz/agent/git/api" "github.com/intelops/kubviz/gitmodels/azuremodel" "github.com/intelops/kubviz/model" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) func (app *Application) PostGitea(c *gin.Context) { log.Println("gitea handler called...") + + tracer := otel.Tracer("gitea-git") + _, span := tracer.Start(c.Request.Context(), "PostGitea") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer log.Println("gitea handler exited...") event := c.Request.Header.Get(string(model.GiteaHeader)) @@ -30,6 +38,12 @@ func (app *Application) PostGitea(c *gin.Context) { func (app *Application) PostAzure(c *gin.Context) { log.Println("azure handler called...") + + tracer := otel.Tracer("azure-git") + _, span := tracer.Start(c.Request.Context(), "PostAzure") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer log.Println("azure handler exited...") jsonData, err := c.GetRawData() @@ -58,6 +72,12 @@ func (app *Application) PostAzure(c *gin.Context) { // githubHandler handles the github webhooks post requests. func (app *Application) PostGithub(c *gin.Context) { log.Println("github handler called...") + + tracer := otel.Tracer("github-git") + _, span := tracer.Start(c.Request.Context(), "PostGithub") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer log.Println("github handler exited...") event := c.Request.Header.Get(string(model.GithubHeader)) @@ -79,6 +99,12 @@ func (app *Application) PostGithub(c *gin.Context) { // gitlabHandler handles the github webhooks post requests. func (app *Application) PostGitlab(c *gin.Context) { log.Println("gitlab handler called...") + + tracer := otel.Tracer("gitlab-git") + _, span := tracer.Start(c.Request.Context(), "PostGitlab") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer log.Println("gitlab handler exited...") event := c.Request.Header.Get(string(model.GitlabHeader)) @@ -100,6 +126,12 @@ func (app *Application) PostGitlab(c *gin.Context) { // bitBucketHandler handles the github webhooks post requests. func (app *Application) PostBitbucket(c *gin.Context) { log.Println("bitbucket handler called...") + + tracer := otel.Tracer("bitbucket-git") + _, span := tracer.Start(c.Request.Context(), "PostBitbucket") + span.SetAttributes(attribute.String("http.method", "POST")) + defer span.End() + defer log.Println("bitbucket handler exited...") event := c.Request.Header.Get(string(model.BitBucketHeader)) diff --git a/agent/git/pkg/clients/nats_client.go b/agent/git/pkg/clients/nats_client.go index e9ef06c2..b42f9dcf 100644 --- a/agent/git/pkg/clients/nats_client.go +++ b/agent/git/pkg/clients/nats_client.go @@ -1,10 +1,14 @@ package clients import ( + "context" "fmt" "github.com/intelops/kubviz/agent/git/pkg/config" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "log" "time" @@ -91,6 +95,13 @@ func (n *NATSContext) Close() { } func (n *NATSContext) Publish(metric []byte, repo string, eventkey model.EventKey, eventvalue model.EventValue) error { + + ctx:=context.Background() + tracer := otel.Tracer("git-nats-client") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "GitPublish") + span.SetAttributes(attribute.String("repo-name", repo)) + defer span.End() + msg := nats.NewMsg(eventSubject) msg.Data = metric msg.Header.Set("GitProvider", repo) diff --git a/agent/kubviz/k8smetrics_agent.go b/agent/kubviz/k8smetrics_agent.go index fbc9b24c..2dd8f127 100644 --- a/agent/kubviz/k8smetrics_agent.go +++ b/agent/kubviz/k8smetrics_agent.go @@ -11,6 +11,8 @@ import ( "time" "github.com/intelops/go-common/logging" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "github.com/go-co-op/gocron" "github.com/nats-io/nats.go" @@ -19,6 +21,7 @@ import ( "github.com/intelops/kubviz/constants" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -98,6 +101,17 @@ func main() { } clientset = getK8sClient(config) } + + tp, err := opentelemetry.InitTracer() + if err != nil { + log.Fatal(err) + } + defer func() { + if err := tp.Shutdown(context.Background()); err != nil { + log.Printf("Error shutting down tracer provider: %v", err) + } + }() + go publishMetrics(clientset, js, clusterMetricsChan) go server.StartServer() collectAndPublishMetrics := func() { @@ -151,11 +165,25 @@ func main() { // publishMetrics publishes stream of events // with subject "METRICS.created" func publishMetrics(clientset *kubernetes.Clientset, js nats.JetStreamContext, errCh chan error) { + + ctx:=context.Background() + tracer := otel.Tracer("kubviz-publish-metrics") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "publishMetrics") + span.SetAttributes(attribute.String("kubviz-agent", "publish-metrics")) + defer span.End() + watchK8sEvents(clientset, js) errCh <- nil } func publishK8sMetrics(id string, mtype string, mdata *v1.Event, js nats.JetStreamContext) (bool, error) { + + ctx:=context.Background() + tracer := otel.Tracer("kubviz-publish-k8smetrics") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "publishK8sMetrics") + span.SetAttributes(attribute.String("kubviz-agent", "publish-k8smetrics")) + defer span.End() + metrics := model.Metrics{ ID: id, Type: mtype, @@ -250,6 +278,13 @@ func LogErr(err error) { } } func watchK8sEvents(clientset *kubernetes.Clientset, js nats.JetStreamContext) { + + ctx:=context.Background() + tracer := otel.Tracer("kubviz-watch-k8sevents") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "watchK8sEvents") + span.SetAttributes(attribute.String("kubviz-agent", "watch-k8sevents")) + defer span.End() + watchlist := cache.NewListWatchFromClient( clientset.CoreV1().RESTClient(), "events", diff --git a/agent/kubviz/ketall.go b/agent/kubviz/ketall.go index ce6d125f..ffc2e7b4 100644 --- a/agent/kubviz/ketall.go +++ b/agent/kubviz/ketall.go @@ -6,6 +6,9 @@ import ( "time" "github.com/intelops/kubviz/constants" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "github.com/intelops/kubviz/model" "github.com/nats-io/nats.go" @@ -29,6 +32,13 @@ func PublishAllResources(result model.Resource, js nats.JetStreamContext) error } func GetAllResources(config *rest.Config, js nats.JetStreamContext) error { + + ctx:=context.Background() + tracer := otel.Tracer("ketall") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "GetAllResources") + span.SetAttributes(attribute.String("ketall-plugin-agent", "ketall-output")) + defer span.End() + // TODO: upto this uncomment for production // Create a new discovery client to discover all resources in the cluster dc := discovery.NewDiscoveryClientForConfigOrDie(config) diff --git a/agent/kubviz/kubePreUpgrade.go b/agent/kubviz/kubePreUpgrade.go index 18c1597a..68577ac0 100644 --- a/agent/kubviz/kubePreUpgrade.go +++ b/agent/kubviz/kubePreUpgrade.go @@ -10,6 +10,9 @@ import ( "strings" "github.com/intelops/kubviz/constants" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -79,6 +82,13 @@ func publishK8sDepricated_Deleted_Api(result *model.Result, js nats.JetStreamCon } func KubePreUpgradeDetector(config *rest.Config, js nats.JetStreamContext) error { + + ctx := context.Background() + tracer := otel.Tracer("kubepreupgrade") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "KubePreUpgradeDetector") + span.SetAttributes(attribute.String("kubepug-plugin-agent", "kubepug-output")) + defer span.End() + pvcMountPath := "/mnt/agent/kbz" uniqueDir := fmt.Sprintf("%s/kubepug", pvcMountPath) err := os.MkdirAll(uniqueDir, 0755) diff --git a/agent/kubviz/kube_score.go b/agent/kubviz/kube_score.go index 57ea8cb8..90551e0f 100644 --- a/agent/kubviz/kube_score.go +++ b/agent/kubviz/kube_score.go @@ -9,8 +9,11 @@ import ( "github.com/google/uuid" "github.com/intelops/kubviz/constants" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/nats-io/nats.go" "github.com/zegl/kube-score/renderer/json_v2" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" ) @@ -57,6 +60,13 @@ func publish(ns string, js nats.JetStreamContext) error { } func publishKubescoreMetrics(report []json_v2.ScoredObject, js nats.JetStreamContext) error { + + ctx:=context.Background() + tracer := otel.Tracer("kubescore") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "publishKubescoreMetrics") + span.SetAttributes(attribute.String("kubescore-plugin-agent", "kubescore-output")) + defer span.End() + metrics := model.KubeScoreRecommendations{ ID: uuid.New().String(), ClusterName: ClusterName, @@ -73,6 +83,13 @@ func publishKubescoreMetrics(report []json_v2.ScoredObject, js nats.JetStreamCon } func executeCommand(command string) (string, error) { + + ctx:=context.Background() + tracer := otel.Tracer("kubescore") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "executeCommand") + span.SetAttributes(attribute.String("kubescore-agent", "kubescore-command-running")) + defer span.End() + cmd := exec.Command("/bin/sh", "-c", command) stdout, err := cmd.Output() diff --git a/agent/kubviz/outdated.go b/agent/kubviz/outdated.go index ce3a77d3..8b2fe748 100644 --- a/agent/kubviz/outdated.go +++ b/agent/kubviz/outdated.go @@ -15,6 +15,9 @@ import ( "time" "github.com/intelops/kubviz/constants" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "github.com/intelops/kubviz/model" "github.com/nats-io/nats.go" @@ -56,6 +59,13 @@ func truncateTagName(tagName string) string { return truncatedTagName } func PublishOutdatedImages(out model.CheckResultfinal, js nats.JetStreamContext) error { + + ctx:=context.Background() + tracer := otel.Tracer("outdated-images") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "PublishOutdatedImages") + span.SetAttributes(attribute.String("outdated-plugin-agent", "outdated-output")) + defer span.End() + metrics := out metrics.ClusterName = ClusterName metricsJson, _ := json.Marshal(metrics) diff --git a/agent/kubviz/rakees_agent.go b/agent/kubviz/rakees_agent.go index 0b8426c1..0b1d142c 100644 --- a/agent/kubviz/rakees_agent.go +++ b/agent/kubviz/rakees_agent.go @@ -10,6 +10,9 @@ import ( "syscall" "github.com/intelops/kubviz/constants" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "github.com/intelops/kubviz/agent/kubviz/rakkess" "github.com/intelops/kubviz/model" @@ -34,6 +37,13 @@ func accessToOutcome(access rakkess.Access) (rakkess.Outcome, error) { } func RakeesOutput(config *rest.Config, js nats.JetStreamContext) error { + + ctx:=context.Background() + tracer := otel.Tracer("rakees") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "RakeesOutput") + span.SetAttributes(attribute.String("rakees-plugin-agent", "rakees-output")) + defer span.End() + // Create a new Kubernetes client client, err := kubernetes.NewForConfig(config) if err != nil { diff --git a/agent/kubviz/trivy.go b/agent/kubviz/trivy.go index 848f2595..2cedf804 100644 --- a/agent/kubviz/trivy.go +++ b/agent/kubviz/trivy.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "encoding/json" "fmt" "log" @@ -13,10 +14,20 @@ import ( "github.com/google/uuid" "github.com/intelops/kubviz/constants" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/nats-io/nats.go" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) func executeCommandTrivy(command string) ([]byte, error) { + + ctx := context.Background() + tracer := otel.Tracer("trivy-cluster") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "executeCommandTrivy") + span.SetAttributes(attribute.String("trivy-k8s-agent", "command-running")) + defer span.End() + cmd := exec.Command("/bin/sh", "-c", command) var outc, errc bytes.Buffer cmd.Stdout = &outc @@ -39,6 +50,13 @@ func RunTrivyK8sClusterScan(js nats.JetStreamContext) error { return err } var report report.ConsolidatedReport + + ctx := context.Background() + tracer := otel.Tracer("trivy-cluster") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "RunTrivyK8sClusterScan") + span.SetAttributes(attribute.String("cluster-name", report.ClusterName)) + defer span.End() + cmdString := fmt.Sprintf("trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir %s --debug", trivyCacheDir) // clearCacheCmd := "trivy k8s --clear-cache" out, err := executeCommandTrivy(cmdString) diff --git a/agent/kubviz/trivy_image.go b/agent/kubviz/trivy_image.go index 8a64fb5c..d8d70e5a 100644 --- a/agent/kubviz/trivy_image.go +++ b/agent/kubviz/trivy_image.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "fmt" "log" @@ -11,7 +12,10 @@ import ( "github.com/google/uuid" "github.com/intelops/kubviz/constants" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/nats-io/nats.go" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "k8s.io/client-go/rest" ) @@ -25,6 +29,12 @@ func RunTrivyImageScans(config *rest.Config, js nats.JetStreamContext) error { } // clearCacheCmd := "trivy image --clear-cache" + ctx:=context.Background() + tracer := otel.Tracer("trivy-image") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "RunTrivyImageScans") + span.SetAttributes(attribute.String("trivy-image-scan-agent", "image-scan")) + defer span.End() + images, err := ListImages(config) if err != nil { log.Println("error occured while trying to list images, error :", err.Error()) diff --git a/agent/kubviz/trivy_sbom.go b/agent/kubviz/trivy_sbom.go index 5cc0f13c..944037db 100644 --- a/agent/kubviz/trivy_sbom.go +++ b/agent/kubviz/trivy_sbom.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "encoding/json" "fmt" "log" @@ -12,7 +13,10 @@ import ( "github.com/google/uuid" "github.com/intelops/kubviz/constants" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/nats-io/nats.go" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "k8s.io/client-go/rest" ) @@ -48,6 +52,13 @@ func publishTrivySbomReport(report cyclonedx.BOM, js nats.JetStreamContext) erro } func executeCommandSbom(command string) ([]byte, error) { + + ctx:=context.Background() + tracer := otel.Tracer("trivy-sbom") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "executeCommandSbom") + span.SetAttributes(attribute.String("trivy-sbom-agent", "sbom-command-running")) + defer span.End() + cmd := exec.Command("/bin/sh", "-c", command) var outc, errc bytes.Buffer cmd.Stdout = &outc @@ -68,6 +79,13 @@ func RunTrivySbomScan(config *rest.Config, js nats.JetStreamContext) error { log.Printf("Error creating Trivy cache directory: %v\n", err) return err } + + ctx:=context.Background() + tracer := otel.Tracer("trivy-sbom") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "RunTrivySbomScan") + span.SetAttributes(attribute.String("sbom", "sbom-creation")) + defer span.End() + images, err := ListImages(config) if err != nil { diff --git a/agent/server/server.go b/agent/server/server.go index cee938ae..70eb3b3e 100644 --- a/agent/server/server.go +++ b/agent/server/server.go @@ -6,6 +6,8 @@ import ( _ "net/http/pprof" "github.com/gin-gonic/gin" + "github.com/intelops/kubviz/pkg/opentelemetry" + "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" ) func EnableProfile(r *gin.Engine) { @@ -32,6 +34,14 @@ func EnableProfile(r *gin.Engine) { func StartServer() { r := gin.Default() + + config, err := opentelemetry.GetConfigurations() + if err != nil { + log.Println("Unable to read open telemetry configurations") + } + + r.Use(otelgin.Middleware(config.ServiceName)) + EnableProfile(r) log.Fatal(r.Run(":8080")) } diff --git a/client/main.go b/client/main.go index e3c5611c..af2316db 100644 --- a/client/main.go +++ b/client/main.go @@ -1,17 +1,30 @@ package main import ( + "context" "log" "os" "os/signal" "syscall" "github.com/intelops/kubviz/client/pkg/application" + "github.com/intelops/kubviz/pkg/opentelemetry" ) func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) log.Println("new client running...") + + tp, err := opentelemetry.InitTracer() + if err != nil { + log.Fatal(err) + } + defer func() { + if err := tp.Shutdown(context.Background()); err != nil { + log.Printf("Error shutting down tracer provider: %v", err) + } + }() + app := application.Start() signals := make(chan os.Signal, 1) diff --git a/client/pkg/application/application.go b/client/pkg/application/application.go index d95e8ede..c7bfd8eb 100644 --- a/client/pkg/application/application.go +++ b/client/pkg/application/application.go @@ -1,12 +1,16 @@ package application import ( + "context" "log" "github.com/intelops/kubviz/client/pkg/clickhouse" "github.com/intelops/kubviz/client/pkg/clients" "github.com/intelops/kubviz/client/pkg/config" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/kelseyhightower/envconfig" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) type Application struct { @@ -17,6 +21,13 @@ type Application struct { func Start() *Application { log.Println("Client Application started...") + + ctx:=context.Background() + tracer := otel.Tracer("kubviz-client") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "Start") + span.SetAttributes(attribute.String("start-app-client", "application")) + defer span.End() + cfg := &config.Config{} if err := envconfig.Process("", cfg); err != nil { log.Fatalf("Could not parse env Config: %v", err) diff --git a/client/pkg/clickhouse/db_client.go b/client/pkg/clickhouse/db_client.go index 35460db3..ff17af95 100644 --- a/client/pkg/clickhouse/db_client.go +++ b/client/pkg/clickhouse/db_client.go @@ -10,12 +10,15 @@ import ( "time" "github.com/ClickHouse/clickhouse-go/v2" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "github.com/ClickHouse/clickhouse-go/v2/lib/driver" "github.com/intelops/kubviz/client/pkg/config" "github.com/intelops/kubviz/gitmodels/dbstatement" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" ) type DBClient struct { @@ -134,6 +137,12 @@ func NewDBClient(conf *config.Config) (DBInterface, error) { func (c *DBClient) InsertContainerEventAzure(pushEvent model.AzureContainerPushEventPayload) { + ctx:=context.Background() + tracer := otel.Tracer("insert-container-azure") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertContainerEventAzure") + span.SetAttributes(attribute.String("container-azure-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -183,6 +192,13 @@ func (c *DBClient) InsertContainerEventAzure(pushEvent model.AzureContainerPushE } func (c *DBClient) InsertContainerEventQuay(pushEvent model.QuayImagePushPayload) { + + ctx:=context.Background() + tracer := otel.Tracer("insert-container-quay") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertContainerEventQuay") + span.SetAttributes(attribute.String("container-quay-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -234,6 +250,13 @@ func (c *DBClient) InsertContainerEventQuay(pushEvent model.QuayImagePushPayload } func (c *DBClient) InsertContainerEventJfrog(pushEvent model.JfrogContainerPushEventPayload) { + + ctx:=context.Background() + tracer := otel.Tracer("insert-container-jfrog") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertContainerEventJfrog") + span.SetAttributes(attribute.String("container-jfrog-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -285,6 +308,13 @@ func (c *DBClient) InsertContainerEventJfrog(pushEvent model.JfrogContainerPushE } func (c *DBClient) InsertRakeesMetrics(metrics model.RakeesMetrics) { + + ctx:=context.Background() + tracer := otel.Tracer("insert-rakees-metrics") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertRakeesMetrics") + span.SetAttributes(attribute.String("rakees-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -315,6 +345,13 @@ func (c *DBClient) InsertRakeesMetrics(metrics model.RakeesMetrics) { } func (c *DBClient) InsertKetallEvent(metrics model.Resource) { + + ctx:=context.Background() + tracer := otel.Tracer("insert-ketall-event") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertKetallEvent") + span.SetAttributes(attribute.String("ketall-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -344,6 +381,13 @@ func (c *DBClient) InsertKetallEvent(metrics model.Resource) { } func (c *DBClient) InsertOutdatedEvent(metrics model.CheckResultfinal) { + + ctx:=context.Background() + tracer := otel.Tracer("insert-outdated-event") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertOutdatedEvent") + span.SetAttributes(attribute.String("outdated-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -375,6 +419,13 @@ func (c *DBClient) InsertOutdatedEvent(metrics model.CheckResultfinal) { } func (c *DBClient) InsertDeprecatedAPI(deprecatedAPI model.DeprecatedAPI) { + + ctx:=context.Background() + tracer := otel.Tracer("insert-depricated-event") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertDeprecatedAPI") + span.SetAttributes(attribute.String("depricated-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -413,6 +464,13 @@ func (c *DBClient) InsertDeprecatedAPI(deprecatedAPI model.DeprecatedAPI) { } func (c *DBClient) InsertDeletedAPI(deletedAPI model.DeletedAPI) { + + ctx:=context.Background() + tracer := otel.Tracer("insert-deletedapi") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertDeletedAPI") + span.SetAttributes(attribute.String("deletedapi-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -452,6 +510,13 @@ func (c *DBClient) InsertDeletedAPI(deletedAPI model.DeletedAPI) { } func (c *DBClient) InsertKubvizEvent(metrics model.Metrics) { + + ctx:=context.Background() + tracer := otel.Tracer("insert-kubviz-event") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertKubvizEvent") + span.SetAttributes(attribute.String("kubvizevent-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -489,6 +554,12 @@ func (c *DBClient) InsertKubvizEvent(metrics model.Metrics) { } func (c *DBClient) InsertGitEvent(event string) { ctx := context.Background() + + tracer := otel.Tracer("insert-git-event") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertGitEvent") + span.SetAttributes(attribute.String("git-client", "insert")) + defer span.End() + batch, err := c.splconn.PrepareBatch(ctx, "INSERT INTO git_json") if err != nil { log.Fatal(err) @@ -504,6 +575,12 @@ func (c *DBClient) InsertGitEvent(event string) { } func (c *DBClient) InsertContainerEvent(event string) { ctx := context.Background() + + tracer := otel.Tracer("insert-container-event") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertContainerEvent") + span.SetAttributes(attribute.String("container-client", "insert")) + defer span.End() + batch, err := c.splconn.PrepareBatch(ctx, "INSERT INTO container_bridge") if err != nil { log.Fatal(err) @@ -519,6 +596,14 @@ func (c *DBClient) InsertContainerEvent(event string) { } func (c *DBClient) InsertKubeScoreMetrics(metrics model.KubeScoreRecommendations) { + + ctx := context.Background() + + tracer := otel.Tracer("insert-kubescore-event") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertKubeScoreMetrics") + span.SetAttributes(attribute.String("kubescore-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -564,6 +649,13 @@ func (c *DBClient) InsertKubeScoreMetrics(metrics model.KubeScoreRecommendations } func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) { + + ctx := context.Background() + tracer := otel.Tracer("insert-trivy-metrics") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertTrivyMetrics") + span.SetAttributes(attribute.String("trivy-metrics-client", "insert")) + defer span.End() + for _, finding := range metrics.Report.Findings { for _, result := range finding.Results { for _, vulnerability := range result.Vulnerabilities { @@ -644,6 +736,13 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) { } func (c *DBClient) InsertTrivyImageMetrics(metrics model.TrivyImage) { + + ctx := context.Background() + tracer := otel.Tracer("insert-trivy-image") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertTrivyImageMetrics") + span.SetAttributes(attribute.String("trivy-image-client", "insert")) + defer span.End() + for _, result := range metrics.Report.Results { for _, vulnerability := range result.Vulnerabilities { tx, err := c.conn.Begin() @@ -688,6 +787,12 @@ func (c *DBClient) InsertTrivyImageMetrics(metrics model.TrivyImage) { func (c *DBClient) InsertTrivySbomMetrics(metrics model.SbomData) { log.Println("####started inserting value") + ctx := context.Background() + tracer := otel.Tracer("insert-trivy-sbom") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertTrivySbomMetrics") + span.SetAttributes(attribute.String("trivy-sbom-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -815,6 +920,13 @@ func (c *DBClient) RetrieveKubvizEvent() ([]model.DbEvent, error) { } func (c *DBClient) InsertContainerEventDockerHub(build model.DockerHubBuild) { + + ctx := context.Background() + tracer := otel.Tracer("insert-container-dockerhub") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertContainerEventDockerHub") + span.SetAttributes(attribute.String("container-dockerhub-client", "insert")) + defer span.End() + tx, err := c.conn.Begin() if err != nil { log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err) @@ -845,6 +957,13 @@ func (c *DBClient) InsertContainerEventDockerHub(build model.DockerHubBuild) { } func (c *DBClient) InsertContainerEventGithub(event string) { + + ctx := context.Background() + tracer := otel.Tracer("insert-container-github") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "InsertContainerEventGithub") + span.SetAttributes(attribute.String("container-github-client", "insert")) + defer span.End() + var image model.GithubImage err := json.Unmarshal([]byte(event), &image) if err != nil { diff --git a/client/pkg/clients/bridge_client.go b/client/pkg/clients/bridge_client.go index 3082bf57..999cc07a 100644 --- a/client/pkg/clients/bridge_client.go +++ b/client/pkg/clients/bridge_client.go @@ -1,6 +1,7 @@ package clients import ( + "context" "encoding/json" "errors" "log" @@ -15,7 +16,10 @@ import ( "github.com/intelops/kubviz/gitmodels/azuremodel" "github.com/intelops/kubviz/gitmodels/dbstatement" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/nats-io/nats.go" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) // ErrHeaderEmpty defines an error occur when header is empty in git stream @@ -36,6 +40,13 @@ const ( // the respective funcs to insert data into clickhouse DB func (n *NATSContext) SubscribeGitBridgeNats(conn clickhouse.DBInterface) { log.Printf("Creating nats consumer %s with subject: %s \n", bridgeConsumer, bridgeSubject) + + ctx:=context.Background() + tracer := otel.Tracer("git-client") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "SubscribeGitBridgeNats") + span.SetAttributes(attribute.String("git-subscribe", "Subscribe")) + defer span.End() + n.stream.Subscribe(string(bridgeSubject), func(msg *nats.Msg) { msg.Ack() gitprovider := msg.Header.Get("GitProvider") diff --git a/client/pkg/clients/container_client.go b/client/pkg/clients/container_client.go index 29dc5763..cea17181 100644 --- a/client/pkg/clients/container_client.go +++ b/client/pkg/clients/container_client.go @@ -1,6 +1,7 @@ package clients import ( + "context" "encoding/json" "errors" "log" @@ -8,7 +9,10 @@ import ( "github.com/intelops/kubviz/client/pkg/clickhouse" "github.com/intelops/kubviz/model" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/nats-io/nats.go" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" ) var ( @@ -26,6 +30,13 @@ const ( ) func (n *NATSContext) SubscribeContainerNats(conn clickhouse.DBInterface) { + + ctx:=context.Background() + tracer := otel.Tracer("container-client") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "SubscribeContainerNats") + span.SetAttributes(attribute.String("container-subscribe", "Subscribe")) + defer span.End() + n.stream.Subscribe(string(containerSubject), func(msg *nats.Msg) { msg.Ack() repoName := msg.Header.Get("REPO_NAME") diff --git a/client/pkg/clients/kubviz_client.go b/client/pkg/clients/kubviz_client.go index 683cd563..d4854dfa 100644 --- a/client/pkg/clients/kubviz_client.go +++ b/client/pkg/clients/kubviz_client.go @@ -1,11 +1,15 @@ package clients import ( + "context" "encoding/json" "log" "github.com/intelops/kubviz/constants" + "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/nats-io/nats.go" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "github.com/intelops/kubviz/client/pkg/clickhouse" "github.com/intelops/kubviz/model" @@ -18,6 +22,13 @@ type SubscriptionInfo struct { } func (n *NATSContext) SubscribeAllKubvizNats(conn clickhouse.DBInterface) { + + ctx:=context.Background() + tracer := otel.Tracer("kubviz-client") + _, span := tracer.Start(opentelemetry.BuildContext(ctx), "SubscribeAllKubvizNats") + span.SetAttributes(attribute.String("kubviz-subscribe", "subscribe")) + defer span.End() + subscribe := func(sub SubscriptionInfo) { n.stream.Subscribe(sub.Subject, sub.Handler, nats.Durable(sub.Consumer), nats.ManualAck()) } diff --git a/go.mod b/go.mod index 48f274bd..e6b1f544 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/go-co-op/gocron v1.30.1 github.com/go-playground/webhooks/v6 v6.2.0 github.com/golang-migrate/migrate/v4 v4.16.2 - github.com/google/uuid v1.3.0 + github.com/google/uuid v1.3.1 github.com/hashicorp/go-version v1.6.0 github.com/intelops/go-common v1.0.19 github.com/kelseyhightower/envconfig v1.4.0 @@ -25,7 +25,12 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/zegl/kube-score v1.17.0 - golang.org/x/term v0.11.0 + go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.46.1 + go.opentelemetry.io/otel v1.21.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 + go.opentelemetry.io/otel/sdk v1.21.0 + golang.org/x/term v0.14.0 k8s.io/api v0.27.3 k8s.io/apimachinery v0.27.3 k8s.io/cli-runtime v0.27.3 @@ -34,7 +39,7 @@ require ( ) require ( - cloud.google.com/go v0.110.6 // indirect + cloud.google.com/go v0.110.7 // indirect cloud.google.com/go/iam v1.1.1 // indirect cloud.google.com/go/storage v1.30.1 // indirect github.com/ClickHouse/ch-go v0.52.1 // indirect @@ -47,6 +52,7 @@ require ( github.com/aquasecurity/trivy-db v0.0.0-20230703082116-dc52e83376ce // indirect github.com/aquasecurity/trivy-kubernetes v0.5.7-0.20230628140707-dae3bdb6ee81 // indirect github.com/bytedance/sonic v1.9.1 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/docker/distribution v2.8.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect @@ -60,7 +66,8 @@ require ( github.com/go-errors/errors v1.4.2 // indirect github.com/go-faster/city v1.0.1 // indirect github.com/go-faster/errors v0.6.1 // 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.1 // indirect github.com/go-openapi/swag v0.22.3 // indirect @@ -72,12 +79,13 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-containerregistry v0.15.2 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/googleapis/gax-go/v2 v2.11.0 // indirect github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/imdario/mergo v0.3.15 // indirect @@ -88,7 +96,6 @@ require ( github.com/klauspost/compress v1.16.5 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/knqyf263/go-rpm-version v0.0.0-20220614171824-631e686d1075 // indirect - github.com/kr/pretty v0.3.1 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect github.com/mailru/easyjson v0.7.7 // indirect @@ -127,26 +134,27 @@ require ( github.com/ugorji/go/codec v1.2.11 // indirect github.com/xlab/treeprint v1.1.0 // indirect go.etcd.io/bbolt v1.3.7 // indirect - go.opentelemetry.io/otel v1.14.0 // indirect - go.opentelemetry.io/otel/trace v1.14.0 // indirect + go.opentelemetry.io/otel/metric v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.21.0 // indirect + go.opentelemetry.io/proto/otlp v1.0.0 // indirect go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect go.uber.org/atomic v1.10.0 // indirect - go.uber.org/goleak v1.2.1 // indirect go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.12.0 // indirect + golang.org/x/crypto v0.15.0 // indirect golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/net v0.14.0 // indirect + golang.org/x/net v0.18.0 // indirect golang.org/x/oauth2 v0.11.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect + golang.org/x/sys v0.14.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.126.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // 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 ce5d958d..ce8b6444 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.110.6 h1:8uYAkj3YHTP/1iwReuHPxLSbdcyc+dSBbzFMrVwDR6Q= -cloud.google.com/go v0.110.6/go.mod h1:+EYjdK8e5RME/VY/qLCAtuyALQ9q67dvuum8i+H5xsI= +cloud.google.com/go v0.110.7 h1:rJyC7nWRg2jWGZ4wSJ5nY65GTdYJkg0cd/uXb+ACI6o= +cloud.google.com/go v0.110.7/go.mod h1:+EYjdK8e5RME/VY/qLCAtuyALQ9q67dvuum8i+H5xsI= cloud.google.com/go/compute v1.23.0 h1:tP41Zoavr8ptEqaW6j+LQOnyBBhO7OkOMAGrgLopTwY= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/iam v1.1.1 h1:lW7fzj15aVIXYHREOqjRBV9PsH0Z6u8Y46a1YGvQP4Y= @@ -69,6 +69,8 @@ github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4 github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +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/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNSjIRk= @@ -153,9 +155,11 @@ github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8 github.com/go-git/go-git/v5 v5.7.0 h1:t9AudWVLmqzlo+4bqdf7GY+46SUuRsx59SboFxkq2aE= github.com/go-gorp/gorp/v3 v3.0.5 h1:PUjzYdYu3HBOh8LE+UUmRG2P0IRDak9XMeGNvaeq4Ow= 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.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= 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= @@ -187,6 +191,7 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang-migrate/migrate/v4 v4.16.2 h1:8coYbMKUyInrFk1lfGfRovTLAW7PhWp8qQDT2iKfuoA= github.com/golang-migrate/migrate/v4 v4.16.2/go.mod h1:pfcJX4nPHaVdc5nmdCikFBWtm+UBpiZjRNNsyBbp0/o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -213,8 +218,9 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/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-containerregistry v0.15.2 h1:MMkSh+tjSdnmJZO7ljvEqV1DjfekB6VUEAZgy3a+TQE= github.com/google/go-containerregistry v0.15.2/go.mod h1:wWK+LnOv4jXMM23IT/F1wdYftGWGr47Is8CG+pmHK1Q= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -225,8 +231,8 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJY github.com/google/s2a-go v0.1.4 h1:1kZ/sQM3srePvKs3tXAvQzo66XfcReoqFpIpIccE7Oc= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9aurXEpJX+U6FLtpYTdC3R06k= github.com/googleapis/gax-go/v2 v2.11.0 h1:9V9PWXEsWnPpQhu/PeQIkS4eGzMlTLGgt80cUUI8Ki4= github.com/googleapis/gax-go/v2 v2.11.0/go.mod h1:DxmR61SGKkGLa2xigwuZIQpkCI2S5iydzRfb3peWZJI= @@ -237,6 +243,8 @@ github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.11.1/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +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/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -286,7 +294,6 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -400,7 +407,6 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rubenv/sql-migrate v1.3.1 h1:Vx+n4Du8X8VTYuXbhNxdEUoh6wiJERA0GlWocR5FrbA= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= @@ -478,17 +484,29 @@ go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ= go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= go.mongodb.org/mongo-driver v1.11.1/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= -go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= -go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= -go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M= -go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8= +go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.46.1 h1:mMv2jG58h6ZI5t5S9QCVGdzCmAsTakMa3oxVgpSD44g= +go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.46.1/go.mod h1:oqRuNKG0upTaDPbLVCG8AD0G2ETrfDtmh7jViy7ox6M= +go.opentelemetry.io/contrib/propagators/b3 v1.21.1 h1:WPYiUgmw3+b7b3sQ1bFBFAf0q+Di9dvNc3AtYfnT4RQ= +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.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 h1:+FNtrFTmVw0YZGpBGX56XDee331t6JAXeK2bcyhLOOc= go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= -go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= @@ -500,8 +518,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk 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= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= @@ -522,8 +540,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= -golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU= golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk= @@ -550,18 +568,18 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.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.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= -golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= +golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= +golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -591,16 +609,17 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g= -google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8= -google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e h1:z3vDksarJxsAKM5dmEGv0GHwE2hKJ096wZra71Vs4sw= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY= +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-20230913181813-007df8e322eb h1:Isk1sSH7bovx8Rti2wZK0UZF6oraBDK74uoyLEEVFN0= google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= +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 v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/pkg/opentelemetry/opentelemetry.go b/pkg/opentelemetry/opentelemetry.go new file mode 100644 index 00000000..f3c6d2dd --- /dev/null +++ b/pkg/opentelemetry/opentelemetry.go @@ -0,0 +1,88 @@ +package opentelemetry + +import ( + "context" + "log" + + "github.com/kelseyhightower/envconfig" + "github.com/pkg/errors" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/sdk/resource" + "go.opentelemetry.io/otel/sdk/trace" + sdktrace "go.opentelemetry.io/otel/sdk/trace" +) + +type Configurations struct { + ServiceName string `envconfig:"APPLICATION_NAME" default:"Kubviz"` + CollectorURL string `envconfig:"OPTEL_URL" default:"otelcollector.azureagent.optimizor.app:80"` +} + +func GetConfigurations() (opteConfig *Configurations, err error) { + opteConfig = &Configurations{} + if err = envconfig.Process("", opteConfig); err != nil { + return nil, errors.WithStack(err) + } + return +} + +func InitTracer() (*sdktrace.TracerProvider, error) { + ctx := context.Background() + + config, err := GetConfigurations() + if err != nil { + log.Println("Unable to read open telemetry configurations") + return nil, err + } + + headers := map[string]string{ + "signoz-service-name": config.ServiceName, + } + + client := otlptracegrpc.NewClient( + otlptracegrpc.WithEndpoint(config.CollectorURL), + otlptracegrpc.WithHeaders(headers), + otlptracegrpc.WithInsecure(), + ) + + exporter, err := otlptrace.New(ctx, client) + if err != nil { + log.Fatalf("failed to initialize exporter: %e", err) + } + + res, err := resource.New( + ctx, + resource.WithAttributes( + attribute.String("service.name", config.ServiceName), + attribute.String("library.language", "go"), + + ), + ) + if err != nil { + log.Fatalf("failed to initialize resource: %e", err) + } + + // Create the trace provider + tp := sdktrace.NewTracerProvider( + trace.WithSampler(trace.AlwaysSample()), + sdktrace.WithBatcher(exporter), + sdktrace.WithResource(res), + ) + + // Set the global trace provider + otel.SetTracerProvider(tp) + + // Set the propagator + propagator := propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}) + otel.SetTextMapPropagator(propagator) + + return tp, nil +} + +func BuildContext(ctx context.Context) context.Context { + newCtx, _ := context.WithCancel(ctx) + return newCtx +} \ No newline at end of file