Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implemented cache for storing cloud provider #4591

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions client/telemetry/TelemetryEventClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type TelemetryEventClientImpl struct {
InstalledAppRepository repository2.InstalledAppRepository
userAttributesRepository repository.UserAttributesRepository
cloudProviderIdentifierService cloudProviderIdentifier.ProviderIdentifierService
cloudProviderCache string
kartik-579 marked this conversation as resolved.
Show resolved Hide resolved
}

type TelemetryEventClient interface {
Expand Down Expand Up @@ -105,9 +106,24 @@ func NewTelemetryEventClientImpl(logger *zap.SugaredLogger, client *http.Client,
logger.Errorw("error in starting heartbeat event", "err", err)
return nil, err
}
err = watcher.UpdateCloudProviderCache()
if err != nil {
logger.Errorw("error in updating cloud provider", "err", err)
return nil, err
}
kartik-579 marked this conversation as resolved.
Show resolved Hide resolved
return watcher, err
}

func (impl *TelemetryEventClientImpl) UpdateCloudProviderCache() error {
provider, err := impl.cloudProviderIdentifierService.IdentifyProvider()
if err != nil {
impl.logger.Errorw("exception while getting cluster provider", "error", err)
return err
}
impl.cloudProviderCache = provider
return err
}

func (impl *TelemetryEventClientImpl) StopCron() {
impl.cron.Stop()
}
Expand Down Expand Up @@ -143,6 +159,7 @@ const DevtronUniqueClientIdConfigMap = "devtron-ucid"
const DevtronUniqueClientIdConfigMapKey = "UCID"
const InstallEventKey = "installEvent"
const UIEventKey = "uiEventKey"
const Unknown = "unknown"

type TelemetryEventType string

Expand Down Expand Up @@ -320,12 +337,14 @@ func (impl *TelemetryEventClientImpl) SendSummaryEvent(eventType string) error {
payload.HelmChartSuccessfulDeploymentCount = helmChartSuccessfulDeploymentCount
payload.ExternalHelmAppClusterCount = ExternalHelmAppClusterCount

provider, err := impl.cloudProviderIdentifierService.IdentifyProvider()
if err != nil {
impl.logger.Errorw("exception while getting cluster provider", "error", err)
return err
if len(payload.ClusterProvider) == 0 || payload.ClusterProvider == Unknown {
err := impl.UpdateCloudProviderCache()
if err != nil {
impl.logger.Errorw("error while updating cluster provider", "error", err)
return err
}
}
payload.ClusterProvider = provider
payload.ClusterProvider = impl.cloudProviderCache

latestUser, err := impl.userAuditService.GetLatestUser()
if err == nil {
Expand Down Expand Up @@ -486,12 +505,14 @@ func (impl *TelemetryEventClientImpl) SendTelemetryInstallEventEA() (*TelemetryE
payload.DevtronMode = util.GetDevtronVersion().ServerMode
payload.ServerVersion = k8sServerVersion.String()

provider, err := impl.cloudProviderIdentifierService.IdentifyProvider()
if err != nil {
impl.logger.Errorw("exception while getting cluster provider", "error", err)
return nil, err
if len(payload.ClusterProvider) == 0 || payload.ClusterProvider == Unknown {
err := impl.UpdateCloudProviderCache()
if err != nil {
impl.logger.Errorw("error while updating cluster provider", "error", err)
return nil, err
}
}
payload.ClusterProvider = provider
payload.ClusterProvider = impl.cloudProviderCache

reqBody, err := json.Marshal(payload)
if err != nil {
Expand Down Expand Up @@ -553,12 +574,14 @@ func (impl *TelemetryEventClientImpl) SendTelemetryDashboardAccessEvent() error
payload.DevtronMode = util.GetDevtronVersion().ServerMode
payload.ServerVersion = k8sServerVersion.String()

provider, err := impl.cloudProviderIdentifierService.IdentifyProvider()
if err != nil {
impl.logger.Errorw("exception while getting cluster provider", "error", err)
return err
if len(payload.ClusterProvider) == 0 || payload.ClusterProvider == Unknown {
err := impl.UpdateCloudProviderCache()
if err != nil {
impl.logger.Errorw("error while updating cluster provider", "error", err)
return err
}
}
payload.ClusterProvider = provider
payload.ClusterProvider = impl.cloudProviderCache

reqBody, err := json.Marshal(payload)
if err != nil {
Expand Down Expand Up @@ -620,12 +643,14 @@ func (impl *TelemetryEventClientImpl) SendTelemetryDashboardLoggedInEvent() erro
payload.DevtronMode = util.GetDevtronVersion().ServerMode
payload.ServerVersion = k8sServerVersion.String()

provider, err := impl.cloudProviderIdentifierService.IdentifyProvider()
if err != nil {
impl.logger.Errorw("exception while getting cluster provider", "error", err)
return err
if len(payload.ClusterProvider) == 0 || payload.ClusterProvider == Unknown {
err := impl.UpdateCloudProviderCache()
if err != nil {
impl.logger.Errorw("error while updating cluster provider", "error", err)
return err
}
}
payload.ClusterProvider = provider
payload.ClusterProvider = impl.cloudProviderCache

reqBody, err := json.Marshal(payload)
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions client/telemetry/TelemetryEventClientExtended.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,14 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string)
payload.HelmChartSuccessfulDeploymentCount = HelmChartSuccessfulDeploymentCount
payload.ExternalHelmAppClusterCount = ExternalHelmAppClusterCount

provider, err := impl.cloudProviderIdentifierService.IdentifyProvider()
if err != nil {
impl.logger.Errorw("exception while getting cluster provider", "error", err)
return err
if len(payload.ClusterProvider) == 0 || payload.ClusterProvider == Unknown {
err := impl.UpdateCloudProviderCache()
if err != nil {
impl.logger.Errorw("error while updating cluster provider", "error", err)
return err
}
}
payload.ClusterProvider = provider
payload.ClusterProvider = impl.cloudProviderCache

latestUser, err := impl.userAuditService.GetLatestUser()
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
github.com/devtron-labs/authenticator v0.4.33
github.com/devtron-labs/common-lib v0.0.10
github.com/devtron-labs/common-lib v0.0.11
github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADG
github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
github.com/devtron-labs/authenticator v0.4.33 h1:FpAV3ZgFluaRFcMwPpwxr/mwSipJ16XRvgABq3BzP5Y=
github.com/devtron-labs/authenticator v0.4.33/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU=
github.com/devtron-labs/common-lib v0.0.10 h1:3ayOUwIedXTvBEj80mKJ0iLo06glZ9nzY/WFsYFpYGM=
github.com/devtron-labs/common-lib v0.0.10/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU=
github.com/devtron-labs/common-lib v0.0.11 h1:xyVjD09miYhOKt0Oc//kOBWJas/OXsP7dyRoA1Hg90U=
github.com/devtron-labs/common-lib v0.0.11/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU=
github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY=
github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ github.com/devtron-labs/authenticator/jwt
github.com/devtron-labs/authenticator/middleware
github.com/devtron-labs/authenticator/oidc
github.com/devtron-labs/authenticator/password
# github.com/devtron-labs/common-lib v0.0.10
# github.com/devtron-labs/common-lib v0.0.11
## explicit; go 1.20
github.com/devtron-labs/common-lib/blob-storage
github.com/devtron-labs/common-lib/cloud-provider-identifier
Expand Down
Loading