Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
01e54cd
inital-commit
kripanshdevtron Dec 15, 2022
0fad98e
collector url config
kripanshdevtron Dec 15, 2022
c47245a
otel collector DNS rename
kripanshdevtron Dec 15, 2022
576970b
k8s otel handling
kripanshdevtron Dec 16, 2022
b8fe162
Merge branch 'main' into trace-observability-otlp
kripanshdevtron Dec 16, 2022
9288eee
k8s client override refactoring
kripanshdevtron Dec 16, 2022
96f36b1
grpc client instrumentation
kripanshdevtron Dec 16, 2022
4cc7f16
k8s client request with context
kripanshdevtron Dec 18, 2022
da429c2
other env API tracing
kripanshdevtron Dec 18, 2022
4a9a434
fetch other env context fix
kripanshdevtron Dec 18, 2022
be901c8
helm app context handling
kripanshdevtron Dec 18, 2022
b166937
app list urls context
kripanshdevtron Dec 18, 2022
b7b7ebb
k8s config client overriden
kripanshdevtron Dec 19, 2022
0ba2d57
manual deployment trigger OTEL
kripanshdevtron Dec 20, 2022
3d492e8
save deployment template API OTEL
kripanshdevtron Dec 20, 2022
cb7a391
ctx obj fix
kripanshdevtron Dec 20, 2022
d7c9d23
otel config check added
kripanshdevtron Dec 26, 2022
9355521
otel commit
kripanshdevtron Jan 4, 2023
daf8b97
otel service configured
kripanshdevtron Jan 4, 2023
366e878
wrapped span refactoring
kripanshdevtron Jan 12, 2023
b74ba51
Merge branch 'main' into trace-observability-otlp
kripanshdevtron Jan 12, 2023
bad9db7
otel integrated with more API
kripanshdevtron Jan 13, 2023
df0f803
Merge branch 'main' into trace-observability-otlp
kripanshdevtron Jan 15, 2023
7a504c0
cyclic dependency error fix
kripanshdevtron Jan 15, 2023
ce24a7a
context passed on
kripanshdevtron Jan 15, 2023
612f222
trace provider set
kripanshdevtron Jan 15, 2023
147e4ce
Merge branch 'main' into trace-observability-otlp
kripanshdevtron Jan 17, 2023
75a97ce
code refactoring
kripanshdevtron Jan 17, 2023
0bc09b6
override httpclient
kripanshdevtron Jan 17, 2023
646eaca
Merge branch 'main' into trace-observability-otlp
kripanshdevtron Jan 19, 2023
ec35ff3
refactoring done
kripanshdevtron Jan 19, 2023
a98729c
code cleaning
kripanshdevtron Jan 19, 2023
5f612cd
code cleaning
kripanshdevtron Jan 19, 2023
73b6d8a
code cleaning
kripanshdevtron Jan 19, 2023
cbcf5e2
k8s cluster service code cleaning
kripanshdevtron Jan 19, 2023
b7f32d2
clean directory fix
kripanshdevtron Jan 20, 2023
3727151
code refactoring fix
kripanshdevtron Jan 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 26 additions & 11 deletions App.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto/tls"
"fmt"
"github.com/devtron-labs/devtron/client/telemetry"
"github.com/devtron-labs/devtron/otel"
"log"
"net/http"
"os"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/devtron-labs/devtron/pkg/user"
"github.com/go-pg/pg"
_ "github.com/lib/pq"
"go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
"go.uber.org/zap"
)

Expand All @@ -49,8 +51,9 @@ type App struct {
pubsubClient *pubsub.PubSubClient
posthogClient *telemetry.PosthogClient
// used for local dev only
serveTls bool
sessionManager2 *authMiddleware.SessionManager
serveTls bool
sessionManager2 *authMiddleware.SessionManager
OtelTracingService *otel.OtelTracingServiceImpl
}

