Skip to content

Commit

Permalink
Setup debug logs for favoriting servives. (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 authored Jan 16, 2024
1 parent adbc7de commit 8a53570
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type FeatureFlagsConfig struct {
AdminToken string
}

type DebugConfig struct {
DebugFavoriteIds []string
}

type ChromeServiceConfig struct {
WebPort int
OpenApiSpecPath string
Expand All @@ -72,6 +76,7 @@ type ChromeServiceConfig struct {
KafkaConfig KafkaCfg
IntercomConfig IntercomConfig
FeatureFlagConfig FeatureFlagsConfig
DebugConfig DebugConfig
}

const RdsCaLocation = "/app/rdsca.cert"
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions deploy/clowdapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions rest/service/favoritePageService.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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

Expand All @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions rest/service/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8a53570

Please sign in to comment.