Skip to content

Commit 2263ace

Browse files
authored
Merge branch 'develop' into api-specs-post
2 parents bdc2575 + f17457f commit 2263ace

File tree

6 files changed

+291
-79
lines changed

6 files changed

+291
-79
lines changed

client/telemetry/TelemetryEventClient.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,29 @@ func NewTelemetryEventClientImpl(logger *zap.SugaredLogger, client *http.Client,
133133

134134
func (impl *TelemetryEventClientImpl) GetCloudProvider() (string, error) {
135135
// assumption: the IMDS server will be reachable on startup
136+
// Return cached value or "unknown" if identification is still in progress
136137
if len(impl.telemetryConfig.cloudProvider) == 0 {
137-
provider, err := impl.cloudProviderIdentifierService.IdentifyProvider()
138-
if err != nil {
139-
impl.logger.Errorw("exception while getting cluster provider", "error", err)
140-
return "", err
141-
}
142-
impl.telemetryConfig.cloudProvider = provider
138+
// Return unknown for now, background identification will update this
139+
return "unknown", nil
143140
}
144141
return impl.telemetryConfig.cloudProvider, nil
145142
}
146143

144+
// identifyCloudProviderAsync runs cloud provider identification in background
145+
func (impl *TelemetryEventClientImpl) identifyCloudProviderAsync() {
146+
impl.logger.Info("Starting cloud provider identification in background")
147+
148+
provider, err := impl.cloudProviderIdentifierService.IdentifyProvider()
149+
if err != nil {
150+
impl.logger.Errorw("exception while getting cluster provider", "error", err)
151+
impl.telemetryConfig.cloudProvider = "unknown"
152+
return
153+
}
154+
155+
impl.telemetryConfig.cloudProvider = provider
156+
impl.logger.Infow("Cloud provider identified", "provider", provider)
157+
}
158+
147159
func (impl *TelemetryEventClientImpl) StopCron() {
148160
impl.cron.Stop()
149161
}
@@ -341,6 +353,10 @@ func (impl *TelemetryEventClientImpl) GetTelemetryMetaInfo() (*TelemetryMetaInfo
341353

342354
func (impl *TelemetryEventClientImpl) SendTelemetryInstallEventEA() (*TelemetryEventType, error) {
343355
ucid, err := impl.getUCIDAndCheckIsOptedOut(context.Background())
356+
357+
// Start cloud provider identification in background to avoid blocking startup
358+
go impl.identifyCloudProviderAsync()
359+
344360
if err != nil {
345361
impl.logger.Errorw("exception while getting unique client id", "error", err)
346362
return nil, err

cmd/external-app/externalApp.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
posthogTelemetry "github.com/devtron-labs/common-lib/telemetry"
2423
"net/http"
2524
"os"
2625
"time"
2726

27+
posthogTelemetry "github.com/devtron-labs/common-lib/telemetry"
28+
2829
authMiddleware "github.com/devtron-labs/authenticator/middleware"
2930
"github.com/devtron-labs/common-lib/middlewares"
3031
"github.com/devtron-labs/devtron/client/telemetry"
@@ -71,21 +72,31 @@ func (app *App) Start() {
7172
app.MuxRouter.Init()
7273
//authEnforcer := casbin2.Create()
7374

74-
_, err := app.telemetry.SendTelemetryInstallEventEA()
75-
76-
if err != nil {
77-
app.Logger.Warnw("telemetry installation success event failed", "err", err)
78-
}
75+
// Send telemetry event asynchronously to avoid blocking startup
76+
go func() {
77+
_, err := app.telemetry.SendTelemetryInstallEventEA()
78+
if err != nil {
79+
app.Logger.Warnw("telemetry installation success event failed", "err", err)
80+
}
81+
}()
7982
server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: authMiddleware.Authorizer(app.sessionManager, user.WhitelistChecker, app.userService.CheckUserStatusAndUpdateLoginAudit)(app.MuxRouter.Router)}
8083
app.MuxRouter.Router.Use(middleware.PrometheusMiddleware)
8184
app.MuxRouter.Router.Use(middlewares.Recovery)
8285
app.server = server
8386

84-
err = server.ListenAndServe()
85-
if err != nil && !errors.Is(err, http.ErrServerClosed) {
86-
app.Logger.Errorw("error in startup", "err", err)
87-
os.Exit(2)
88-
}
87+
// Start server in goroutine to make it non-blocking
88+
go func() {
89+
app.Logger.Info("HTTP server starting to listen")
90+
err := server.ListenAndServe()
91+
if err != nil && !errors.Is(err, http.ErrServerClosed) {
92+
app.Logger.Errorw("error in startup", "err", err)
93+
os.Exit(2)
94+
}
95+
}()
96+
97+
// Give server a moment to start listening
98+
time.Sleep(1 * time.Second)
99+
app.Logger.Info("HTTP server should be ready for health checks")
89100
}
90101

91102
func (app *App) Stop() {
@@ -98,7 +109,10 @@ func (app *App) Stop() {
98109

99110
timeoutContext, _ := context.WithTimeout(context.Background(), 5*time.Second)
100111
app.Logger.Infow("closing router")
101-
err := app.server.Shutdown(timeoutContext)
112+
var err error
113+
if app.server != nil {
114+
err = app.server.Shutdown(timeoutContext)
115+
}
102116
if err != nil {
103117
app.Logger.Errorw("error in mux router shutdown", "err", err)
104118
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ require (
338338
replace (
339339
github.com/argoproj/argo-workflows/v3 v3.5.13 => github.com/devtron-labs/argo-workflows/v3 v3.5.13
340340
github.com/cyphar/filepath-securejoin v0.4.1 => github.com/cyphar/filepath-securejoin v0.3.6 // indirect
341-
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250902070957-ff08ef4190df
342-
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250902070957-ff08ef4190df
341+
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250910095456-9e49667d03f5
342+
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250910095456-9e49667d03f5
343343
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1
344344
)

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2
116116
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
117117
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
118118
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
119-
github.com/argoproj/argo-cd/v2 v2.14.13 h1:oSLPHV9Gon6mEqVkyBOuLJ7T16ShZv6xSjkCiquzEDM=
120-
github.com/argoproj/argo-cd/v2 v2.14.13/go.mod h1:P72XxcRigWQpQsuAgaXyHPFYkSPE4sdACA5g/s3Si1I=
121119
github.com/argoproj/argo-cd/v2 v2.14.17 h1:r/CkYKzHoPjGgJ/4/fdubUVpG+LBj6AtOigbitNHgy4=
122120
github.com/argoproj/argo-cd/v2 v2.14.17/go.mod h1:CF9GX0CjKiszpAnvYNCLV5tLSVqgfOgn/tcOt2VHTQo=
123121
github.com/argoproj/gitops-engine v0.7.1-0.20250521000818-c08b0a72c1f1 h1:Ze4U6kV49vSzlUBhH10HkO52bYKAIXS4tHr/MlNDfdU=
@@ -239,10 +237,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
239237
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
240238
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
241239
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
242-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250902070957-ff08ef4190df h1:cI8b8B/RKmAyuYgsN483H9hldoK/yOGMv2nNEPVFH+w=
243-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250902070957-ff08ef4190df/go.mod h1:9LCkYfiWaEKIBkmxw9jX1GujvEMyHwmDtVsatffAkeU=
244-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250902070957-ff08ef4190df h1:vYRAvhDypMUbUecNXTdJHp+dxgFsaCVMaYfVRmIM8LU=
245-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250902070957-ff08ef4190df/go.mod h1:BPvuxIUW9TNYZ3+9r39nMzeORMcLqTwNkakirqp9AzU=
240+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250910095456-9e49667d03f5 h1:NpkOPkaqVYWTArDgnwmhyh4W/qLppSE3VNqSZ27Z3/E=
241+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250910095456-9e49667d03f5/go.mod h1:9LCkYfiWaEKIBkmxw9jX1GujvEMyHwmDtVsatffAkeU=
242+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250910095456-9e49667d03f5 h1:DNyGQjgukvQ7cA0Dwd6+4DR5rKr5SFxv+eANWbFIc8o=
243+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250910095456-9e49667d03f5/go.mod h1:BPvuxIUW9TNYZ3+9r39nMzeORMcLqTwNkakirqp9AzU=
246244
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
247245
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
248246
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs=

0 commit comments

Comments
 (0)