func NewApp(router *router.MuxRouter,
Expand All @@ -65,15 +68,16 @@ func NewApp(router *router.MuxRouter,
//check argo connection
//todo - check argo-cd version on acd integration installation
app := &App{
MuxRouter: router,
Logger: Logger,
SSE: sse,
Enforcer: enforcer,
db: db,
pubsubClient: pubsubClient,
serveTls: false,
sessionManager2: sessionManager2,
posthogClient: posthogClient,
MuxRouter: router,
Logger: Logger,
SSE: sse,
Enforcer: enforcer,
db: db,
pubsubClient: pubsubClient,
serveTls: false,
sessionManager2: sessionManager2,
posthogClient: posthogClient,
OtelTracingService: otel.NewOtelTracingServiceImpl(Logger),
}
return app
}
Expand All @@ -82,11 +86,19 @@ func (app *App) Start() {
port := 8080 //TODO: extract from environment variable
app.Logger.Debugw("starting server")
app.Logger.Infow("starting server on ", "port", port)

// setup tracer
tracerProvider := app.OtelTracingService.Init(otel.OTEL_ORCHESTRASTOR_SERVICE_NAME)

app.MuxRouter.Init()
//authEnforcer := casbin2.Create()

server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: authMiddleware.Authorizer(app.sessionManager2, user.WhitelistChecker)(app.MuxRouter.Router)}

app.MuxRouter.Router.Use(middleware.PrometheusMiddleware)
if tracerProvider != nil {
app.MuxRouter.Router.Use(otelmux.Middleware(otel.OTEL_ORCHESTRASTOR_SERVICE_NAME))
}
app.server = server
var err error
if app.serveTls {
Expand Down Expand Up @@ -124,6 +136,9 @@ func (app *App) Stop() {
if err != nil {
app.Logger.Errorw("error in mux router shutdown", "err", err)
}

app.OtelTracingService.Shutdown()

app.Logger.Infow("closing db connection")
err = app.db.Close()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ func InitializeApp() (*App, error) {
//ArgoUtil.NewClusterServiceImpl,
//wire.Bind(new(ArgoUtil.ClusterService), new(ArgoUtil.ClusterServiceImpl)),
pipeline.GetEcrConfig,
//otel.NewOtelTracingServiceImpl,
//wire.Bind(new(otel.OtelTracingService), new(*otel.OtelTracingServiceImpl)),
NewApp,
//session.NewK8sClient,

Expand Down
16 changes: 8 additions & 8 deletions api/helm-app/HelmAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (handler *HelmAppRestHandlerImpl) ListApplications(w http.ResponseWriter, r
clusterIds = append(clusterIds, j)
}
token := r.Header.Get("token")
handler.helmAppService.ListHelmApplications(clusterIds, w, token, handler.checkHelmAuth)
handler.helmAppService.ListHelmApplications(r.Context(), clusterIds, w, token, handler.checkHelmAuth)
}

func (handler *HelmAppRestHandlerImpl) GetApplicationDetail(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func (handler *HelmAppRestHandlerImpl) Hibernate(w http.ResponseWriter, r *http.
return
}
//RBAC enforcer Ends
res, err := handler.helmAppService.HibernateApplication(context.Background(), appIdentifier, hibernateRequest)
res, err := handler.helmAppService.HibernateApplication(r.Context(), appIdentifier, hibernateRequest)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand Down Expand Up @@ -185,7 +185,7 @@ func (handler *HelmAppRestHandlerImpl) UnHibernate(w http.ResponseWriter, r *htt
return
}
//RBAC enforcer Ends
res, err := handler.helmAppService.UnHibernateApplication(context.Background(), appIdentifier, hibernateRequest)
res, err := handler.helmAppService.UnHibernateApplication(r.Context(), appIdentifier, hibernateRequest)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand All @@ -212,7 +212,7 @@ func (handler *HelmAppRestHandlerImpl) GetReleaseInfo(w http.ResponseWriter, r *
return
}
//RBAC enforcer Ends
releaseInfo, err := handler.helmAppService.GetValuesYaml(context.Background(), appIdentifier)
releaseInfo, err := handler.helmAppService.GetValuesYaml(r.Context(), appIdentifier)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand Down Expand Up @@ -255,7 +255,7 @@ func (handler *HelmAppRestHandlerImpl) GetDesiredManifest(w http.ResponseWriter,
return
}
//RBAC enforcer Ends
res, err := handler.helmAppService.GetDesiredManifest(context.Background(), appIdentifier, desiredManifestRequest.Resource)
res, err := handler.helmAppService.GetDesiredManifest(r.Context(), appIdentifier, desiredManifestRequest.Resource)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand Down Expand Up @@ -304,7 +304,7 @@ func (handler *HelmAppRestHandlerImpl) DeleteApplication(w http.ResponseWriter,
return
}

res, err := handler.helmAppService.DeleteApplication(context.Background(), appIdentifier)
res, err := handler.helmAppService.DeleteApplication(r.Context(), appIdentifier)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand Down Expand Up @@ -338,7 +338,7 @@ func (handler *HelmAppRestHandlerImpl) UpdateApplication(w http.ResponseWriter,
//RBAC enforcer Ends

// update application externally
res, err := handler.helmAppService.UpdateApplication(context.Background(), appIdentifier, request)
res, err := handler.helmAppService.UpdateApplication(r.Context(), appIdentifier, request)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand All @@ -364,7 +364,7 @@ func (handler *HelmAppRestHandlerImpl) TemplateChart(w http.ResponseWriter, r *h
//making this api rbac free

// template chart starts
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
defer cancel()
response, err := handler.helmAppService.TemplateChart(ctx, request)
if err != nil {
Expand Down
17 changes: 12 additions & 5 deletions api/helm-app/HelmAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
"net/http"
"reflect"
Expand All @@ -36,7 +37,7 @@ const DEFAULT_CLUSTER = "default_cluster"
const DEFAULT_CLUSTER_ID = 1

type HelmAppService interface {
ListHelmApplications(clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool)
ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool)
GetApplicationDetail(ctx context.Context, app *AppIdentifier) (*AppDetail, error)
GetApplicationDetailWithFilter(ctx context.Context, app *AppIdentifier, resourceTreeFilter *ResourceTreeFilter) (*AppDetail, error)
HibernateApplication(ctx context.Context, app *AppIdentifier, hibernateRequest *openapi.HibernateRequest) ([]*openapi.HibernateStatus, error)
Expand Down Expand Up @@ -101,11 +102,13 @@ type ResourceRequestBean struct {
K8sRequest application.K8sRequestBean `json:"k8sRequest"`
}

func (impl *HelmAppServiceImpl) listApplications(clusterIds []int) (ApplicationService_ListApplicationsClient, error) {
func (impl *HelmAppServiceImpl) listApplications(ctx context.Context, clusterIds []int) (ApplicationService_ListApplicationsClient, error) {
if len(clusterIds) == 0 {
return nil, nil
}
_, span := otel.Tracer("clusterService").Start(ctx, "FindByIds")
clusters, err := impl.clusterService.FindByIds(clusterIds)
span.End()
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "err", err)
return nil, err
Expand All @@ -120,31 +123,35 @@ func (impl *HelmAppServiceImpl) listApplications(clusterIds []int) (ApplicationS
}
req.Clusters = append(req.Clusters, config)
}
applicatonStream, err := impl.helmAppClient.ListApplication(req)
applicatonStream, err := impl.helmAppClient.ListApplication(ctx, req)
if err != nil {
return nil, err
}

return applicatonStream, err
}

func (impl *HelmAppServiceImpl) ListHelmApplications(clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool) {
func (impl *HelmAppServiceImpl) ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool) {
var helmCdPipelines []*pipelineConfig.Pipeline
var installedHelmApps []*repository.InstalledApps
appStream, err := impl.listApplications(clusterIds)
appStream, err := impl.listApplications(ctx, clusterIds)
if err != nil {
impl.logger.Errorw("error in fetching app list", "clusters", clusterIds, "err", err)
}
if err == nil && len(clusterIds) > 0 {
// get helm apps which are created using cd_pipelines
newCtx, span := otel.Tracer("pipelineRepository").Start(ctx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method might be called from diff places Tracer("pipelineRepository").Start(ctx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline") will change accordingly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for all Tracer impl

helmCdPipelines, err = impl.pipelineRepository.GetAppAndEnvDetailsForDeploymentAppTypePipeline(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
span.End()
if err != nil {
impl.logger.Errorw("error in fetching helm app list from DB created using cd_pipelines", "clusters", clusterIds, "err", err)
}

// if not hyperion mode, then fetch from installed_apps whose deployment_app_type is helm (as in hyperion mode, these apps should be treated as external-apps)
if !util2.IsBaseStack() {
newCtx, span = otel.Tracer("pipelineRepository").Start(newCtx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
installedHelmApps, err = impl.installedAppRepository.GetAppAndEnvDetailsForDeploymentAppTypeInstalledApps(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
span.End()
if err != nil {
impl.logger.Errorw("error in fetching helm app list from DB created from app store", "clusters", clusterIds, "err", err)
}
Expand Down
9 changes: 6 additions & 3 deletions api/helm-app/applicationClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"fmt"
"github.com/caarlos0/env"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.uber.org/zap"
"google.golang.org/grpc"
"time"
)

type HelmAppClient interface {
ListApplication(req *AppListRequest) (ApplicationService_ListApplicationsClient, error)
ListApplication(ctx context.Context, req *AppListRequest) (ApplicationService_ListApplicationsClient, error)
GetAppDetail(ctx context.Context, in *AppDetailRequest) (*AppDetail, error)
Hibernate(ctx context.Context, in *HibernateRequest) (*HibernateResponse, error)
UnHibernate(ctx context.Context, in *HibernateRequest) (*HibernateResponse, error)
Expand Down Expand Up @@ -66,6 +67,8 @@ func (impl *HelmAppClientImpl) getConnection() (*grpc.ClientConn, error) {
var opts []grpc.DialOption
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
opts = append(opts,
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()),
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()),
grpc.WithBlock(),
grpc.WithInsecure(),
grpc.WithDefaultCallOptions(
Expand All @@ -81,12 +84,12 @@ func (impl *HelmAppClientImpl) getConnection() (*grpc.ClientConn, error) {
return conn, err
}

func (impl *HelmAppClientImpl) ListApplication(req *AppListRequest) (ApplicationService_ListApplicationsClient, error) {
func (impl *HelmAppClientImpl) ListApplication(ctx context.Context, req *AppListRequest) (ApplicationService_ListApplicationsClient, error) {
applicationClient, err := impl.getApplicationClient()
if err != nil {
return nil, err
}
stream, err := applicationClient.ListApplications(context.Background(), req)
stream, err := applicationClient.ListApplications(ctx, req)
if err != nil {
return nil, err
}
Expand Down
Loading