From 8a53570670ade6c38afb96907867deb3e5f747a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Maro=C5=A1i?= Date: Tue, 16 Jan 2024 16:24:27 +0100 Subject: [PATCH] Setup debug logs for favoriting servives. (#379) --- config/config.go | 9 +++++++++ deploy/clowdapp.yml | 6 ++++++ rest/service/favoritePageService.go | 15 +++++++++++++++ rest/service/identity.go | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/config/config.go b/config/config.go index 0be6d344..aaeff5bc 100644 --- a/config/config.go +++ b/config/config.go @@ -56,6 +56,10 @@ type FeatureFlagsConfig struct { AdminToken string } +type DebugConfig struct { + DebugFavoriteIds []string +} + type ChromeServiceConfig struct { WebPort int OpenApiSpecPath string @@ -72,6 +76,7 @@ type ChromeServiceConfig struct { KafkaConfig KafkaCfg IntercomConfig IntercomConfig FeatureFlagConfig FeatureFlagsConfig + DebugConfig DebugConfig } const RdsCaLocation = "/app/rdsca.cert" @@ -203,6 +208,10 @@ func init() { dbaas: os.Getenv("INTERCOM_DBAAS"), dbaas_dev: os.Getenv("INTERCOM_DBAAS_DEV"), } + + options.DebugConfig = DebugConfig{ + DebugFavoriteIds: []string{"", os.Getenv("DEBUG_FAVORITES_ACCOUNT_1")}, + } config = options } diff --git a/deploy/clowdapp.yml b/deploy/clowdapp.yml index b2985943..676afa35 100644 --- a/deploy/clowdapp.yml +++ b/deploy/clowdapp.yml @@ -127,6 +127,11 @@ objects: secretKeyRef: name: chrome-service-backend key: SEARCH_CLIENT_SECRET_STAGE + - name: DEBUG_FAVORITES_ACCOUNT_1 + valueFrom: + secretKeyRef: + name: chrome-service-backend + key: DEBUG_FAVORITES_ACCOUNT_1 resources: limits: cpu: ${CPU_LIMIT} @@ -154,6 +159,7 @@ objects: SEARCH_CLIENT_SECRET_STAGE: dGVzdFZhbHVl INTERCOM_DBAAS: dGVzdFZhbHVl INTERCOM_DBAAS_DEV: dGVzdFZhbHVl + DEBUG_FAVORITES_ACCOUNT_1: OTk5 type: Opaque parameters: diff --git a/rest/service/favoritePageService.go b/rest/service/favoritePageService.go index 9cf2101a..ed7c2846 100644 --- a/rest/service/favoritePageService.go +++ b/rest/service/favoritePageService.go @@ -1,8 +1,12 @@ package service import ( + "fmt" + + "github.com/RedHatInsights/chrome-service-backend/config" "github.com/RedHatInsights/chrome-service-backend/rest/database" "github.com/RedHatInsights/chrome-service-backend/rest/models" + "github.com/sirupsen/logrus" ) func GetUserActiveFavoritePages(userID uint) ([]models.FavoritePage, error) { @@ -49,6 +53,15 @@ func UpdateFavoritePage(favoritePage models.FavoritePage) error { return database.DB.Model(&models.FavoritePage{}).Where("pathname = ?", favoritePage.Pathname).Update("favorite", favoritePage.Favorite).Error } +func debugFavoritesEntry(accountId uint, payload models.FavoritePage) { + c := config.Get() + for _, i := range c.DebugConfig.DebugFavoriteIds { + if i == fmt.Sprint(accountId) { + logrus.Warningln(fmt.Sprintf("\n_____\nDEBUG_FAVORITES_ACCOUNT_ID: %d\nDEBUG_FAVORITES_PATH: %s\nDEBUG_FAVORITES_FLAG: %s\n_____", accountId, payload.Pathname, fmt.Sprint(payload.Favorite))) + } + } +} + func SaveUserFavoritePage(userID uint, newFavoritePage models.FavoritePage) error { var userFavoritePages []models.FavoritePage @@ -62,7 +75,9 @@ func SaveUserFavoritePage(userID uint, newFavoritePage models.FavoritePage) erro if alreadyInDB { err = UpdateFavoritePage(newFavoritePage) + debugFavoritesEntry(userID, newFavoritePage) } else { + debugFavoritesEntry(userID, newFavoritePage) err = database.DB.Create(&newFavoritePage).Error } diff --git a/rest/service/identity.go b/rest/service/identity.go index 71ce054e..af1de9a9 100644 --- a/rest/service/identity.go +++ b/rest/service/identity.go @@ -33,6 +33,15 @@ const ( DBAAS IntercomApp = "dbaas" ) +func debugFavoritesIdentity(userId string) { + c := config.Get() + for _, i := range c.DebugConfig.DebugFavoriteIds { + if i == userId { + logrus.Warningln("DEBUG_FAVORITES_ACCOUNT_ID", userId) + } + } +} + func (ib IntercomApp) IsValidApp() error { switch ib { case OpenShift, HacCore, Ansible, Acs, AnsibleDashboard, AutomationHub, AutomationAnalytics, DBAAS: @@ -62,6 +71,7 @@ func GetUserIdentityData(user models.UserIdentity) (models.UserIdentity, error) return user, err } err = database.DB.Model(&user).Association("FavoritePages").Find(&favoritePages) + debugFavoritesIdentity(user.AccountId) user.LastVisitedPages = lastVisitedPages user.FavoritePages = favoritePages