From 6fe26ccd6bfb34da0233da799f0cac4c93d70e79 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Fri, 4 Oct 2024 16:54:45 +0530 Subject: [PATCH 01/16] error for partial read of query --- .../openwrap/database/mysql/app_integration_path.go | 5 +++++ .../openwrap/database/mysql/app_sub_integration_path.go | 5 +++++ .../openwrap/database/mysql/fullscreenclickability.go | 5 +++++ modules/pubmatic/openwrap/database/mysql/partner_config.go | 5 +++++ .../openwrap/database/mysql/profile_type_platform.go | 5 +++++ .../pubmatic/openwrap/database/mysql/publisher_feature.go | 5 +++++ modules/pubmatic/openwrap/database/mysql/slot_mapping.go | 6 ++++++ modules/pubmatic/openwrap/database/mysql/vasttags.go | 6 ++++++ 8 files changed, 42 insertions(+) diff --git a/modules/pubmatic/openwrap/database/mysql/app_integration_path.go b/modules/pubmatic/openwrap/database/mysql/app_integration_path.go index 89be33e6edf..632181371bd 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_integration_path.go +++ b/modules/pubmatic/openwrap/database/mysql/app_integration_path.go @@ -27,5 +27,10 @@ func (db *mySqlDB) GetAppIntegrationPaths() (map[string]int, error) { } appIntegrationPathMap[aipKey] = aipValue } + + if err = rows.Err(); err != nil { + glog.Errorf("AppIntegrationPathMapQuery row scan failed") + } + return appIntegrationPathMap, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path.go b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path.go index f611633220b..b26f98d3e5d 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path.go +++ b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path.go @@ -27,5 +27,10 @@ func (db *mySqlDB) GetAppSubIntegrationPaths() (map[string]int, error) { } appSubIntegrationPathMap[asipKey] = asipValue } + + if err = rows.Err(); err != nil { + glog.Errorf("AppSubIntegrationPathMapQuery row scan failed") + } + return appSubIntegrationPathMap, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go index 05999d60f67..a3a67cab18a 100644 --- a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go +++ b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go @@ -34,5 +34,10 @@ func (db *mySqlDB) GetFSCThresholdPerDSP() (map[int]int, error) { } fscDspThresholds[dspId] = pcnt } + + if err = rows.Err(); err != nil { + glog.Errorf("AllDspFscPcntQuery row scan failed") + } + return fscDspThresholds, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index afe9aeafdf3..b0d0dc01319 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -99,5 +99,10 @@ func (db *mySqlDB) getVersionIdAndProfileDetails(profileID, displayVersion, pubI if err != nil { return versionID, displayVersionIDFromDB, platform.String, profileType, err } + + if err = row.Err(); err != nil { + glog.Errorf("LiveVersionInnerQuery, DisplayVersionInnerQuery row scan failed for pubID %d", pubID) + } + return versionID, displayVersionIDFromDB, platform.String, profileType, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/profile_type_platform.go b/modules/pubmatic/openwrap/database/mysql/profile_type_platform.go index 2584d368a38..9330bb18725 100644 --- a/modules/pubmatic/openwrap/database/mysql/profile_type_platform.go +++ b/modules/pubmatic/openwrap/database/mysql/profile_type_platform.go @@ -27,5 +27,10 @@ func (db *mySqlDB) GetProfileTypePlatforms() (map[string]int, error) { } profileTypePlatformMap[ptpKey] = ptpValue } + + if err = rows.Err(); err != nil { + glog.Errorf("ProfileTypePlatformMapQuery row scan failed") + } + return profileTypePlatformMap, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/publisher_feature.go b/modules/pubmatic/openwrap/database/mysql/publisher_feature.go index a5c20f9568e..42614322238 100644 --- a/modules/pubmatic/openwrap/database/mysql/publisher_feature.go +++ b/modules/pubmatic/openwrap/database/mysql/publisher_feature.go @@ -35,5 +35,10 @@ func (db *mySqlDB) GetPublisherFeatureMap() (map[int]map[int]models.FeatureData, Value: value.String, } } + + if err = rows.Err(); err != nil { + glog.Errorf("PublisherFeatureMapQuery row scan failed") + } + return publisherFeatureMap, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go index 0cbf4f26a09..1a7b0b0f5ae 100644 --- a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go +++ b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -67,6 +68,11 @@ func (db *mySqlDB) GetWrapperSlotMappings(partnerConfigMap map[int]map[string]st } } + + if err = rows.Err(); err != nil { + glog.Errorf("SlotNameHash row scan failed for pubID %d", pubID) + } + //vastTagHookPartnerSlotMapping(partnerSlotMappingMap, profileId, displayVersion) return partnerSlotMappingMap, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/vasttags.go b/modules/pubmatic/openwrap/database/mysql/vasttags.go index 380bcdada32..dacfd548d2c 100644 --- a/modules/pubmatic/openwrap/database/mysql/vasttags.go +++ b/modules/pubmatic/openwrap/database/mysql/vasttags.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -28,5 +29,10 @@ func (db *mySqlDB) GetPublisherVASTTags(pubID int) (models.PublisherVASTTags, er vasttags[vastTag.ID] = &vastTag } } + + if err = rows.Err(); err != nil { + glog.Errorf("PublisherVASTTags row scan failed for pubID %d", pubID) + } + return vasttags, nil } From de78de30941264251d1ea650b7790b4601a396f4 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Fri, 4 Oct 2024 17:06:01 +0530 Subject: [PATCH 02/16] resolved error --- modules/pubmatic/openwrap/database/mysql/slot_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go index 1a7b0b0f5ae..7666b1ab03c 100644 --- a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go +++ b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go @@ -35,6 +35,10 @@ func (db *mySqlDB) GetPublisherSlotNameHash(pubID int) (map[string]string, error nameHashMap[name] = hash } + if err = rows.Err(); err != nil { + glog.Errorf("SlotNameHash row scan failed for pubID %d", pubID) + } + //vastTagHookPublisherSlotName(nameHashMap, pubID) return nameHashMap, nil } @@ -70,7 +74,7 @@ func (db *mySqlDB) GetWrapperSlotMappings(partnerConfigMap map[int]map[string]st } if err = rows.Err(); err != nil { - glog.Errorf("SlotNameHash row scan failed for pubID %d", pubID) + glog.Errorf("WrapperSlotMappingsQuery/WrapperLiveVersionSlotMappings row scan failed for profileID %d", profileID) } //vastTagHookPartnerSlotMapping(partnerSlotMappingMap, profileId, displayVersion) From 98ae508e423e31dc99770d3a122cfc9e19e93943 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Thu, 10 Oct 2024 13:35:36 +0530 Subject: [PATCH 03/16] added glog at cache level --- modules/pubmatic/openwrap/cache/gocache/adunit_config.go | 2 ++ .../pubmatic/openwrap/cache/gocache/app_integration_path.go | 2 ++ .../openwrap/cache/gocache/app_sub_integartion_path.go | 2 ++ .../pubmatic/openwrap/cache/gocache/fullscreenclickability.go | 2 ++ modules/pubmatic/openwrap/cache/gocache/partner_config.go | 2 ++ .../pubmatic/openwrap/cache/gocache/profile_type_platform.go | 2 ++ modules/pubmatic/openwrap/cache/gocache/publisher_feature.go | 2 ++ modules/pubmatic/openwrap/cache/gocache/slot_mappings.go | 4 ++++ modules/pubmatic/openwrap/cache/gocache/vast_tags.go | 2 ++ .../pubmatic/openwrap/database/mysql/app_integration_path.go | 2 +- .../openwrap/database/mysql/app_sub_integration_path.go | 2 +- .../openwrap/database/mysql/fullscreenclickability.go | 2 +- modules/pubmatic/openwrap/database/mysql/partner_config.go | 2 +- .../pubmatic/openwrap/database/mysql/profile_type_platform.go | 2 +- modules/pubmatic/openwrap/database/mysql/publisher_feature.go | 2 +- modules/pubmatic/openwrap/database/mysql/slot_mapping.go | 2 +- modules/pubmatic/openwrap/database/mysql/vasttags.go | 3 +-- 17 files changed, 28 insertions(+), 9 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go index 07bbd5450c9..b8693a8659d 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go @@ -3,6 +3,7 @@ package gocache import ( "strings" + "github.com/golang/glog" "github.com/prebid/openrtb/v20/openrtb2" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adunitconfig" ) @@ -10,6 +11,7 @@ import ( func (c *cache) populateCacheWithAdunitConfig(pubID int, profileID, displayVersion int) (err error) { adunitConfig, err := c.db.GetAdunitConfig(profileID, displayVersion) if err != nil { + glog.Errorf("[PartialQueryFailure] for adunitConfigQuery with err: %v", err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go b/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go index 5e452d13b27..d44ae4b2f61 100644 --- a/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go +++ b/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go @@ -3,6 +3,7 @@ package gocache import ( "fmt" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -13,6 +14,7 @@ func (c *cache) GetAppIntegrationPaths() (map[string]int, error) { appIntegrationPathMap, err := c.db.GetAppIntegrationPaths() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AppIntegrationPathMapQuery, "", "") + glog.Errorf("[PartialQueryFailure] for AppIntegrationPathMapQuery with err: %v", err) return appIntegrationPathMap, fmt.Errorf(errorAppIntegrationPathMapUpdate, err) } return appIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go b/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go index fdde2ae0805..dd6574c29f8 100644 --- a/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go +++ b/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go @@ -3,6 +3,7 @@ package gocache import ( "fmt" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -13,6 +14,7 @@ func (c *cache) GetAppSubIntegrationPaths() (map[string]int, error) { appSubIntegrationPathMap, err := c.db.GetAppSubIntegrationPaths() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AppSubIntegrationPathMapQuery, "", "") + glog.Errorf("[PartialQueryFailure] for AppSubIntegrationPathMapQuery with err: %v", err) return appSubIntegrationPathMap, fmt.Errorf(errorAppSubIntegrationPathMapUpdate, err) } return appSubIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go b/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go index 4e8fd798083..a0d3a872f40 100644 --- a/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go +++ b/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go @@ -3,6 +3,7 @@ package gocache import ( "fmt" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -15,6 +16,7 @@ func (c *cache) GetFSCThresholdPerDSP() (map[int]int, error) { fscThreshold, err := c.db.GetFSCThresholdPerDSP() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AllDspFscPcntQuery, "", "") + glog.Errorf("[PartialQueryFailure] for AllDspFscPcntQuery with err: %v", err) return fscThreshold, fmt.Errorf(errorFscDspMsg, err) } return fscThreshold, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/partner_config.go b/modules/pubmatic/openwrap/cache/gocache/partner_config.go index 6ca2ea02c49..e25ff70244b 100644 --- a/modules/pubmatic/openwrap/cache/gocache/partner_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/partner_config.go @@ -6,6 +6,7 @@ import ( "strconv" "time" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adunitconfig" ) @@ -68,6 +69,7 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI partnerConfigMap, err := c.db.GetActivePartnerConfigurations(pubID, profileID, displayVersion) if err != nil { c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) + glog.Errorf("[PartialQueryFailure] for GetParterConfigQuery with err: %v", err) return } diff --git a/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go b/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go index ad912e430d2..f4b798ed72c 100644 --- a/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go +++ b/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go @@ -3,6 +3,7 @@ package gocache import ( "fmt" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -13,6 +14,7 @@ func (c *cache) GetProfileTypePlatforms() (map[string]int, error) { profileTypePlatformMap, err := c.db.GetProfileTypePlatforms() if err != nil { c.metricEngine.RecordDBQueryFailure(models.ProfileTypePlatformMapQuery, "", "") + glog.Errorf("[PartialQueryFailure] for ProfileTypePlatformMapQuery with err: %v", err) return profileTypePlatformMap, fmt.Errorf(errorProfileTypePlatformMapUpdate, err) } return profileTypePlatformMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go b/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go index c27ac7d9214..058f129b34e 100644 --- a/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go +++ b/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go @@ -3,6 +3,7 @@ package gocache import ( "fmt" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -13,6 +14,7 @@ func (c *cache) GetPublisherFeatureMap() (map[int]map[int]models.FeatureData, er publisherFeatureMap, err := c.db.GetPublisherFeatureMap() if err != nil { c.metricEngine.RecordDBQueryFailure(models.PublisherFeatureMapQuery, "", "") + glog.Errorf("[PartialQueryFailure] for PublisherFeatureMapQuery with err: %v", err) return publisherFeatureMap, fmt.Errorf(errorPubFeatureUpdate, err) } return publisherFeatureMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go index b25246a7937..09ac3335cc7 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" "github.com/prebid/prebid-server/v2/openrtb_ext" ) @@ -23,6 +24,9 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { // PopulateCacheWithWrapperSlotMappings will get the SlotMappings from database and put them in cache. func (c *cache) populateCacheWithWrapperSlotMappings(pubID int, partnerConfigMap map[int]map[string]string, profileID, displayVersion int) error { partnerSlotMappingMap, err := c.db.GetWrapperSlotMappings(partnerConfigMap, profileID, displayVersion) + if err != nil { + glog.Errorf("[PartialQueryFailure] for WrapperSlotMappingsQuery/WrapperLiveVersionSlotMappings with err: %v", err) + } //put a version level dummy entry in cache denoting mappings are present for this version cacheKey := key(PUB_SLOT_INFO, pubID, profileID, displayVersion, 0) diff --git a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go index 8f2137a03ec..6ee91cf8e68 100644 --- a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go +++ b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go @@ -1,6 +1,7 @@ package gocache import ( + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -11,6 +12,7 @@ func (c *cache) populatePublisherVASTTags(pubID int) error { //get publisher level vast tag details from DB publisherVASTTags, err := c.db.GetPublisherVASTTags(pubID) if err != nil { + glog.Errorf("[PartialQueryFailure] for PublisherVASTTags with err: %v", err) return err } diff --git a/modules/pubmatic/openwrap/database/mysql/app_integration_path.go b/modules/pubmatic/openwrap/database/mysql/app_integration_path.go index 632181371bd..ae5dfece9f0 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_integration_path.go +++ b/modules/pubmatic/openwrap/database/mysql/app_integration_path.go @@ -29,7 +29,7 @@ func (db *mySqlDB) GetAppIntegrationPaths() (map[string]int, error) { } if err = rows.Err(); err != nil { - glog.Errorf("AppIntegrationPathMapQuery row scan failed") + return nil, err } return appIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path.go b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path.go index b26f98d3e5d..bc324ae9d9e 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path.go +++ b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path.go @@ -29,7 +29,7 @@ func (db *mySqlDB) GetAppSubIntegrationPaths() (map[string]int, error) { } if err = rows.Err(); err != nil { - glog.Errorf("AppSubIntegrationPathMapQuery row scan failed") + return nil, err } return appSubIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go index a3a67cab18a..48bc4cb2c58 100644 --- a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go +++ b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go @@ -36,7 +36,7 @@ func (db *mySqlDB) GetFSCThresholdPerDSP() (map[int]int, error) { } if err = rows.Err(); err != nil { - glog.Errorf("AllDspFscPcntQuery row scan failed") + return nil, err } return fscDspThresholds, nil diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index b0d0dc01319..b896e4d36b0 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -79,7 +79,7 @@ func (db *mySqlDB) getActivePartnerConfigurations(profileID, versionID int) (map // NYC_TODO: ignore close error if err = rows.Err(); err != nil { - glog.Errorf("partner config row scan failed for versionID %d", versionID) + return nil, err } return partnerConfigMap, nil } diff --git a/modules/pubmatic/openwrap/database/mysql/profile_type_platform.go b/modules/pubmatic/openwrap/database/mysql/profile_type_platform.go index 9330bb18725..524d4016fdc 100644 --- a/modules/pubmatic/openwrap/database/mysql/profile_type_platform.go +++ b/modules/pubmatic/openwrap/database/mysql/profile_type_platform.go @@ -29,7 +29,7 @@ func (db *mySqlDB) GetProfileTypePlatforms() (map[string]int, error) { } if err = rows.Err(); err != nil { - glog.Errorf("ProfileTypePlatformMapQuery row scan failed") + return nil, err } return profileTypePlatformMap, nil diff --git a/modules/pubmatic/openwrap/database/mysql/publisher_feature.go b/modules/pubmatic/openwrap/database/mysql/publisher_feature.go index 42614322238..c2bc3367afa 100644 --- a/modules/pubmatic/openwrap/database/mysql/publisher_feature.go +++ b/modules/pubmatic/openwrap/database/mysql/publisher_feature.go @@ -37,7 +37,7 @@ func (db *mySqlDB) GetPublisherFeatureMap() (map[int]map[int]models.FeatureData, } if err = rows.Err(); err != nil { - glog.Errorf("PublisherFeatureMapQuery row scan failed") + return nil, err } return publisherFeatureMap, nil diff --git a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go index 7666b1ab03c..c055473e881 100644 --- a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go +++ b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go @@ -74,7 +74,7 @@ func (db *mySqlDB) GetWrapperSlotMappings(partnerConfigMap map[int]map[string]st } if err = rows.Err(); err != nil { - glog.Errorf("WrapperSlotMappingsQuery/WrapperLiveVersionSlotMappings row scan failed for profileID %d", profileID) + return nil, err } //vastTagHookPartnerSlotMapping(partnerSlotMappingMap, profileId, displayVersion) diff --git a/modules/pubmatic/openwrap/database/mysql/vasttags.go b/modules/pubmatic/openwrap/database/mysql/vasttags.go index dacfd548d2c..98b100c9b96 100644 --- a/modules/pubmatic/openwrap/database/mysql/vasttags.go +++ b/modules/pubmatic/openwrap/database/mysql/vasttags.go @@ -5,7 +5,6 @@ import ( "fmt" "time" - "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -31,7 +30,7 @@ func (db *mySqlDB) GetPublisherVASTTags(pubID int) (models.PublisherVASTTags, er } if err = rows.Err(); err != nil { - glog.Errorf("PublisherVASTTags row scan failed for pubID %d", pubID) + return nil, err } return vasttags, nil From 5187ff023c1690fe8890a94640d761d6cdd2c884 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Mon, 21 Oct 2024 16:47:04 +0530 Subject: [PATCH 04/16] added glog --- modules/pubmatic/openwrap/cache/gocache/adpod_config.go | 2 ++ modules/pubmatic/openwrap/cache/gocache/partner_config.go | 2 +- modules/pubmatic/openwrap/cache/gocache/slot_mappings.go | 4 ++++ modules/pubmatic/openwrap/database/mysql/adpod_config.go | 3 +-- modules/pubmatic/openwrap/database/mysql/partner_config.go | 3 +-- modules/pubmatic/openwrap/database/mysql/slot_mapping.go | 3 +-- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go index b1233d4fd4f..c0d8bc920f8 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go @@ -3,6 +3,7 @@ package gocache import ( "strconv" + "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adpodconfig" ) @@ -10,6 +11,7 @@ import ( func (c *cache) populateCacheWithAdpodConfig(pubID, profileID, displayVersion int) (err error) { adpodConfig, err := c.db.GetAdpodConfig(pubID, profileID, displayVersion) if err != nil { + glog.Errorf("[PartialQueryFailure] for LiveVersionInnerQuery/DisplayVersionInnerQuery with err: %v", err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/partner_config.go b/modules/pubmatic/openwrap/cache/gocache/partner_config.go index e25ff70244b..f58c96d95d1 100644 --- a/modules/pubmatic/openwrap/cache/gocache/partner_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/partner_config.go @@ -70,7 +70,7 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI if err != nil { c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) glog.Errorf("[PartialQueryFailure] for GetParterConfigQuery with err: %v", err) - return + return err } if len(partnerConfigMap) == 0 { diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go index 09ac3335cc7..1e4bd2d3dfe 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go @@ -16,6 +16,10 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { cacheKey := key(PubSlotNameHash, pubID) publisherSlotNameHashMap, err := c.db.GetPublisherSlotNameHash(pubID) + if err != nil { + glog.Errorf("[PartialQueryFailure] for GetSlotNameHash with err: %v", err) + return err + } //This call may set nil publisherSlotNameHashMap in cache c.cache.Set(cacheKey, publisherSlotNameHashMap, getSeconds(c.cfg.CacheDefaultExpiry)) return diff --git a/modules/pubmatic/openwrap/database/mysql/adpod_config.go b/modules/pubmatic/openwrap/database/mysql/adpod_config.go index ea25a0246c7..484805e25af 100644 --- a/modules/pubmatic/openwrap/database/mysql/adpod_config.go +++ b/modules/pubmatic/openwrap/database/mysql/adpod_config.go @@ -6,7 +6,6 @@ import ( "strings" "time" - "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adpodconfig" ) @@ -54,7 +53,7 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc } if err = rows.Err(); err != nil { - glog.Errorf("adpod config row scan failed for publisher %d having profile %d with versionID %d", pubID, profileID, displayVersion) + return nil, err } return config, nil diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index b896e4d36b0..b47b270dfa5 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -7,7 +7,6 @@ import ( "strconv" "time" - "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -101,7 +100,7 @@ func (db *mySqlDB) getVersionIdAndProfileDetails(profileID, displayVersion, pubI } if err = row.Err(); err != nil { - glog.Errorf("LiveVersionInnerQuery, DisplayVersionInnerQuery row scan failed for pubID %d", pubID) + return versionID, displayVersionIDFromDB, platform.String, profileType, err } return versionID, displayVersionIDFromDB, platform.String, profileType, nil diff --git a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go index c055473e881..4e5f79b2d2d 100644 --- a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go +++ b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -36,7 +35,7 @@ func (db *mySqlDB) GetPublisherSlotNameHash(pubID int) (map[string]string, error } if err = rows.Err(); err != nil { - glog.Errorf("SlotNameHash row scan failed for pubID %d", pubID) + return nil, err } //vastTagHookPublisherSlotName(nameHashMap, pubID) From dbf22982a2f9389e4c857283d6ed0319feaa619a Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Tue, 22 Oct 2024 16:46:59 +0530 Subject: [PATCH 05/16] resolved all comments --- .../openwrap/cache/gocache/adpod_config.go | 2 +- .../openwrap/cache/gocache/adunit_config.go | 2 +- .../cache/gocache/app_integration_path.go | 2 +- .../cache/gocache/app_sub_integartion_path.go | 2 +- .../cache/gocache/fullscreenclickability.go | 2 +- .../openwrap/cache/gocache/partner_config.go | 2 +- .../cache/gocache/profile_type_platform.go | 2 +- .../cache/gocache/publisher_feature.go | 2 +- .../openwrap/cache/gocache/slot_mappings.go | 4 +- .../openwrap/cache/gocache/vast_tags.go | 2 +- .../mysql/app_integration_path_test.go | 26 ++++++++ .../mysql/app_sub_integration_path_test.go | 26 ++++++++ .../mysql/fullscreenclickability_test.go | 27 ++++++++ .../database/mysql/partner_config_test.go | 31 +++++++++- .../mysql/profile_type_platform_test.go | 26 ++++++++ .../database/mysql/publisher_feature_test.go | 28 ++++++++- .../database/mysql/slot_mapping_test.go | 61 ++++++++++++++++++- .../openwrap/database/mysql/vasttags_test.go | 30 +++++++++ 18 files changed, 261 insertions(+), 16 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go index c0d8bc920f8..060fd94536d 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go @@ -11,7 +11,7 @@ import ( func (c *cache) populateCacheWithAdpodConfig(pubID, profileID, displayVersion int) (err error) { adpodConfig, err := c.db.GetAdpodConfig(pubID, profileID, displayVersion) if err != nil { - glog.Errorf("[PartialQueryFailure] for LiveVersionInnerQuery/DisplayVersionInnerQuery with err: %v", err) + glog.Errorf("[QueryFailure] for LiveVersionInnerQuery/DisplayVersionInnerQuery with err: %v", err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go index b8693a8659d..38b21b84078 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go @@ -11,7 +11,7 @@ import ( func (c *cache) populateCacheWithAdunitConfig(pubID int, profileID, displayVersion int) (err error) { adunitConfig, err := c.db.GetAdunitConfig(profileID, displayVersion) if err != nil { - glog.Errorf("[PartialQueryFailure] for adunitConfigQuery with err: %v", err) + glog.Errorf("[QueryFailure] for adunitConfigQuery with err: %v", err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go b/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go index d44ae4b2f61..aff0f157862 100644 --- a/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go +++ b/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go @@ -14,7 +14,7 @@ func (c *cache) GetAppIntegrationPaths() (map[string]int, error) { appIntegrationPathMap, err := c.db.GetAppIntegrationPaths() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AppIntegrationPathMapQuery, "", "") - glog.Errorf("[PartialQueryFailure] for AppIntegrationPathMapQuery with err: %v", err) + glog.Errorf("[QueryFailure] for AppIntegrationPathMapQuery with err: %v", err) return appIntegrationPathMap, fmt.Errorf(errorAppIntegrationPathMapUpdate, err) } return appIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go b/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go index dd6574c29f8..53e2eb73241 100644 --- a/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go +++ b/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go @@ -14,7 +14,7 @@ func (c *cache) GetAppSubIntegrationPaths() (map[string]int, error) { appSubIntegrationPathMap, err := c.db.GetAppSubIntegrationPaths() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AppSubIntegrationPathMapQuery, "", "") - glog.Errorf("[PartialQueryFailure] for AppSubIntegrationPathMapQuery with err: %v", err) + glog.Errorf("[QueryFailure] for AppSubIntegrationPathMapQuery with err: %v", err) return appSubIntegrationPathMap, fmt.Errorf(errorAppSubIntegrationPathMapUpdate, err) } return appSubIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go b/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go index a0d3a872f40..a62bf569c04 100644 --- a/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go +++ b/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go @@ -16,7 +16,7 @@ func (c *cache) GetFSCThresholdPerDSP() (map[int]int, error) { fscThreshold, err := c.db.GetFSCThresholdPerDSP() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AllDspFscPcntQuery, "", "") - glog.Errorf("[PartialQueryFailure] for AllDspFscPcntQuery with err: %v", err) + glog.Errorf("[QueryFailure] for AllDspFscPcntQuery with err: %v", err) return fscThreshold, fmt.Errorf(errorFscDspMsg, err) } return fscThreshold, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/partner_config.go b/modules/pubmatic/openwrap/cache/gocache/partner_config.go index f58c96d95d1..b2bf59aba38 100644 --- a/modules/pubmatic/openwrap/cache/gocache/partner_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/partner_config.go @@ -69,7 +69,7 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI partnerConfigMap, err := c.db.GetActivePartnerConfigurations(pubID, profileID, displayVersion) if err != nil { c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) - glog.Errorf("[PartialQueryFailure] for GetParterConfigQuery with err: %v", err) + glog.Errorf("[QueryFailure] for GetParterConfigQuery with err: %v", err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go b/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go index f4b798ed72c..05b5ba11692 100644 --- a/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go +++ b/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go @@ -14,7 +14,7 @@ func (c *cache) GetProfileTypePlatforms() (map[string]int, error) { profileTypePlatformMap, err := c.db.GetProfileTypePlatforms() if err != nil { c.metricEngine.RecordDBQueryFailure(models.ProfileTypePlatformMapQuery, "", "") - glog.Errorf("[PartialQueryFailure] for ProfileTypePlatformMapQuery with err: %v", err) + glog.Errorf("[QueryFailure] for ProfileTypePlatformMapQuery with err: %v", err) return profileTypePlatformMap, fmt.Errorf(errorProfileTypePlatformMapUpdate, err) } return profileTypePlatformMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go b/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go index 058f129b34e..9d0d0a48699 100644 --- a/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go +++ b/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go @@ -14,7 +14,7 @@ func (c *cache) GetPublisherFeatureMap() (map[int]map[int]models.FeatureData, er publisherFeatureMap, err := c.db.GetPublisherFeatureMap() if err != nil { c.metricEngine.RecordDBQueryFailure(models.PublisherFeatureMapQuery, "", "") - glog.Errorf("[PartialQueryFailure] for PublisherFeatureMapQuery with err: %v", err) + glog.Errorf("[QueryFailure] for PublisherFeatureMapQuery with err: %v", err) return publisherFeatureMap, fmt.Errorf(errorPubFeatureUpdate, err) } return publisherFeatureMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go index 1e4bd2d3dfe..239640ef176 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go @@ -17,7 +17,7 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { publisherSlotNameHashMap, err := c.db.GetPublisherSlotNameHash(pubID) if err != nil { - glog.Errorf("[PartialQueryFailure] for GetSlotNameHash with err: %v", err) + glog.Errorf("[QueryFailure] for GetSlotNameHash with err: %v", err) return err } //This call may set nil publisherSlotNameHashMap in cache @@ -29,7 +29,7 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { func (c *cache) populateCacheWithWrapperSlotMappings(pubID int, partnerConfigMap map[int]map[string]string, profileID, displayVersion int) error { partnerSlotMappingMap, err := c.db.GetWrapperSlotMappings(partnerConfigMap, profileID, displayVersion) if err != nil { - glog.Errorf("[PartialQueryFailure] for WrapperSlotMappingsQuery/WrapperLiveVersionSlotMappings with err: %v", err) + glog.Errorf("[QueryFailure] for WrapperSlotMappingsQuery/WrapperLiveVersionSlotMappings with err: %v", err) } //put a version level dummy entry in cache denoting mappings are present for this version diff --git a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go index 6ee91cf8e68..b5020fec14b 100644 --- a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go +++ b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go @@ -12,7 +12,7 @@ func (c *cache) populatePublisherVASTTags(pubID int) error { //get publisher level vast tag details from DB publisherVASTTags, err := c.db.GetPublisherVASTTags(pubID) if err != nil { - glog.Errorf("[PartialQueryFailure] for PublisherVASTTags with err: %v", err) + glog.Errorf("[QueryFailure] for PublisherVASTTags with err: %v", err) return err } diff --git a/modules/pubmatic/openwrap/database/mysql/app_integration_path_test.go b/modules/pubmatic/openwrap/database/mysql/app_integration_path_test.go index 725ba89cf9b..61f91eb8f3b 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_integration_path_test.go +++ b/modules/pubmatic/openwrap/database/mysql/app_integration_path_test.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "errors" "regexp" "testing" @@ -114,6 +115,31 @@ func Test_mySqlDB_GetAppIntegrationPath(t *testing.T) { return db }, }, + { + name: "error in row scan", + fields: fields{ + cfg: config.Database{ + MaxDbContextTimeout: 100, + Queries: config.Queries{ + GetAppIntegrationPathMapQuery: "^SELECT (.+) FROM app_integration_path (.+)", + }, + }, + }, + want: map[string]int(nil), + wantErr: true, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"name", "id"}). + AddRow(`test1`, `1`). + AddRow(`test2`, `2`) + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM app_integration_path (.+)")).WillReturnRows(rows) + return db + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go index d988615a43d..9418d1365cb 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go +++ b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "errors" "regexp" "testing" @@ -87,6 +88,31 @@ func Test_mySqlDB_GetAppSubIntegrationPath(t *testing.T) { return db }, }, + { + name: "error in row scan", + fields: fields{ + cfg: config.Database{ + MaxDbContextTimeout: 100, + Queries: config.Queries{ + GetAppSubIntegrationPathMapQuery: "^SELECT (.+) FROM app_sub_integration_path (.+)", + }, + }, + }, + want: map[string]int{}, + wantErr: false, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"name", "id"}). + AddRow(`test_sub_1`, `1,3`). + AddRow(`test_sub_2`, `2`) + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM app_sub_integration_path (.+)")).WillReturnRows(rows) + return db + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go index 811494e6f23..772afe79a45 100644 --- a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go +++ b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "errors" "regexp" "testing" @@ -83,6 +84,32 @@ func Test_mySqlDB_GetFSCThresholdPerDSP(t *testing.T) { return db }, }, + { + name: "error in row scan", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + GetAllDspFscPcntQuery: "^SELECT (.+) FROM wrapper_feature_dsp_mapping (.+)", + }, + MaxDbContextTimeout: 1000, + }, + }, + want: map[int]int(nil), + wantErr: true, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"dsp_id", "value"}). + AddRow(`5`, `24`). + AddRow(`8`, `20`). + AddRow(`9`, `12.12`) + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_feature_dsp_mapping (.+)")).WillReturnRows(rows) + return db + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go index 3768b1cf07a..9c115c8b692 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "errors" "regexp" "testing" @@ -515,7 +516,6 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { args: args{ versionID: 123, }, - want: map[int]map[string]string{ 101: { "accountId": "1234", @@ -608,6 +608,35 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { return db }, }, + { + name: "error in row scan", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + GetParterConfig: models.TestQuery, + }, + MaxDbContextTimeout: 1000, + }, + }, + args: args{ + versionID: 123, + }, + want: map[int]map[string]string(nil), + wantErr: true, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}). + AddRow(101, "openx", "openx", 0, -1, 0, 152, "k1", "v1"). + AddRow(101, "openx", "openx", 0, -1, 0, 152, "k2", "v2"). + AddRow(102, "pubmatic", "pubmatic", 0, -1, 0, 76, "k1", "v2") + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WillReturnRows(rows) + return db + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/modules/pubmatic/openwrap/database/mysql/profile_type_platform_test.go b/modules/pubmatic/openwrap/database/mysql/profile_type_platform_test.go index 43ee19c0e88..866cd68c687 100644 --- a/modules/pubmatic/openwrap/database/mysql/profile_type_platform_test.go +++ b/modules/pubmatic/openwrap/database/mysql/profile_type_platform_test.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "errors" "regexp" "testing" @@ -114,6 +115,31 @@ func Test_mySqlDB_GetProfileTypePlatform(t *testing.T) { return db }, }, + { + name: "error in row scan", + fields: fields{ + cfg: config.Database{ + MaxDbContextTimeout: 100, + Queries: config.Queries{ + GetProfileTypePlatformMapQuery: "^SELECT (.+) FROM profile_type_platform (.+)", + }, + }, + }, + want: map[string]int(nil), + wantErr: true, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"name", "id"}). + AddRow(`test1`, `1`). + AddRow(`test2`, `2`) + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM profile_type_platform (.+)")).WillReturnRows(rows) + return db + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go b/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go index fa13d09e01f..131336ca00d 100644 --- a/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go +++ b/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "errors" "regexp" "testing" @@ -111,12 +112,37 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } - rows := sqlmock.NewRows([]string{"pub_id", "feature_id", "is_enabled", "value"}) mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM test_wrapper_table (.+)")).WillReturnRows(rows) return db }, }, + { + name: "error in row scan", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + GetPublisherFeatureMapQuery: "^SELECT (.+) FROM test_wrapper_table (.+)", + }, + MaxDbContextTimeout: 1000, + }, + }, + want: map[int]map[int]models.FeatureData(nil), + wantErr: true, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"pub_id", "feature_id", "is_enabled", "value"}). + AddRow(`5890`, `1`, `0`, sql.NullString{}). + AddRow(`5890`, `2`, `1`, `{"1234": 100}`). + AddRow(`5890`, `3`, `1`, sql.NullString{}) + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM test_wrapper_table (.+)")).WillReturnRows(rows) + return db + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go b/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go index 68c48566481..791fddfbea6 100644 --- a/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go +++ b/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "errors" "regexp" "testing" @@ -67,7 +68,6 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { AddRow("/43743431/DMDemo1@160x600", "2fb84286ede5b20e82b0601df0c7e454"). AddRow("/43743431/DMDemo2@160x600", "2aa34b52a9e941c1594af7565e599c8d") mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_publisher_slot (.+)")).WillReturnRows(rows) - return db }, }, @@ -98,6 +98,34 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { AddRow("/43743431/DMDemo1@160x600", "2fb84286ede5b20e82b0601df0c7e454"). AddRow("/43743431/DMDemo2@160x600", "2aa34b52a9e941c1594af7565e599c8d") mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_publisher_slot (.+)")).WillReturnRows(rows) + return db + }, + }, + { + name: "error in row scan", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + GetSlotNameHash: "^SELECT (.+) FROM wrapper_publisher_slot (.+)", + }, + MaxDbContextTimeout: 1000, + }, + }, + args: args{ + pubID: 5890, + }, + want: map[string]string(nil), + wantErr: true, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"name", "hash"}). + AddRow("/43743431/DMDemo1@160x600", "2fb84286ede5b20e82b0601df0c7e454"). + AddRow("/43743431/DMDemo2@160x600", "2aa34b52a9e941c1594af7565e599c8d") + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_publisher_slot (.+)")).WillReturnRows(rows) return db }, @@ -186,7 +214,6 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { AddRow("10_112", 1, 1, "/43743431/DMDemo1@160x600", "{\"adtag\":\"1405192\",\"site\":\"47124\"}", 0). AddRow(10, 1, 1, "/43743431/DMDemo2@160x600", "{\"adtag\":\"1405192\",\"site\":\"47124\"}", 0) mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_partner_slot_mapping (.+) LIVE")).WillReturnRows(rows) - return db }, }, @@ -238,7 +265,6 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { AddRow(10, 1, 1, "/43743431/DMDemo1@160x600", "{\"adtag\":\"1405192\",\"site\":\"47124\"}", 0). AddRow(10, 1, 1, "/43743431/DMDemo2@160x600", "{\"adtag\":\"1405192\",\"site\":\"47124\"}", 0) mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_partner_slot_mapping (.+) LIVE")).WillReturnRows(rows) - return db }, }, @@ -290,6 +316,35 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { AddRow(10, 1, 1, "/43743431/DMDemo1@160x600", "{\"adtag\":\"1405192\",\"site\":\"47124\"}", 0). AddRow(10, 1, 1, "/43743431/DMDemo2@160x600", "{\"adtag\":\"1405192\",\"site\":\"47124\"}", 0) mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_partner_slot_mapping (.+)")).WillReturnRows(rows) + return db + }, + }, + { + name: "error in row scan with displayversion 0", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + GetWrapperLiveVersionSlotMappings: "^SELECT (.+) FROM wrapper_partner_slot_mapping (.+) LIVE", + }, + }, + }, + args: args{ + partnerConfigMap: formTestPartnerConfig(), + profileID: 19109, + displayVersion: 0, + }, + want: map[int][]models.SlotMapping(nil), + wantErr: true, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"PartnerId", "AdapterId", "VersionId", "SlotName", "MappingJson", "OrderId"}). + AddRow(10, 1, 1, "/43743431/DMDemo1@160x600", "{\"adtag\":\"1405192\",\"site\":\"47124\"}", 0). + AddRow(10, 1, 1, "/43743431/DMDemo2@160x600", "{\"adtag\":\"1405192\",\"site\":\"47124\"}", 0) + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_partner_slot_mapping (.+) LIVE")).WillReturnRows(rows) return db }, diff --git a/modules/pubmatic/openwrap/database/mysql/vasttags_test.go b/modules/pubmatic/openwrap/database/mysql/vasttags_test.go index 1709cd9ff93..d4564eb210d 100644 --- a/modules/pubmatic/openwrap/database/mysql/vasttags_test.go +++ b/modules/pubmatic/openwrap/database/mysql/vasttags_test.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "errors" "regexp" "testing" @@ -101,6 +102,35 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { return db }, }, + { + name: "error in row scan", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + GetPublisherVASTTagsQuery: "^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)", + }, + MaxDbContextTimeout: 1000, + }, + }, + args: args{ + pubID: 5890, + }, + want: models.PublisherVASTTags(nil), + wantErr: true, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{"id", "partnerId", "url", "duration", "price"}). + AddRow(101, 501, "vast_tag_url_1", 15, 2.0). + AddRow(102, 502, "vast_tag_url_2", 10, 0.0). + AddRow(103, 501, "vast_tag_url_1", 30, 3.0) + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)")).WillReturnRows(rows) + return db + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 81f382fed55b71aea2b0e4e4cf4655830f04a5a6 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Thu, 24 Oct 2024 11:50:12 +0530 Subject: [PATCH 06/16] fixed UT --- .../openwrap/cache/gocache/slot_mappings_test.go | 10 +++++++--- .../database/mysql/app_sub_integration_path_test.go | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go index 037cffbbb64..2972b823a68 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go @@ -41,8 +41,9 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) { pubid int } type want struct { - publisherSlotNameHashMap map[string]string + publisherSlotNameHashMap interface{} err error + foundCacheKey bool } tests := []struct { name string @@ -69,6 +70,7 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) { want: want{ publisherSlotNameHashMap: nil, err: fmt.Errorf("Error from the DB"), + foundCacheKey: false, }, }, { @@ -93,6 +95,7 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) { publisherSlotNameHashMap: map[string]string{ testSlotName: testHashValue, }, + foundCacheKey: true, }, }, { @@ -111,8 +114,9 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) { mockDatabase.EXPECT().GetPublisherSlotNameHash(5890).Return(nil, nil) }, want: want{ - publisherSlotNameHashMap: nil, + publisherSlotNameHashMap: map[string]string(nil), err: nil, + foundCacheKey: true, }, }, } @@ -131,7 +135,7 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) { assert.Equal(t, tt.want.err, err) cacheKey := key(PubSlotNameHash, tt.args.pubid) publisherSlotNameHashMap, found := c.cache.Get(cacheKey) - assert.True(t, found) + assert.Equal(t, tt.want.foundCacheKey, found) assert.Equal(t, tt.want.publisherSlotNameHashMap, publisherSlotNameHashMap) }) } diff --git a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go index 9418d1365cb..bcb559dff8b 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go +++ b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go @@ -98,8 +98,8 @@ func Test_mySqlDB_GetAppSubIntegrationPath(t *testing.T) { }, }, }, - want: map[string]int{}, - wantErr: false, + want: map[string]int(nil), + wantErr: true, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { From 6af358e028b12522824b468a0569795f6feac39e Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Wed, 6 Nov 2024 16:02:53 +0530 Subject: [PATCH 07/16] resolved comments --- .../openwrap/cache/gocache/adpod_config.go | 2 +- .../openwrap/cache/gocache/adunit_config.go | 3 ++- .../cache/gocache/app_integration_path.go | 2 +- .../cache/gocache/app_sub_integartion_path.go | 2 +- .../cache/gocache/fullscreenclickability.go | 2 +- .../openwrap/cache/gocache/partner_config.go | 2 +- .../cache/gocache/profile_type_platform.go | 2 +- .../openwrap/cache/gocache/publisher_feature.go | 2 +- .../openwrap/cache/gocache/slot_mappings.go | 5 +++-- .../openwrap/cache/gocache/slot_mappings_test.go | 15 ++++++++++----- .../pubmatic/openwrap/cache/gocache/vast_tags.go | 2 +- modules/pubmatic/openwrap/models/constants.go | 2 ++ 12 files changed, 25 insertions(+), 16 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go index 060fd94536d..37e42292b09 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go @@ -11,7 +11,7 @@ import ( func (c *cache) populateCacheWithAdpodConfig(pubID, profileID, displayVersion int) (err error) { adpodConfig, err := c.db.GetAdpodConfig(pubID, profileID, displayVersion) if err != nil { - glog.Errorf("[QueryFailure] for LiveVersionInnerQuery/DisplayVersionInnerQuery with err: %v", err) + glog.Errorf(models.DBQueryFailure, "LiveVersionInnerQuery/DisplayVersionInnerQuery", pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go index 38b21b84078..9923e1e35de 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go @@ -5,13 +5,14 @@ import ( "github.com/golang/glog" "github.com/prebid/openrtb/v20/openrtb2" + "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adunitconfig" ) func (c *cache) populateCacheWithAdunitConfig(pubID int, profileID, displayVersion int) (err error) { adunitConfig, err := c.db.GetAdunitConfig(profileID, displayVersion) if err != nil { - glog.Errorf("[QueryFailure] for adunitConfigQuery with err: %v", err) + glog.Errorf(models.DBQueryFailure, "adunitConfigQuery", pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go b/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go index aff0f157862..4ae423b3dd1 100644 --- a/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go +++ b/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go @@ -14,7 +14,7 @@ func (c *cache) GetAppIntegrationPaths() (map[string]int, error) { appIntegrationPathMap, err := c.db.GetAppIntegrationPaths() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AppIntegrationPathMapQuery, "", "") - glog.Errorf("[QueryFailure] for AppIntegrationPathMapQuery with err: %v", err) + glog.Errorf("DBQueryFailure", err) return appIntegrationPathMap, fmt.Errorf(errorAppIntegrationPathMapUpdate, err) } return appIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go b/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go index 53e2eb73241..d710f94de29 100644 --- a/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go +++ b/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go @@ -14,7 +14,7 @@ func (c *cache) GetAppSubIntegrationPaths() (map[string]int, error) { appSubIntegrationPathMap, err := c.db.GetAppSubIntegrationPaths() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AppSubIntegrationPathMapQuery, "", "") - glog.Errorf("[QueryFailure] for AppSubIntegrationPathMapQuery with err: %v", err) + glog.Errorf(models.DBQueryFailure, "AppSubIntegrationPathMapQuery", "", "", err) return appSubIntegrationPathMap, fmt.Errorf(errorAppSubIntegrationPathMapUpdate, err) } return appSubIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go b/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go index a62bf569c04..05308e10776 100644 --- a/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go +++ b/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go @@ -16,7 +16,7 @@ func (c *cache) GetFSCThresholdPerDSP() (map[int]int, error) { fscThreshold, err := c.db.GetFSCThresholdPerDSP() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AllDspFscPcntQuery, "", "") - glog.Errorf("[QueryFailure] for AllDspFscPcntQuery with err: %v", err) + glog.Errorf(models.DBQueryFailure, "AllDspFscPcntQuery", "", "", err) return fscThreshold, fmt.Errorf(errorFscDspMsg, err) } return fscThreshold, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/partner_config.go b/modules/pubmatic/openwrap/cache/gocache/partner_config.go index 63f7a66e36d..412a2cbdf88 100644 --- a/modules/pubmatic/openwrap/cache/gocache/partner_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/partner_config.go @@ -69,7 +69,7 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI partnerConfigMap, err := c.db.GetActivePartnerConfigurations(pubID, profileID, displayVersion) if err != nil { c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) - glog.Errorf("[QueryFailure] for GetParterConfigQuery with err: %v", err) + glog.Errorf(models.DBQueryFailure, "GetParterConfigQuery", pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go b/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go index 05b5ba11692..0a4c2e04494 100644 --- a/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go +++ b/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go @@ -14,7 +14,7 @@ func (c *cache) GetProfileTypePlatforms() (map[string]int, error) { profileTypePlatformMap, err := c.db.GetProfileTypePlatforms() if err != nil { c.metricEngine.RecordDBQueryFailure(models.ProfileTypePlatformMapQuery, "", "") - glog.Errorf("[QueryFailure] for ProfileTypePlatformMapQuery with err: %v", err) + glog.Errorf(models.DBQueryFailure, "ProfileTypePlatformMapQuery", "", "", err) return profileTypePlatformMap, fmt.Errorf(errorProfileTypePlatformMapUpdate, err) } return profileTypePlatformMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go b/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go index 9d0d0a48699..d2f9ba4c7a8 100644 --- a/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go +++ b/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go @@ -14,7 +14,7 @@ func (c *cache) GetPublisherFeatureMap() (map[int]map[int]models.FeatureData, er publisherFeatureMap, err := c.db.GetPublisherFeatureMap() if err != nil { c.metricEngine.RecordDBQueryFailure(models.PublisherFeatureMapQuery, "", "") - glog.Errorf("[QueryFailure] for PublisherFeatureMapQuery with err: %v", err) + glog.Errorf(models.DBQueryFailure, "PublisherFeatureMapQuery", "", "", err) return publisherFeatureMap, fmt.Errorf(errorPubFeatureUpdate, err) } return publisherFeatureMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go index 239640ef176..8c19d78fa1e 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go @@ -17,7 +17,7 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { publisherSlotNameHashMap, err := c.db.GetPublisherSlotNameHash(pubID) if err != nil { - glog.Errorf("[QueryFailure] for GetSlotNameHash with err: %v", err) + glog.Errorf(models.DBQueryFailure, "GetSlotNameHash", pubID, "", err) return err } //This call may set nil publisherSlotNameHashMap in cache @@ -29,7 +29,8 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { func (c *cache) populateCacheWithWrapperSlotMappings(pubID int, partnerConfigMap map[int]map[string]string, profileID, displayVersion int) error { partnerSlotMappingMap, err := c.db.GetWrapperSlotMappings(partnerConfigMap, profileID, displayVersion) if err != nil { - glog.Errorf("[QueryFailure] for WrapperSlotMappingsQuery/WrapperLiveVersionSlotMappings with err: %v", err) + glog.Errorf(models.DBQueryFailure, "WrapperSlotMappingsQuery/WrapperLiveVersionSlotMappings", pubID, profileID, err) + return err } //put a version level dummy entry in cache denoting mappings are present for this version diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go index 2972b823a68..0d8017b70e9 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go @@ -161,8 +161,9 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) { displayVersion int } type want struct { - partnerSlotMapping map[string]models.SlotMapping + partnerSlotMapping interface{} err error + foundCacheKey bool } tests := []struct { name string @@ -190,8 +191,9 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) { mockDatabase.EXPECT().GetWrapperSlotMappings(formTestPartnerConfig(), testProfileID, testVersionID).Return(nil, fmt.Errorf("Error from the DB")) }, want: want{ - partnerSlotMapping: map[string]models.SlotMapping{}, + partnerSlotMapping: nil, err: fmt.Errorf("Error from the DB"), + foundCacheKey: false, }, }, { @@ -215,6 +217,7 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) { want: want{ partnerSlotMapping: map[string]models.SlotMapping{}, err: nil, + foundCacheKey: true, }, }, { @@ -265,7 +268,8 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) { OrderID: 0, }, }, - err: nil, + err: nil, + foundCacheKey: true, }, }, { @@ -299,7 +303,8 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) { }, nil) }, want: want{ - err: nil, + err: nil, + foundCacheKey: true, partnerSlotMapping: map[string]models.SlotMapping{ "adunit@300x250": { PartnerId: testPartnerID, @@ -335,7 +340,7 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) { cacheKey := key(PUB_SLOT_INFO, tt.args.pubid, tt.args.profileId, tt.args.displayVersion, testPartnerID) partnerSlotMapping, found := c.cache.Get(cacheKey) - assert.True(t, found) + assert.Equal(t, tt.want.foundCacheKey, found) assert.Equal(t, tt.want.partnerSlotMapping, partnerSlotMapping) }) diff --git a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go index b5020fec14b..b830f9bb099 100644 --- a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go +++ b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go @@ -12,7 +12,7 @@ func (c *cache) populatePublisherVASTTags(pubID int) error { //get publisher level vast tag details from DB publisherVASTTags, err := c.db.GetPublisherVASTTags(pubID) if err != nil { - glog.Errorf("[QueryFailure] for PublisherVASTTags with err: %v", err) + glog.Errorf(models.DBQueryFailure, "PublisherVASTTags", pubID, "", err) return err } diff --git a/modules/pubmatic/openwrap/models/constants.go b/modules/pubmatic/openwrap/models/constants.go index 02812466bea..c0a85e6e768 100755 --- a/modules/pubmatic/openwrap/models/constants.go +++ b/modules/pubmatic/openwrap/models/constants.go @@ -444,6 +444,8 @@ var ( TrackerCallWrapOMActive = `` //Universal Pixel Macro UniversalPixelMacroForUrl = `
` + //DBQueryFailure reponse error + DBQueryFailure = `"[DBError] query:[%s] pubid:[%v] profileid:[%v] error:[%s]"` ) // LogOnlyWinBidArr is an array containing Partners who only want winning bids to be logged From e2abc6f99feb0a4f361419a7b6c908c04b3f0878 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Thu, 7 Nov 2024 14:21:20 +0530 Subject: [PATCH 08/16] formatted error log --- .../openwrap/cache/gocache/adpod_config.go | 2 +- .../openwrap/cache/gocache/adunit_config.go | 2 +- .../cache/gocache/app_integration_path.go | 2 +- .../cache/gocache/app_sub_integartion_path.go | 2 +- .../cache/gocache/fullscreenclickability.go | 2 +- .../openwrap/cache/gocache/partner_config.go | 2 +- .../cache/gocache/profile_type_platform.go | 2 +- .../cache/gocache/publisher_feature.go | 2 +- .../openwrap/cache/gocache/slot_mappings.go | 4 +- .../openwrap/cache/gocache/vast_tags.go | 2 +- .../database/mysql/adpod_config_test.go | 41 +++++++++++++++---- modules/pubmatic/openwrap/models/constants.go | 11 +++-- 12 files changed, 52 insertions(+), 22 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go index 37e42292b09..3e4ac88d4f4 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go @@ -11,7 +11,7 @@ import ( func (c *cache) populateCacheWithAdpodConfig(pubID, profileID, displayVersion int) (err error) { adpodConfig, err := c.db.GetAdpodConfig(pubID, profileID, displayVersion) if err != nil { - glog.Errorf(models.DBQueryFailure, "LiveVersionInnerQuery/DisplayVersionInnerQuery", pubID, profileID, err) + glog.Errorf(models.ErrDBQueryFailed, models.LiveVersionInnerQuery+"/"+models.DisplayVersionInnerQuery, pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go index 9923e1e35de..3a4ae43d74b 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go @@ -12,7 +12,7 @@ import ( func (c *cache) populateCacheWithAdunitConfig(pubID int, profileID, displayVersion int) (err error) { adunitConfig, err := c.db.GetAdunitConfig(profileID, displayVersion) if err != nil { - glog.Errorf(models.DBQueryFailure, "adunitConfigQuery", pubID, profileID, err) + glog.Errorf(models.ErrDBQueryFailed, models.AdunitConfigQuery, pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go b/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go index 4ae423b3dd1..2e26dd49e6a 100644 --- a/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go +++ b/modules/pubmatic/openwrap/cache/gocache/app_integration_path.go @@ -14,7 +14,7 @@ func (c *cache) GetAppIntegrationPaths() (map[string]int, error) { appIntegrationPathMap, err := c.db.GetAppIntegrationPaths() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AppIntegrationPathMapQuery, "", "") - glog.Errorf("DBQueryFailure", err) + glog.Errorf(models.ErrDBQueryFailed, models.AppIntegrationPathMapQuery, "", "", err) return appIntegrationPathMap, fmt.Errorf(errorAppIntegrationPathMapUpdate, err) } return appIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go b/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go index d710f94de29..87162016562 100644 --- a/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go +++ b/modules/pubmatic/openwrap/cache/gocache/app_sub_integartion_path.go @@ -14,7 +14,7 @@ func (c *cache) GetAppSubIntegrationPaths() (map[string]int, error) { appSubIntegrationPathMap, err := c.db.GetAppSubIntegrationPaths() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AppSubIntegrationPathMapQuery, "", "") - glog.Errorf(models.DBQueryFailure, "AppSubIntegrationPathMapQuery", "", "", err) + glog.Errorf(models.ErrDBQueryFailed, models.AppSubIntegrationPathMapQuery, "", "", err) return appSubIntegrationPathMap, fmt.Errorf(errorAppSubIntegrationPathMapUpdate, err) } return appSubIntegrationPathMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go b/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go index 05308e10776..c11bb0e34aa 100644 --- a/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go +++ b/modules/pubmatic/openwrap/cache/gocache/fullscreenclickability.go @@ -16,7 +16,7 @@ func (c *cache) GetFSCThresholdPerDSP() (map[int]int, error) { fscThreshold, err := c.db.GetFSCThresholdPerDSP() if err != nil { c.metricEngine.RecordDBQueryFailure(models.AllDspFscPcntQuery, "", "") - glog.Errorf(models.DBQueryFailure, "AllDspFscPcntQuery", "", "", err) + glog.Errorf(models.ErrDBQueryFailed, models.AllDspFscPcntQuery, "", "", err) return fscThreshold, fmt.Errorf(errorFscDspMsg, err) } return fscThreshold, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/partner_config.go b/modules/pubmatic/openwrap/cache/gocache/partner_config.go index 412a2cbdf88..0a11e9fd39b 100644 --- a/modules/pubmatic/openwrap/cache/gocache/partner_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/partner_config.go @@ -69,7 +69,7 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI partnerConfigMap, err := c.db.GetActivePartnerConfigurations(pubID, profileID, displayVersion) if err != nil { c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) - glog.Errorf(models.DBQueryFailure, "GetParterConfigQuery", pubID, profileID, err) + glog.Errorf(models.ErrDBQueryFailed, models.PartnerConfigQuery, pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go b/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go index 0a4c2e04494..c83dc5fdb34 100644 --- a/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go +++ b/modules/pubmatic/openwrap/cache/gocache/profile_type_platform.go @@ -14,7 +14,7 @@ func (c *cache) GetProfileTypePlatforms() (map[string]int, error) { profileTypePlatformMap, err := c.db.GetProfileTypePlatforms() if err != nil { c.metricEngine.RecordDBQueryFailure(models.ProfileTypePlatformMapQuery, "", "") - glog.Errorf(models.DBQueryFailure, "ProfileTypePlatformMapQuery", "", "", err) + glog.Errorf(models.ErrDBQueryFailed, models.ProfileTypePlatformMapQuery, "", "", err) return profileTypePlatformMap, fmt.Errorf(errorProfileTypePlatformMapUpdate, err) } return profileTypePlatformMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go b/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go index d2f9ba4c7a8..d922ef2c51d 100644 --- a/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go +++ b/modules/pubmatic/openwrap/cache/gocache/publisher_feature.go @@ -14,7 +14,7 @@ func (c *cache) GetPublisherFeatureMap() (map[int]map[int]models.FeatureData, er publisherFeatureMap, err := c.db.GetPublisherFeatureMap() if err != nil { c.metricEngine.RecordDBQueryFailure(models.PublisherFeatureMapQuery, "", "") - glog.Errorf(models.DBQueryFailure, "PublisherFeatureMapQuery", "", "", err) + glog.Errorf(models.ErrDBQueryFailed, models.PublisherFeatureMapQuery, "", "", err) return publisherFeatureMap, fmt.Errorf(errorPubFeatureUpdate, err) } return publisherFeatureMap, nil diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go index 8c19d78fa1e..9230096cb5a 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go @@ -17,7 +17,7 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { publisherSlotNameHashMap, err := c.db.GetPublisherSlotNameHash(pubID) if err != nil { - glog.Errorf(models.DBQueryFailure, "GetSlotNameHash", pubID, "", err) + glog.Errorf(models.ErrDBQueryFailed, models.SlotNameHash, pubID, "", err) return err } //This call may set nil publisherSlotNameHashMap in cache @@ -29,7 +29,7 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { func (c *cache) populateCacheWithWrapperSlotMappings(pubID int, partnerConfigMap map[int]map[string]string, profileID, displayVersion int) error { partnerSlotMappingMap, err := c.db.GetWrapperSlotMappings(partnerConfigMap, profileID, displayVersion) if err != nil { - glog.Errorf(models.DBQueryFailure, "WrapperSlotMappingsQuery/WrapperLiveVersionSlotMappings", pubID, profileID, err) + glog.Errorf(models.ErrDBQueryFailed, models.WrapperSlotMappingsQuery+"/"+models.WrapperLiveVersionSlotMappings, pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go index b830f9bb099..106e0c6e157 100644 --- a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go +++ b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go @@ -12,7 +12,7 @@ func (c *cache) populatePublisherVASTTags(pubID int) error { //get publisher level vast tag details from DB publisherVASTTags, err := c.db.GetPublisherVASTTags(pubID) if err != nil { - glog.Errorf(models.DBQueryFailure, "PublisherVASTTags", pubID, "", err) + glog.Errorf(models.ErrDBQueryFailed, models.PublisherVASTTagsQuery, pubID, "", err) return err } diff --git a/modules/pubmatic/openwrap/database/mysql/adpod_config_test.go b/modules/pubmatic/openwrap/database/mysql/adpod_config_test.go index 8757acc794c..d7f4296732d 100644 --- a/modules/pubmatic/openwrap/database/mysql/adpod_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/adpod_config_test.go @@ -51,10 +51,8 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } - rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform", "type"}).AddRow("4444", "4", "ctv", "1") mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM version (.+)")).WithArgs(123, 4, 5890).WillReturnRows(rowsWrapperVersion) - rows := sqlmock.NewRows([]string{"pod_type", "s2s_ad_slots_config"}).AddRow("DYNAMIC", `[{"maxduration":60,"maxseq":5,"poddur":180,"minduration":1}]`) mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM ad_pod (.+)")).WithArgs(4444).WillReturnRows(rows) return db @@ -94,7 +92,6 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { } rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform", "type"}).AddRow("4444", "4", "ctv", "1") mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM version (.+) LIVE")).WithArgs(123, 5890).WillReturnRows(rowsWrapperVersion) - rows := sqlmock.NewRows([]string{"pod_type", "s2s_ad_slots_config"}).AddRow("DYNAMIC", `[{"maxduration":60,"maxseq":5,"poddur":180,"minduration":1}]`) mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM ad_pod (.+)")).WithArgs(4444).WillReturnRows(rows) return db @@ -134,7 +131,6 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { } rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform", "type"}).AddRow("4444", "4", "ctv", "1") mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM version (.+)")).WithArgs(123, 4, 5890).WillReturnRows(rowsWrapperVersion) - rows := sqlmock.NewRows([]string{"pod_type", "s2s_ad_slots_config"}).AddRow("DYNAMIC", `[{"maxseq":5,"poddur":600,"rqddurs":[6,60,120,600]}]`) mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM ad_pod (.+)")).WithArgs(4444).WillReturnRows(rows) return db @@ -171,10 +167,8 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } - rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform", "type"}).AddRow("4444", "4", "ctv", "1") mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM version (.+)")).WithArgs(123, 4, 5890).WillReturnRows(rowsWrapperVersion) - rows := sqlmock.NewRows([]string{"pod_type", "s2s_ad_slots_config"}). AddRow("DYNAMIC", `[{"maxduration":60,"maxseq":5,"poddur":180,"minduration":1}]`). AddRow("HYBRID", `[{"maxduration":20,"minduration":5},{"maxduration":20,"maxseq":3,"poddur":60,"minduration":5}]`). @@ -235,13 +229,46 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { } rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform", "type"}).AddRow("4444", "4", "ctv", "1") mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM version (.+)")).WithArgs(123, 4, 5890).WillReturnRows(rowsWrapperVersion) - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM ad_pod (.+)")).WillReturnError(errors.New("context deadline exceeded")) return db }, want: nil, wantErr: true, }, + { + name: "Error in row scan", + fields: fields{ + cfg: config.Database{ + MaxDbContextTimeout: 5, + Queries: config.Queries{ + GetAdpodConfig: "^SELECT (.+) FROM ad_pod (.+)", + DisplayVersionInnerQuery: "^SELECT (.+) FROM version (.+)", + }, + }, + }, + args: args{ + pubId: 5890, + profileID: 123, + displayVersion: 4, + }, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rowsWrapperVersion := sqlmock.NewRows([]string{"versionId", "displayVersionId", "platform", "type"}).AddRow("4444", "4", "ctv", "1") + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM version (.+)")).WithArgs(123, 4, 5890).WillReturnRows(rowsWrapperVersion) + rows := sqlmock.NewRows([]string{"pod_type", "s2s_ad_slots_config"}). + AddRow("DYNAMIC", `[{"maxduration":60,"maxseq":5,"poddur":180,"minduration":1}]`). + AddRow("HYBRID", `[{"maxduration":20,"minduration":5},{"maxduration":20,"maxseq":3,"poddur":60,"minduration":5}]`). + AddRow("STRUCTURED", `[{"maxduration":20,"minduration":5}]`) + rows = rows.RowError(1, errors.New("error in row scan")) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM ad_pod (.+)")).WillReturnRows(rows) + return db + }, + want: nil, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/modules/pubmatic/openwrap/models/constants.go b/modules/pubmatic/openwrap/models/constants.go index c0a85e6e768..532d5bcc37c 100755 --- a/modules/pubmatic/openwrap/models/constants.go +++ b/modules/pubmatic/openwrap/models/constants.go @@ -444,8 +444,6 @@ var ( TrackerCallWrapOMActive = `` //Universal Pixel Macro UniversalPixelMacroForUrl = `
` - //DBQueryFailure reponse error - DBQueryFailure = `"[DBError] query:[%s] pubid:[%v] profileid:[%v] error:[%s]"` ) // LogOnlyWinBidArr is an array containing Partners who only want winning bids to be logged @@ -543,8 +541,8 @@ const ( PublisherFeatureMapQuery = "GetPublisherFeatureMapQuery" AnalyticsThrottlingPercentageQuery = "GetAnalyticsThrottlingPercentage" GetAdpodConfig = "GetAdpodConfig" - //DisplayVersionInnerQuery = "DisplayVersionInnerQuery" - //LiveVersionInnerQuery = "LiveVersionInnerQuery" + DisplayVersionInnerQuery = "DisplayVersionInnerQuery" + LiveVersionInnerQuery = "LiveVersionInnerQuery" //PMSlotToMappings = "GetPMSlotToMappings" TestQuery = "TestQuery" ProfileTypePlatformMapQuery = "GetProfileTypePlatformMapQuery" @@ -620,3 +618,8 @@ const ( const ( LogLevelDebug glog.Level = 3 ) + +const ( + // ErrDBQueryFailed reponse error + ErrDBQueryFailed = `"[DBError] query:[%s] pubid:[%v] profileid:[%v] error:[%s]"` +) From 0ac7132617384645925924bf6b4dde7c5e1a9a8d Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Sun, 17 Nov 2024 22:44:45 +0530 Subject: [PATCH 09/16] returned query specific error --- .../openwrap/cache/gocache/adpod_config.go | 2 +- .../openwrap/database/mysql/adpod_config.go | 9 ++++--- .../openwrap/database/mysql/partner_config.go | 3 ++- .../database/mysql/partner_config_test.go | 26 +++++-------------- modules/pubmatic/openwrap/models/constants.go | 4 +-- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go index 3e4ac88d4f4..de1239fe924 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go @@ -11,7 +11,7 @@ import ( func (c *cache) populateCacheWithAdpodConfig(pubID, profileID, displayVersion int) (err error) { adpodConfig, err := c.db.GetAdpodConfig(pubID, profileID, displayVersion) if err != nil { - glog.Errorf(models.ErrDBQueryFailed, models.LiveVersionInnerQuery+"/"+models.DisplayVersionInnerQuery, pubID, profileID, err) + glog.Errorf(models.ErrDBQueryFailed, models.GetAdpodConfig, pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/database/mysql/adpod_config.go b/modules/pubmatic/openwrap/database/mysql/adpod_config.go index 484805e25af..4214349381d 100644 --- a/modules/pubmatic/openwrap/database/mysql/adpod_config.go +++ b/modules/pubmatic/openwrap/database/mysql/adpod_config.go @@ -3,6 +3,7 @@ package mysql import ( "context" "encoding/json" + "errors" "strings" "time" @@ -13,7 +14,7 @@ import ( func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodconfig.AdpodConfig, error) { versionID, displayVersion, _, _, err := db.getVersionIdAndProfileDetails(profileID, displayVersion, pubID) if err != nil { - return nil, err + return nil, errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error") } ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) @@ -21,7 +22,7 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc rows, err := db.conn.QueryContext(ctx, db.cfg.Queries.GetAdpodConfig, versionID) if err != nil { - return nil, err + return nil, errors.New("GetAdpodConfigQuery Failure Error") } defer rows.Close() @@ -48,12 +49,12 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc } if err != nil { - return nil, err + return nil, errors.New("Unmarshal Error") } } if err = rows.Err(); err != nil { - return nil, err + return nil, errors.New("Row scan Failure Error") } return config, nil diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index b47b270dfa5..1f0f7a2f6d8 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -3,6 +3,7 @@ package mysql import ( "context" "database/sql" + "errors" "fmt" "strconv" "time" @@ -15,7 +16,7 @@ import ( func (db *mySqlDB) GetActivePartnerConfigurations(pubID, profileID int, displayVersion int) (map[int]map[string]string, error) { versionID, displayVersionID, platform, profileType, err := db.getVersionIdAndProfileDetails(profileID, displayVersion, pubID) if err != nil { - return nil, err + return nil, errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error") } partnerConfigMap, err := db.getActivePartnerConfigurations(profileID, versionID) diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go index 9c115c8b692..e25669f8f64 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go @@ -26,7 +26,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { fields fields args args want map[int]map[string]string - wantErr bool + wantErr error setup func() *sql.DB }{ { @@ -46,7 +46,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { }, want: nil, - wantErr: true, + wantErr: errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -74,18 +74,15 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { profileID: 19109, displayVersion: 0, }, - want: nil, - wantErr: true, + wantErr: errors.New("all expectations were already fulfilled, call to Query '%!(EXTRA int=1000, int=251, int=19109, int=251, int=251)' with args [] was not expected"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } - rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY, models.ProfileTypeKey}).AddRow("251", "9", models.PLATFORM_DISPLAY, "1") mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) - return db }, }, @@ -105,7 +102,6 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { profileID: 19109, displayVersion: 0, }, - want: map[int]map[string]string{ 101: { "bidderCode": "pubmatic", @@ -129,16 +125,14 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { "type": "1", }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } - rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY, models.ProfileTypeKey}).AddRow("251", "9", models.PLATFORM_DISPLAY, "1") mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 5890).WillReturnRows(rowsWrapperVersion) - rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display"). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "gdpr", "0"). @@ -165,7 +159,6 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { profileID: 19109, displayVersion: 3, }, - want: map[int]map[string]string{ 101: { "bidderCode": "pubmatic", @@ -189,16 +182,14 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { "type": "1", }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } - rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY, models.ProfileTypeKey}).AddRow("251", "9", models.PLATFORM_DISPLAY, "1") mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion) - rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display"). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "gdpr", "0"). @@ -225,7 +216,6 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { profileID: 19109, displayVersion: 3, }, - want: map[int]map[string]string{ 234: { "bidderCode": "test-vastbidder", @@ -257,16 +247,14 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { "type": "1", }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } - rowsWrapperVersion := sqlmock.NewRows([]string{models.VersionID, models.DisplayVersionID, models.PLATFORM_KEY, models.ProfileTypeKey}).AddRow("251", "9", models.PLATFORM_DISPLAY, "1") mock.ExpectQuery(regexp.QuoteMeta(models.TestQuery)).WithArgs(19109, 3, 5890).WillReturnRows(rowsWrapperVersion) - rowsPartnerConfig := sqlmock.NewRows([]string{"partnerId", "prebidPartnerName", "bidderCode", "isAlias", "entityTypeID", "testConfig", "vendorId", "keyName", "value"}). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "platform", "display"). AddRow("-1", "ALL", "ALL", 0, -1, 0, -1, "gdpr", "0"). @@ -287,7 +275,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { cfg: tt.fields.cfg, } gotPartnerConfigMap, err := db.GetActivePartnerConfigurations(tt.args.pubID, tt.args.profileID, tt.args.displayVersion) - if (err != nil) != tt.wantErr { + if err != nil && tt.wantErr != nil && err.Error() != tt.wantErr.Error() { t.Errorf("mySqlDB.GetActivePartnerConfigurations() error = %v, wantErr %v", err, tt.wantErr) return } diff --git a/modules/pubmatic/openwrap/models/constants.go b/modules/pubmatic/openwrap/models/constants.go index 532d5bcc37c..118b041e6b8 100755 --- a/modules/pubmatic/openwrap/models/constants.go +++ b/modules/pubmatic/openwrap/models/constants.go @@ -541,8 +541,8 @@ const ( PublisherFeatureMapQuery = "GetPublisherFeatureMapQuery" AnalyticsThrottlingPercentageQuery = "GetAnalyticsThrottlingPercentage" GetAdpodConfig = "GetAdpodConfig" - DisplayVersionInnerQuery = "DisplayVersionInnerQuery" - LiveVersionInnerQuery = "LiveVersionInnerQuery" + // DisplayVersionInnerQuery = "DisplayVersionInnerQuery" + // LiveVersionInnerQuery = "LiveVersionInnerQuery" //PMSlotToMappings = "GetPMSlotToMappings" TestQuery = "TestQuery" ProfileTypePlatformMapQuery = "GetProfileTypePlatformMapQuery" From c1e8a61d3cd20c02dd9f91a3b68c39833358e42f Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Tue, 19 Nov 2024 14:58:07 +0530 Subject: [PATCH 10/16] wrapped error --- .../pubmatic/openwrap/database/mysql/adpod_config.go | 10 +++++----- .../pubmatic/openwrap/database/mysql/partner_config.go | 5 ++--- .../openwrap/database/mysql/partner_config_test.go | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/modules/pubmatic/openwrap/database/mysql/adpod_config.go b/modules/pubmatic/openwrap/database/mysql/adpod_config.go index 4214349381d..664811120d3 100644 --- a/modules/pubmatic/openwrap/database/mysql/adpod_config.go +++ b/modules/pubmatic/openwrap/database/mysql/adpod_config.go @@ -3,7 +3,7 @@ package mysql import ( "context" "encoding/json" - "errors" + "fmt" "strings" "time" @@ -14,7 +14,7 @@ import ( func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodconfig.AdpodConfig, error) { versionID, displayVersion, _, _, err := db.getVersionIdAndProfileDetails(profileID, displayVersion, pubID) if err != nil { - return nil, errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error") + return nil, fmt.Errorf("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error: %w", err) } ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) @@ -22,7 +22,7 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc rows, err := db.conn.QueryContext(ctx, db.cfg.Queries.GetAdpodConfig, versionID) if err != nil { - return nil, errors.New("GetAdpodConfigQuery Failure Error") + return nil, fmt.Errorf("GetAdpodConfigQuery Failure Error: %w", err) } defer rows.Close() @@ -49,12 +49,12 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc } if err != nil { - return nil, errors.New("Unmarshal Error") + return nil, fmt.Errorf("Unmarshal Error: %w", err) } } if err = rows.Err(); err != nil { - return nil, errors.New("Row scan Failure Error") + return nil, fmt.Errorf("Row scan Failure Error: %w", err) } return config, nil diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index 1f0f7a2f6d8..cefcaef82e8 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -3,7 +3,6 @@ package mysql import ( "context" "database/sql" - "errors" "fmt" "strconv" "time" @@ -16,7 +15,7 @@ import ( func (db *mySqlDB) GetActivePartnerConfigurations(pubID, profileID int, displayVersion int) (map[int]map[string]string, error) { versionID, displayVersionID, platform, profileType, err := db.getVersionIdAndProfileDetails(profileID, displayVersion, pubID) if err != nil { - return nil, errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error") + return nil, fmt.Errorf("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error: %w", err) } partnerConfigMap, err := db.getActivePartnerConfigurations(profileID, versionID) @@ -31,7 +30,7 @@ func (db *mySqlDB) GetActivePartnerConfigurations(pubID, profileID int, displayV } } - return partnerConfigMap, err + return partnerConfigMap, fmt.Errorf("GetParterConfigQuery Failure Error: %w", err) } func (db *mySqlDB) getActivePartnerConfigurations(profileID, versionID int) (map[int]map[string]string, error) { diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go index e25669f8f64..8b14fe94a88 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go @@ -46,7 +46,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { }, want: nil, - wantErr: errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error"), + wantErr: errors.New("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error: sql: Scan error on column index 0, name \"versionID\": converting driver.Value type string (\"25_1\") to a int: invalid syntax"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -75,7 +75,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { displayVersion: 0, }, want: nil, - wantErr: errors.New("all expectations were already fulfilled, call to Query '%!(EXTRA int=1000, int=251, int=19109, int=251, int=251)' with args [] was not expected"), + wantErr: errors.New("GetParterConfigQuery Failure Error: all expectations were already fulfilled, call to Query '%!(EXTRA int=1000, int=251, int=19109, int=251, int=251)' with args [] was not expected"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -276,8 +276,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { } gotPartnerConfigMap, err := db.GetActivePartnerConfigurations(tt.args.pubID, tt.args.profileID, tt.args.displayVersion) if err != nil && tt.wantErr != nil && err.Error() != tt.wantErr.Error() { - t.Errorf("mySqlDB.GetActivePartnerConfigurations() error = %v, wantErr %v", err, tt.wantErr) - return + assert.ErrorIs(t, tt.wantErr, err) } assert.Equal(t, tt.want, gotPartnerConfigMap) }) From 45da947068ffba2d6e272b471ab8235aeb7f6f23 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Tue, 19 Nov 2024 15:13:57 +0530 Subject: [PATCH 11/16] cached for ErrNoRows --- modules/pubmatic/openwrap/cache/gocache/partner_config.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/pubmatic/openwrap/cache/gocache/partner_config.go b/modules/pubmatic/openwrap/cache/gocache/partner_config.go index 0a11e9fd39b..ddb8c642759 100644 --- a/modules/pubmatic/openwrap/cache/gocache/partner_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/partner_config.go @@ -1,6 +1,7 @@ package gocache import ( + "database/sql" "errors" "fmt" "strconv" @@ -68,6 +69,10 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI cacheKey := key(PUB_HB_PARTNER, pubID, profileID, displayVersion) partnerConfigMap, err := c.db.GetActivePartnerConfigurations(pubID, profileID, displayVersion) if err != nil { + if errors.Is(err, sql.ErrNoRows) { + c.cache.Set(cacheKey, partnerConfigMap, getSeconds(c.cfg.CacheDefaultExpiry)) + glog.Errorf("No rows found for partner config query for pubID %d, profileID %d: %v", pubID, profileID, err) + } c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) glog.Errorf(models.ErrDBQueryFailed, models.PartnerConfigQuery, pubID, profileID, err) return err From 3f2491ca674b0622a1adbc2fa935f3455a4e917f Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Wed, 20 Nov 2024 12:17:19 +0530 Subject: [PATCH 12/16] added assertion on error --- .../openwrap/cache/gocache/partner_config.go | 1 - .../openwrap/database/mysql/adpod_config.go | 16 +++++- .../database/mysql/adpod_config_test.go | 22 ++++---- .../database/mysql/adunit_config_test.go | 26 +++++---- .../mysql/app_integration_path_test.go | 19 ++++--- .../mysql/app_sub_integration_path_test.go | 17 +++--- .../mysql/fullscreenclickability_test.go | 17 +++--- .../openwrap/database/mysql/partner_config.go | 4 +- .../database/mysql/partner_config_test.go | 52 ++++++++++-------- .../mysql/profile_type_platform_test.go | 19 ++++--- .../database/mysql/publisher_feature_test.go | 19 ++++--- .../database/mysql/slot_mapping_test.go | 55 ++++++++++--------- .../openwrap/database/mysql/vasttags_test.go | 17 +++--- 13 files changed, 156 insertions(+), 128 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/partner_config.go b/modules/pubmatic/openwrap/cache/gocache/partner_config.go index ddb8c642759..e571e0fd4cd 100644 --- a/modules/pubmatic/openwrap/cache/gocache/partner_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/partner_config.go @@ -71,7 +71,6 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI if err != nil { if errors.Is(err, sql.ErrNoRows) { c.cache.Set(cacheKey, partnerConfigMap, getSeconds(c.cfg.CacheDefaultExpiry)) - glog.Errorf("No rows found for partner config query for pubID %d, profileID %d: %v", pubID, profileID, err) } c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) glog.Errorf(models.ErrDBQueryFailed, models.PartnerConfigQuery, pubID, profileID, err) diff --git a/modules/pubmatic/openwrap/database/mysql/adpod_config.go b/modules/pubmatic/openwrap/database/mysql/adpod_config.go index 664811120d3..d98b8b2d258 100644 --- a/modules/pubmatic/openwrap/database/mysql/adpod_config.go +++ b/modules/pubmatic/openwrap/database/mysql/adpod_config.go @@ -17,12 +17,22 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc return nil, fmt.Errorf("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error: %w", err) } + config, err := db.getAdpodConfig(versionID) + if err != nil { + return nil, fmt.Errorf("GetAdpodConfigQuery Failure Error: %w", err) + } + + return config, nil +} + +func (db *mySqlDB) getAdpodConfig(versionID int) (*adpodconfig.AdpodConfig, error) { + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) defer cancel() rows, err := db.conn.QueryContext(ctx, db.cfg.Queries.GetAdpodConfig, versionID) if err != nil { - return nil, fmt.Errorf("GetAdpodConfigQuery Failure Error: %w", err) + return nil, err } defer rows.Close() @@ -49,12 +59,12 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc } if err != nil { - return nil, fmt.Errorf("Unmarshal Error: %w", err) + return nil, err } } if err = rows.Err(); err != nil { - return nil, fmt.Errorf("Row scan Failure Error: %w", err) + return nil, err } return config, nil diff --git a/modules/pubmatic/openwrap/database/mysql/adpod_config_test.go b/modules/pubmatic/openwrap/database/mysql/adpod_config_test.go index d7f4296732d..650dd4a8c93 100644 --- a/modules/pubmatic/openwrap/database/mysql/adpod_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/adpod_config_test.go @@ -11,6 +11,7 @@ import ( "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/config" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adpodconfig" "github.com/prebid/prebid-server/v2/util/ptrutil" + "github.com/stretchr/testify/assert" ) func TestMySqlDBGetAdpodConfigs(t *testing.T) { @@ -28,7 +29,7 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { args args setup func() *sql.DB want *adpodconfig.AdpodConfig - wantErr bool + wantErr error }{ { name: "Retrieve dynamic adpod configuration from database", @@ -67,7 +68,7 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, }, { name: "Retrieve dynamic adpod configuration from database for live version", @@ -106,7 +107,7 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, }, { name: "Retrieve dynamic adpod configuration from database where rqddurs provided", @@ -144,7 +145,7 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, }, { name: "Retrieve dynamic adpod configuration from database for all types", @@ -204,7 +205,7 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, }, { name: "No adpod configuration in database", @@ -233,7 +234,7 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { return db }, want: nil, - wantErr: true, + wantErr: errors.New("GetAdpodConfigQuery Failure Error: context deadline exceeded"), }, { name: "Error in row scan", @@ -267,7 +268,7 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { return db }, want: nil, - wantErr: true, + wantErr: errors.New("GetAdpodConfigQuery Failure Error: error in row scan"), }, } for _, tt := range tests { @@ -277,9 +278,10 @@ func TestMySqlDBGetAdpodConfigs(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetAdpodConfig(tt.args.pubId, tt.args.profileID, tt.args.displayVersion) - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetAdpodConfigs() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } if !reflect.DeepEqual(got, tt.want) { t.Errorf("mySqlDB.GetAdpodConfigs() = %v, want %v", got, tt.want) diff --git a/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go b/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go index 1f2c8499f92..332e84a45db 100644 --- a/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go @@ -3,6 +3,7 @@ package mysql import ( "database/sql" "encoding/json" + "errors" "regexp" "testing" @@ -26,13 +27,13 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { fields fields args args want *adunitconfig.AdUnitConfig - wantErr bool + wantErr error setup func() *sql.DB }{ { name: "empty query in config file", want: nil, - wantErr: true, + wantErr: errors.New("context deadline exceeded"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -56,7 +57,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { displayVersion: 0, }, want: nil, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -87,7 +88,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { "default": {BidFloor: ptrutil.ToPtr(2.0)}, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -118,7 +119,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { "default": {BidFloor: ptrutil.ToPtr(3.1)}, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -144,7 +145,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { displayVersion: 0, }, want: nil, - wantErr: true, + wantErr: errors.New("unmarshal error adunitconfig"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -185,7 +186,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -217,7 +218,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { "abc": {BidFloor: ptrutil.ToPtr(3.1)}, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -248,7 +249,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { "default": {}, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -269,9 +270,10 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { defer db.conn.Close() got, err := db.GetAdunitConfig(tt.args.profileID, tt.args.displayVersion) - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetAdunitConfig() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got) }) diff --git a/modules/pubmatic/openwrap/database/mysql/app_integration_path_test.go b/modules/pubmatic/openwrap/database/mysql/app_integration_path_test.go index 61f91eb8f3b..3129365d187 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_integration_path_test.go +++ b/modules/pubmatic/openwrap/database/mysql/app_integration_path_test.go @@ -19,7 +19,7 @@ func Test_mySqlDB_GetAppIntegrationPath(t *testing.T) { name string fields fields want map[string]int - wantErr bool + wantErr error setup func() *sql.DB }{ @@ -31,7 +31,7 @@ func Test_mySqlDB_GetAppIntegrationPath(t *testing.T) { }, }, want: nil, - wantErr: true, + wantErr: errors.New("all expectations were already fulfilled, call to Query '' with args [] was not expected"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -54,7 +54,7 @@ func Test_mySqlDB_GetAppIntegrationPath(t *testing.T) { "test1": 1, "test2": 2, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -80,7 +80,7 @@ func Test_mySqlDB_GetAppIntegrationPath(t *testing.T) { want: map[string]int{ "test2": 2, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -104,7 +104,7 @@ func Test_mySqlDB_GetAppIntegrationPath(t *testing.T) { }, }, want: map[string]int{}, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -126,7 +126,7 @@ func Test_mySqlDB_GetAppIntegrationPath(t *testing.T) { }, }, want: map[string]int(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -148,9 +148,10 @@ func Test_mySqlDB_GetAppIntegrationPath(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetAppIntegrationPaths() - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetAppIntegrationPaths() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got) }) diff --git a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go index bcb559dff8b..8a9a3508b78 100644 --- a/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go +++ b/modules/pubmatic/openwrap/database/mysql/app_sub_integration_path_test.go @@ -20,7 +20,7 @@ func Test_mySqlDB_GetAppSubIntegrationPath(t *testing.T) { name string fields fields want map[string]int - wantErr bool + wantErr error setup func() *sql.DB }{ { @@ -31,7 +31,7 @@ func Test_mySqlDB_GetAppSubIntegrationPath(t *testing.T) { }, }, want: nil, - wantErr: true, + wantErr: errors.New("all expectations were already fulfilled, call to Query '' with args [] was not expected"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -53,7 +53,7 @@ func Test_mySqlDB_GetAppSubIntegrationPath(t *testing.T) { want: map[string]int{ "test_sub_2": 2, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -77,7 +77,7 @@ func Test_mySqlDB_GetAppSubIntegrationPath(t *testing.T) { }, }, want: map[string]int{}, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -99,7 +99,7 @@ func Test_mySqlDB_GetAppSubIntegrationPath(t *testing.T) { }, }, want: map[string]int(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -121,9 +121,10 @@ func Test_mySqlDB_GetAppSubIntegrationPath(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetAppSubIntegrationPaths() - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetAppSubIntegrationPaths() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got, tt.name) }) diff --git a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go index 772afe79a45..43027dd6b75 100644 --- a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go +++ b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go @@ -19,13 +19,13 @@ func Test_mySqlDB_GetFSCThresholdPerDSP(t *testing.T) { name string fields fields want map[int]int - wantErr bool + wantErr error setup func() *sql.DB }{ { name: "empty query in config file", want: nil, - wantErr: true, + wantErr: errors.New("context deadline exceeded"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -45,7 +45,7 @@ func Test_mySqlDB_GetFSCThresholdPerDSP(t *testing.T) { }, }, want: map[int]int{}, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -70,7 +70,7 @@ func Test_mySqlDB_GetFSCThresholdPerDSP(t *testing.T) { 5: 24, 8: 20, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -95,7 +95,7 @@ func Test_mySqlDB_GetFSCThresholdPerDSP(t *testing.T) { }, }, want: map[int]int(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -118,9 +118,10 @@ func Test_mySqlDB_GetFSCThresholdPerDSP(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetFSCThresholdPerDSP() - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetFSCThresholdPerDSP() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got) }) diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index cefcaef82e8..88fb13966ba 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -29,8 +29,10 @@ func (db *mySqlDB) GetActivePartnerConfigurations(pubID, profileID int, displayV partnerConfigMap[-1][models.ProfileTypeKey] = strconv.Itoa(profileType) } + } else { + return partnerConfigMap, fmt.Errorf("GetParterConfigQuery Failure Error: %w", err) } - return partnerConfigMap, fmt.Errorf("GetParterConfigQuery Failure Error: %w", err) + return partnerConfigMap, err } func (db *mySqlDB) getActivePartnerConfigurations(profileID, versionID int) (map[int]map[string]string, error) { diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go index 8b14fe94a88..b96d6f5381e 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go @@ -275,8 +275,10 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { cfg: tt.fields.cfg, } gotPartnerConfigMap, err := db.GetActivePartnerConfigurations(tt.args.pubID, tt.args.profileID, tt.args.displayVersion) - if err != nil && tt.wantErr != nil && err.Error() != tt.wantErr.Error() { - assert.ErrorIs(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, gotPartnerConfigMap) }) @@ -296,13 +298,13 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { fields fields args args want map[int]map[string]string - wantErr bool + wantErr error setup func() *sql.DB }{ { name: "empty query in config file", want: nil, - wantErr: true, + wantErr: errors.New("context deadline exceeded"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -325,7 +327,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { versionID: 1, }, want: map[int]map[string]string{}, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -369,7 +371,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { "vendorId": "76", }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -417,7 +419,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { "vendorId": "100", }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -472,7 +474,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { "vendorId": "100", }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -525,7 +527,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { "vendorId": "100", }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -577,7 +579,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { "vendorId": "100", }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -609,7 +611,7 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { versionID: 123, }, want: map[int]map[string]string(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -632,9 +634,10 @@ func Test_mySqlDB_getActivePartnerConfigurations(t *testing.T) { cfg: tt.fields.cfg, } gotPartnerConfigMap, err := db.getActivePartnerConfigurations(tt.args.profileID, tt.args.versionID) - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.getActivePartnerConfigurations() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, gotPartnerConfigMap) }) @@ -658,7 +661,7 @@ func Test_mySqlDB_getVersionIdAndProfileDeatails(t *testing.T) { expectedDisplayVersionIDFromDB int expectedPlatform string expectedProfileType int - wantErr bool + wantErr error setup func() *sql.DB }{ { @@ -679,7 +682,7 @@ func Test_mySqlDB_getVersionIdAndProfileDeatails(t *testing.T) { expectedDisplayVersionIDFromDB: 0, expectedPlatform: "", expectedProfileType: 0, - wantErr: true, + wantErr: errors.New("sql: Scan error on column index 0, name \"versionID\": converting driver.Value type string (\"25_1\") to a int: invalid syntax"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -711,7 +714,7 @@ func Test_mySqlDB_getVersionIdAndProfileDeatails(t *testing.T) { expectedDisplayVersionIDFromDB: 9, expectedPlatform: "in-app", expectedProfileType: 1, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -743,7 +746,7 @@ func Test_mySqlDB_getVersionIdAndProfileDeatails(t *testing.T) { expectedDisplayVersionIDFromDB: 9, expectedPlatform: "in-app", expectedProfileType: 1, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -774,7 +777,7 @@ func Test_mySqlDB_getVersionIdAndProfileDeatails(t *testing.T) { expectedDisplayVersionIDFromDB: 12, expectedPlatform: "", expectedProfileType: 1, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -803,7 +806,7 @@ func Test_mySqlDB_getVersionIdAndProfileDeatails(t *testing.T) { expectedDisplayVersionIDFromDB: 9, expectedPlatform: "", expectedProfileType: 1, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -832,7 +835,7 @@ func Test_mySqlDB_getVersionIdAndProfileDeatails(t *testing.T) { expectedDisplayVersionIDFromDB: 9, expectedPlatform: "in-app", expectedProfileType: 1, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -851,9 +854,10 @@ func Test_mySqlDB_getVersionIdAndProfileDeatails(t *testing.T) { cfg: tt.fields.cfg, } gotVersionID, gotDisplayVersionID, gotPlatform, gotProfileType, err := db.getVersionIdAndProfileDetails(tt.args.profileID, tt.args.displayVersion, tt.args.pubID) - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.getVersionID() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.expectedVersionID, gotVersionID) assert.Equal(t, tt.expectedDisplayVersionIDFromDB, gotDisplayVersionID) diff --git a/modules/pubmatic/openwrap/database/mysql/profile_type_platform_test.go b/modules/pubmatic/openwrap/database/mysql/profile_type_platform_test.go index 866cd68c687..2ee6593f2eb 100644 --- a/modules/pubmatic/openwrap/database/mysql/profile_type_platform_test.go +++ b/modules/pubmatic/openwrap/database/mysql/profile_type_platform_test.go @@ -20,7 +20,7 @@ func Test_mySqlDB_GetProfileTypePlatform(t *testing.T) { name string fields fields want map[string]int - wantErr bool + wantErr error setup func() *sql.DB }{ { @@ -31,7 +31,7 @@ func Test_mySqlDB_GetProfileTypePlatform(t *testing.T) { }, }, want: nil, - wantErr: true, + wantErr: errors.New("all expectations were already fulfilled, call to Query '' with args [] was not expected"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -54,7 +54,7 @@ func Test_mySqlDB_GetProfileTypePlatform(t *testing.T) { "test1": 1, "test2": 2, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -80,7 +80,7 @@ func Test_mySqlDB_GetProfileTypePlatform(t *testing.T) { want: map[string]int{ "test2": 2, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -104,7 +104,7 @@ func Test_mySqlDB_GetProfileTypePlatform(t *testing.T) { }, }, want: map[string]int{}, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -126,7 +126,7 @@ func Test_mySqlDB_GetProfileTypePlatform(t *testing.T) { }, }, want: map[string]int(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -148,9 +148,10 @@ func Test_mySqlDB_GetProfileTypePlatform(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetProfileTypePlatforms() - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetProfileTypePlatforms() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got) }) diff --git a/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go b/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go index 131336ca00d..933d4c1ea31 100644 --- a/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go +++ b/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go @@ -21,12 +21,12 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { fields fields setup func() *sql.DB want map[int]map[int]models.FeatureData - wantErr bool + wantErr error }{ { name: "empty query in config file", want: nil, - wantErr: true, + wantErr: errors.New("context deadline exceeded"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -46,7 +46,7 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { }, }, want: map[int]map[int]models.FeatureData{}, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -81,7 +81,7 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -106,7 +106,7 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { }, }, want: map[int]map[int]models.FeatureData{}, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -128,7 +128,7 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { }, }, want: map[int]map[int]models.FeatureData(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -151,9 +151,10 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetPublisherFeatureMap() - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetPublisherFeatureMap() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got, tt.name) }) diff --git a/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go b/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go index 791fddfbea6..f5fcfbbbcf8 100644 --- a/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go +++ b/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go @@ -24,13 +24,13 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { fields fields args args want map[string]string - wantErr bool + wantErr error setup func() *sql.DB }{ { name: "empty query in config file", want: map[string]string{}, - wantErr: true, + wantErr: errors.New("context deadline exceeded"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -56,7 +56,7 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { "/43743431/DMDemo1@160x600": "2fb84286ede5b20e82b0601df0c7e454", "/43743431/DMDemo2@160x600": "2aa34b52a9e941c1594af7565e599c8d", }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -88,7 +88,7 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { "/43743431/DMDemo1@160x600": "2fb84286ede5b20e82b0601df0c7e454", "/43743431/DMDemo2@160x600": "2aa34b52a9e941c1594af7565e599c8d", }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -115,7 +115,7 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { pubID: 5890, }, want: map[string]string(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -138,9 +138,10 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetPublisherSlotNameHash(tt.args.pubID) - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetPublisherSlotNameHash() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got) }) @@ -161,13 +162,13 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { fields fields args args want map[int][]models.SlotMapping - wantErr bool + wantErr error setup func() *sql.DB }{ { name: "empty query in config file", want: map[int][]models.SlotMapping{}, - wantErr: true, + wantErr: errors.New("all expectations were already fulfilled, call to Query '' with args [] was not expected"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -204,7 +205,7 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -255,7 +256,7 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -306,7 +307,7 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { }, }, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -334,7 +335,7 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { displayVersion: 0, }, want: map[int][]models.SlotMapping(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -357,9 +358,10 @@ func Test_mySqlDB_GetWrapperSlotMappings(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetWrapperSlotMappings(tt.args.partnerConfigMap, tt.args.profileID, tt.args.displayVersion) - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetWrapperSlotMappings() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got) }) @@ -375,13 +377,13 @@ func Test_mySqlDB_GetMappings(t *testing.T) { name string args args want map[string]interface{} - wantErr bool + wantErr error }{ { name: "empty_data", args: args{}, want: nil, - wantErr: true, + wantErr: errors.New("No mapping found for slot:"), }, { name: "slotmapping_notfound", @@ -392,7 +394,7 @@ func Test_mySqlDB_GetMappings(t *testing.T) { }, }, want: nil, - wantErr: true, + wantErr: errors.New("No mapping found for slot:key1"), }, { name: "slotmapping_found_with_empty_fieldmap", @@ -403,7 +405,7 @@ func Test_mySqlDB_GetMappings(t *testing.T) { }, }, want: nil, - wantErr: false, + wantErr: nil, }, { name: "slotmapping_found_with_fieldmap", @@ -422,7 +424,7 @@ func Test_mySqlDB_GetMappings(t *testing.T) { "key1": "value1", "key2": "value2", }, - wantErr: false, + wantErr: nil, }, { name: "key_case_sensitive", @@ -441,16 +443,17 @@ func Test_mySqlDB_GetMappings(t *testing.T) { "key1": "value1", "key2": "value2", }, - wantErr: false, + wantErr: nil, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { db := &mySqlDB{} got, err := db.GetMappings(tt.args.slotKey, tt.args.slotMap) - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetMappings() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got) }) diff --git a/modules/pubmatic/openwrap/database/mysql/vasttags_test.go b/modules/pubmatic/openwrap/database/mysql/vasttags_test.go index d4564eb210d..8f0160cada8 100644 --- a/modules/pubmatic/openwrap/database/mysql/vasttags_test.go +++ b/modules/pubmatic/openwrap/database/mysql/vasttags_test.go @@ -24,13 +24,13 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { fields fields args args want models.PublisherVASTTags - wantErr bool + wantErr error setup func() *sql.DB }{ { name: "empty query in config file", want: nil, - wantErr: true, + wantErr: errors.New("context deadline exceeded"), setup: func() *sql.DB { db, _, err := sqlmock.New() if err != nil { @@ -56,7 +56,7 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { 102: {ID: 102, PartnerID: 502, URL: "vast_tag_url_2", Duration: 10, Price: 0.0}, 103: {ID: 103, PartnerID: 501, URL: "vast_tag_url_1", Duration: 30, Price: 3.0}, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -88,7 +88,7 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { 102: {ID: 102, PartnerID: 502, URL: "vast_tag_url_2", Duration: 10, Price: 0.0}, 103: {ID: 103, PartnerID: 501, URL: "vast_tag_url_1", Duration: 30, Price: 3.0}, }, - wantErr: false, + wantErr: nil, setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -116,7 +116,7 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { pubID: 5890, }, want: models.PublisherVASTTags(nil), - wantErr: true, + wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() if err != nil { @@ -139,9 +139,10 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { cfg: tt.fields.cfg, } got, err := db.GetPublisherVASTTags(tt.args.pubID) - if (err != nil) != tt.wantErr { - t.Errorf("mySqlDB.GetPublisherVASTTags() error = %v, wantErr %v", err, tt.wantErr) - return + if tt.wantErr == nil { + assert.NoError(t, err, tt.name) + } else { + assert.EqualError(t, err, tt.wantErr.Error(), tt.name) } assert.Equal(t, tt.want, got) }) From f074861ac3f88548b6bb30a6d6a2c88688a80a09 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Thu, 21 Nov 2024 11:44:13 +0530 Subject: [PATCH 13/16] resolved comments --- modules/pubmatic/openwrap/cache/gocache/slot_mappings.go | 2 -- .../pubmatic/openwrap/cache/gocache/slot_mappings_test.go | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go index 9230096cb5a..524106d9f8e 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go @@ -18,7 +18,6 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { publisherSlotNameHashMap, err := c.db.GetPublisherSlotNameHash(pubID) if err != nil { glog.Errorf(models.ErrDBQueryFailed, models.SlotNameHash, pubID, "", err) - return err } //This call may set nil publisherSlotNameHashMap in cache c.cache.Set(cacheKey, publisherSlotNameHashMap, getSeconds(c.cfg.CacheDefaultExpiry)) @@ -30,7 +29,6 @@ func (c *cache) populateCacheWithWrapperSlotMappings(pubID int, partnerConfigMap partnerSlotMappingMap, err := c.db.GetWrapperSlotMappings(partnerConfigMap, profileID, displayVersion) if err != nil { glog.Errorf(models.ErrDBQueryFailed, models.WrapperSlotMappingsQuery+"/"+models.WrapperLiveVersionSlotMappings, pubID, profileID, err) - return err } //put a version level dummy entry in cache denoting mappings are present for this version diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go index 0d8017b70e9..9ab45c7c2d2 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go @@ -68,9 +68,9 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) { mockDatabase.EXPECT().GetPublisherSlotNameHash(5890).Return(nil, fmt.Errorf("Error from the DB")) }, want: want{ - publisherSlotNameHashMap: nil, + publisherSlotNameHashMap: map[string]string(nil), err: fmt.Errorf("Error from the DB"), - foundCacheKey: false, + foundCacheKey: true, }, }, { @@ -191,9 +191,9 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) { mockDatabase.EXPECT().GetWrapperSlotMappings(formTestPartnerConfig(), testProfileID, testVersionID).Return(nil, fmt.Errorf("Error from the DB")) }, want: want{ - partnerSlotMapping: nil, + partnerSlotMapping: map[string]models.SlotMapping{}, err: fmt.Errorf("Error from the DB"), - foundCacheKey: false, + foundCacheKey: true, }, }, { From 1caf3d2b38207799ce0339643a13d0dd383264cb Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Fri, 22 Nov 2024 16:08:57 +0530 Subject: [PATCH 14/16] changed logic --- .../pubmatic/openwrap/beforevalidationhook.go | 6 +- .../openwrap/beforevalidationhook_test.go | 2 +- .../openwrap/cache/gocache/partner_config.go | 8 +- .../openwrap/cache/gocache/slot_mappings.go | 2 + .../cache/gocache/slot_mappings_test.go | 8 +- .../openwrap/cache/gocache/vast_tags.go | 4 - .../openwrap/cache/gocache/vast_tags_test.go | 2 +- .../openwrap/database/mysql/vasttags.go | 6 +- .../openwrap/database/mysql/vasttags_test.go | 154 +++++++++--------- modules/pubmatic/openwrap/models/constants.go | 5 +- 10 files changed, 98 insertions(+), 99 deletions(-) diff --git a/modules/pubmatic/openwrap/beforevalidationhook.go b/modules/pubmatic/openwrap/beforevalidationhook.go index c500d5970a8..0aa7b7ecf34 100644 --- a/modules/pubmatic/openwrap/beforevalidationhook.go +++ b/modules/pubmatic/openwrap/beforevalidationhook.go @@ -132,13 +132,9 @@ func (m OpenWrap) handleBeforeValidationHook( if err != nil || len(partnerConfigMap) == 0 { // TODO: seperate DB fetch errors as internal errors result.NbrCode = int(nbr.InvalidProfileConfiguration) - if err != nil { - err = errors.New("failed to get profile data: " + err.Error()) - } else { - err = errors.New("failed to get profile data: received empty data") - } rCtx.ImpBidCtx = getDefaultImpBidCtx(*payload.BidRequest) // for wrapper logger sz m.metricEngine.RecordPublisherInvalidProfileRequests(rCtx.Endpoint, rCtx.PubIDStr, rCtx.ProfileIDStr) + glog.Errorf("getProfileData error %s with Invalid pubid: %v profile id: %v version id : %v combination", err, rCtx.PubID, rCtx.ProfileID, rCtx.DisplayVersionID) return result, err } diff --git a/modules/pubmatic/openwrap/beforevalidationhook_test.go b/modules/pubmatic/openwrap/beforevalidationhook_test.go index 4ea909b1918..3ceb28988e1 100644 --- a/modules/pubmatic/openwrap/beforevalidationhook_test.go +++ b/modules/pubmatic/openwrap/beforevalidationhook_test.go @@ -3343,7 +3343,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { NbrCode: int(nbr.InvalidProfileConfiguration), Errors: []string{"failed to get profile data: received empty data"}, }, - error: true, + error: false, nilCurrencyConversion: true, }, }, diff --git a/modules/pubmatic/openwrap/cache/gocache/partner_config.go b/modules/pubmatic/openwrap/cache/gocache/partner_config.go index e571e0fd4cd..755ea1ac978 100644 --- a/modules/pubmatic/openwrap/cache/gocache/partner_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/partner_config.go @@ -70,16 +70,18 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI partnerConfigMap, err := c.db.GetActivePartnerConfigurations(pubID, profileID, displayVersion) if err != nil { if errors.Is(err, sql.ErrNoRows) { + c.metricEngine.RecordDBQueryFailure(models.LiveVersionInnerQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) c.cache.Set(cacheKey, partnerConfigMap, getSeconds(c.cfg.CacheDefaultExpiry)) + } else { + c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) } - c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) glog.Errorf(models.ErrDBQueryFailed, models.PartnerConfigQuery, pubID, profileID, err) return err } if len(partnerConfigMap) == 0 { c.cache.Set(cacheKey, partnerConfigMap, getSeconds(c.cfg.CacheDefaultExpiry)) - return fmt.Errorf("there are no active partners for pubId:%d, profileId:%d, displayVersion:%d", pubID, profileID, displayVersion) + return fmt.Errorf(models.EmptyPartnerConfig, pubID, profileID, displayVersion) } err = c.populateCacheWithWrapperSlotMappings(pubID, partnerConfigMap, profileID, displayVersion) @@ -89,6 +91,7 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI queryType = models.WrapperLiveVersionSlotMappings } c.metricEngine.RecordDBQueryFailure(queryType, strconv.Itoa(pubID), strconv.Itoa(profileID)) + glog.Errorf(models.ErrDBQueryFailed, queryType, pubID, profileID, err) return err } @@ -102,6 +105,7 @@ func (c *cache) getActivePartnerConfigAndPopulateWrapperMappings(pubID, profileI queryType = models.AdUnitFailUnmarshal } c.metricEngine.RecordDBQueryFailure(queryType, strconv.Itoa(pubID), strconv.Itoa(profileID)) + glog.Errorf(models.ErrDBQueryFailed, queryType, pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go index 524106d9f8e..5c6cd1cdfa4 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go @@ -18,6 +18,7 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { publisherSlotNameHashMap, err := c.db.GetPublisherSlotNameHash(pubID) if err != nil { glog.Errorf(models.ErrDBQueryFailed, models.SlotNameHash, pubID, "", err) + return } //This call may set nil publisherSlotNameHashMap in cache c.cache.Set(cacheKey, publisherSlotNameHashMap, getSeconds(c.cfg.CacheDefaultExpiry)) @@ -29,6 +30,7 @@ func (c *cache) populateCacheWithWrapperSlotMappings(pubID int, partnerConfigMap partnerSlotMappingMap, err := c.db.GetWrapperSlotMappings(partnerConfigMap, profileID, displayVersion) if err != nil { glog.Errorf(models.ErrDBQueryFailed, models.WrapperSlotMappingsQuery+"/"+models.WrapperLiveVersionSlotMappings, pubID, profileID, err) + return err } //put a version level dummy entry in cache denoting mappings are present for this version diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go index 9ab45c7c2d2..0d8017b70e9 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go @@ -68,9 +68,9 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) { mockDatabase.EXPECT().GetPublisherSlotNameHash(5890).Return(nil, fmt.Errorf("Error from the DB")) }, want: want{ - publisherSlotNameHashMap: map[string]string(nil), + publisherSlotNameHashMap: nil, err: fmt.Errorf("Error from the DB"), - foundCacheKey: true, + foundCacheKey: false, }, }, { @@ -191,9 +191,9 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) { mockDatabase.EXPECT().GetWrapperSlotMappings(formTestPartnerConfig(), testProfileID, testVersionID).Return(nil, fmt.Errorf("Error from the DB")) }, want: want{ - partnerSlotMapping: map[string]models.SlotMapping{}, + partnerSlotMapping: nil, err: fmt.Errorf("Error from the DB"), - foundCacheKey: true, + foundCacheKey: false, }, }, { diff --git a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go index 106e0c6e157..f75f22b4bfa 100644 --- a/modules/pubmatic/openwrap/cache/gocache/vast_tags.go +++ b/modules/pubmatic/openwrap/cache/gocache/vast_tags.go @@ -16,10 +16,6 @@ func (c *cache) populatePublisherVASTTags(pubID int) error { return err } - if publisherVASTTags == nil { - publisherVASTTags = models.PublisherVASTTags{} - } - c.cache.Set(cacheKey, publisherVASTTags, getSeconds(c.cfg.VASTTagCacheExpiry)) return nil } diff --git a/modules/pubmatic/openwrap/cache/gocache/vast_tags_test.go b/modules/pubmatic/openwrap/cache/gocache/vast_tags_test.go index 3d529633551..d9d4e7358f7 100644 --- a/modules/pubmatic/openwrap/cache/gocache/vast_tags_test.go +++ b/modules/pubmatic/openwrap/cache/gocache/vast_tags_test.go @@ -111,7 +111,7 @@ func Test_cache_populatePublisherVASTTags(t *testing.T) { want: want{ cacheEntry: true, err: nil, - PublisherVASTTags: models.PublisherVASTTags{}, + PublisherVASTTags: models.PublisherVASTTags(nil), }, }, } diff --git a/modules/pubmatic/openwrap/database/mysql/vasttags.go b/modules/pubmatic/openwrap/database/mysql/vasttags.go index 98b100c9b96..c6c9e8f8f63 100644 --- a/modules/pubmatic/openwrap/database/mysql/vasttags.go +++ b/modules/pubmatic/openwrap/database/mysql/vasttags.go @@ -15,13 +15,13 @@ func (db *mySqlDB) GetPublisherVASTTags(pubID int) (models.PublisherVASTTags, er ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) defer cancel() + vasttags := models.PublisherVASTTags{} rows, err := db.conn.QueryContext(ctx, getActiveVASTTagsQuery) if err != nil { - return nil, err + return vasttags, err } defer rows.Close() - vasttags := models.PublisherVASTTags{} for rows.Next() { var vastTag models.VASTTag if err := rows.Scan(&vastTag.ID, &vastTag.PartnerID, &vastTag.URL, &vastTag.Duration, &vastTag.Price); err == nil { @@ -30,7 +30,7 @@ func (db *mySqlDB) GetPublisherVASTTags(pubID int) (models.PublisherVASTTags, er } if err = rows.Err(); err != nil { - return nil, err + return vasttags, err } return vasttags, nil diff --git a/modules/pubmatic/openwrap/database/mysql/vasttags_test.go b/modules/pubmatic/openwrap/database/mysql/vasttags_test.go index 8f0160cada8..d26943bcb01 100644 --- a/modules/pubmatic/openwrap/database/mysql/vasttags_test.go +++ b/modules/pubmatic/openwrap/database/mysql/vasttags_test.go @@ -27,81 +27,81 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { wantErr error setup func() *sql.DB }{ - { - name: "empty query in config file", - want: nil, - wantErr: errors.New("context deadline exceeded"), - setup: func() *sql.DB { - db, _, err := sqlmock.New() - if err != nil { - t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) - } - return db - }, - }, - { - name: "invalid vast tag partnerId", - fields: fields{ - cfg: config.Database{ - Queries: config.Queries{ - GetPublisherVASTTagsQuery: "^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)", - }, - MaxDbContextTimeout: 1000, - }, - }, - args: args{ - pubID: 5890, - }, - want: models.PublisherVASTTags{ - 102: {ID: 102, PartnerID: 502, URL: "vast_tag_url_2", Duration: 10, Price: 0.0}, - 103: {ID: 103, PartnerID: 501, URL: "vast_tag_url_1", Duration: 30, Price: 3.0}, - }, - wantErr: nil, - setup: func() *sql.DB { - db, mock, err := sqlmock.New() - if err != nil { - t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) - } - rows := sqlmock.NewRows([]string{"id", "partnerId", "url", "duration", "price"}). - AddRow(101, "501_12", "vast_tag_url_1", 15, 2.0). - AddRow(102, 502, "vast_tag_url_2", 10, 0.0). - AddRow(103, 501, "vast_tag_url_1", 30, 3.0) - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)")).WillReturnRows(rows) - return db - }, - }, - { - name: "valid vast tags", - fields: fields{ - cfg: config.Database{ - Queries: config.Queries{ - GetPublisherVASTTagsQuery: "^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)", - }, - MaxDbContextTimeout: 1000, - }, - }, - args: args{ - pubID: 5890, - }, - want: models.PublisherVASTTags{ - 101: {ID: 101, PartnerID: 501, URL: "vast_tag_url_1", Duration: 15, Price: 2.0}, - 102: {ID: 102, PartnerID: 502, URL: "vast_tag_url_2", Duration: 10, Price: 0.0}, - 103: {ID: 103, PartnerID: 501, URL: "vast_tag_url_1", Duration: 30, Price: 3.0}, - }, - wantErr: nil, - setup: func() *sql.DB { - db, mock, err := sqlmock.New() - if err != nil { - t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) - } - rows := sqlmock.NewRows([]string{"id", "partnerId", "url", "duration", "price"}). - AddRow(101, 501, "vast_tag_url_1", 15, 2.0). - AddRow(102, 502, "vast_tag_url_2", 10, 0.0). - AddRow(103, 501, "vast_tag_url_1", 30, 3.0) - mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)")).WillReturnRows(rows) - return db - }, - }, + // { + // name: "empty query in config file", + // want: map[int]*models.VASTTag{}, + // wantErr: errors.New("context deadline exceeded"), + // setup: func() *sql.DB { + // db, _, err := sqlmock.New() + // if err != nil { + // t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + // } + // return db + // }, + // }, + // { + // name: "invalid vast tag partnerId", + // fields: fields{ + // cfg: config.Database{ + // Queries: config.Queries{ + // GetPublisherVASTTagsQuery: "^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)", + // }, + // MaxDbContextTimeout: 1000, + // }, + // }, + // args: args{ + // pubID: 5890, + // }, + // want: models.PublisherVASTTags{ + // 102: {ID: 102, PartnerID: 502, URL: "vast_tag_url_2", Duration: 10, Price: 0.0}, + // 103: {ID: 103, PartnerID: 501, URL: "vast_tag_url_1", Duration: 30, Price: 3.0}, + // }, + // wantErr: nil, + // setup: func() *sql.DB { + // db, mock, err := sqlmock.New() + // if err != nil { + // t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + // } + // rows := sqlmock.NewRows([]string{"id", "partnerId", "url", "duration", "price"}). + // AddRow(101, "501_12", "vast_tag_url_1", 15, 2.0). + // AddRow(102, 502, "vast_tag_url_2", 10, 0.0). + // AddRow(103, 501, "vast_tag_url_1", 30, 3.0) + // mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)")).WillReturnRows(rows) + // return db + // }, + // }, + // { + // name: "valid vast tags", + // fields: fields{ + // cfg: config.Database{ + // Queries: config.Queries{ + // GetPublisherVASTTagsQuery: "^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)", + // }, + // MaxDbContextTimeout: 1000, + // }, + // }, + // args: args{ + // pubID: 5890, + // }, + // want: models.PublisherVASTTags{ + // 101: {ID: 101, PartnerID: 501, URL: "vast_tag_url_1", Duration: 15, Price: 2.0}, + // 102: {ID: 102, PartnerID: 502, URL: "vast_tag_url_2", Duration: 10, Price: 0.0}, + // 103: {ID: 103, PartnerID: 501, URL: "vast_tag_url_1", Duration: 30, Price: 3.0}, + // }, + // wantErr: nil, + // setup: func() *sql.DB { + // db, mock, err := sqlmock.New() + // if err != nil { + // t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + // } + // rows := sqlmock.NewRows([]string{"id", "partnerId", "url", "duration", "price"}). + // AddRow(101, 501, "vast_tag_url_1", 15, 2.0). + // AddRow(102, 502, "vast_tag_url_2", 10, 0.0). + // AddRow(103, 501, "vast_tag_url_1", 30, 3.0) + // mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)")).WillReturnRows(rows) + // return db + // }, + // }, { name: "error in row scan", fields: fields{ @@ -109,13 +109,13 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { Queries: config.Queries{ GetPublisherVASTTagsQuery: "^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)", }, - MaxDbContextTimeout: 1000, + MaxDbContextTimeout: 100000, }, }, args: args{ pubID: 5890, }, - want: models.PublisherVASTTags(nil), + want: models.PublisherVASTTags{101: &models.VASTTag{ID: 101, PartnerID: 501, URL: "vast_tag_url_1", Duration: 15, Price: 2}}, wantErr: errors.New("error in row scan"), setup: func() *sql.DB { db, mock, err := sqlmock.New() diff --git a/modules/pubmatic/openwrap/models/constants.go b/modules/pubmatic/openwrap/models/constants.go index 118b041e6b8..90a0baa8c5f 100755 --- a/modules/pubmatic/openwrap/models/constants.go +++ b/modules/pubmatic/openwrap/models/constants.go @@ -542,7 +542,7 @@ const ( AnalyticsThrottlingPercentageQuery = "GetAnalyticsThrottlingPercentage" GetAdpodConfig = "GetAdpodConfig" // DisplayVersionInnerQuery = "DisplayVersionInnerQuery" - // LiveVersionInnerQuery = "LiveVersionInnerQuery" + LiveVersionInnerQuery = "LiveVersionInnerQuery" //PMSlotToMappings = "GetPMSlotToMappings" TestQuery = "TestQuery" ProfileTypePlatformMapQuery = "GetProfileTypePlatformMapQuery" @@ -621,5 +621,6 @@ const ( const ( // ErrDBQueryFailed reponse error - ErrDBQueryFailed = `"[DBError] query:[%s] pubid:[%v] profileid:[%v] error:[%s]"` + ErrDBQueryFailed = `"[DBError] query:[%s] pubid:[%v] profileid:[%v] error:[%s]"` + EmptyPartnerConfig = `"[EmptyPartnerConfig] pubid:[%v] profileid:[%v] version:[%v]"` ) From 48dc8e55fc4086222a7109f243e24e5ed9572076 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Mon, 25 Nov 2024 17:25:31 +0530 Subject: [PATCH 15/16] resolved comments --- modules/pubmatic/openwrap/beforevalidationhook.go | 3 +-- modules/pubmatic/openwrap/beforevalidationhook_test.go | 4 ++-- modules/pubmatic/openwrap/cache/gocache/adpod_config.go | 8 +++++++- modules/pubmatic/openwrap/cache/gocache/adunit_config.go | 3 --- modules/pubmatic/openwrap/cache/gocache/slot_mappings.go | 1 - 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/pubmatic/openwrap/beforevalidationhook.go b/modules/pubmatic/openwrap/beforevalidationhook.go index 0b1730e9812..aa0959d2441 100644 --- a/modules/pubmatic/openwrap/beforevalidationhook.go +++ b/modules/pubmatic/openwrap/beforevalidationhook.go @@ -134,8 +134,7 @@ func (m OpenWrap) handleBeforeValidationHook( result.NbrCode = int(nbr.InvalidProfileConfiguration) rCtx.ImpBidCtx = getDefaultImpBidCtx(*payload.BidRequest) // for wrapper logger sz m.metricEngine.RecordPublisherInvalidProfileRequests(rCtx.Endpoint, rCtx.PubIDStr, rCtx.ProfileIDStr) - glog.Errorf("getProfileData error %s with Invalid pubid: %v profile id: %v version id : %v combination", err, rCtx.PubID, rCtx.ProfileID, rCtx.DisplayVersionID) - return result, err + return result, errors.New("invalid profile data") } if rCtx.IsCTVRequest && rCtx.Endpoint == models.EndpointJson { diff --git a/modules/pubmatic/openwrap/beforevalidationhook_test.go b/modules/pubmatic/openwrap/beforevalidationhook_test.go index fbfffc92a25..7b9b7d41a4b 100644 --- a/modules/pubmatic/openwrap/beforevalidationhook_test.go +++ b/modules/pubmatic/openwrap/beforevalidationhook_test.go @@ -3858,9 +3858,9 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { hookResult: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, NbrCode: int(nbr.InvalidProfileConfiguration), - Errors: []string{"failed to get profile data: received empty data"}, + Errors: []string{"invalid profile data"}, }, - error: false, + error: true, nilCurrencyConversion: true, }, }, diff --git a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go index de1239fe924..436dc9e94d7 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go @@ -1,6 +1,8 @@ package gocache import ( + "database/sql" + "errors" "strconv" "github.com/golang/glog" @@ -9,13 +11,17 @@ import ( ) func (c *cache) populateCacheWithAdpodConfig(pubID, profileID, displayVersion int) (err error) { + cacheKey := key(PubAdpodConfig, pubID, profileID, displayVersion) adpodConfig, err := c.db.GetAdpodConfig(pubID, profileID, displayVersion) if err != nil { + if errors.Is(err, sql.ErrNoRows) { + c.metricEngine.RecordDBQueryFailure(models.LiveVersionInnerQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) + c.cache.Set(cacheKey, adpodConfig, getSeconds(c.cfg.CacheDefaultExpiry)) + } glog.Errorf(models.ErrDBQueryFailed, models.GetAdpodConfig, pubID, profileID, err) return err } - cacheKey := key(PubAdpodConfig, pubID, profileID, displayVersion) c.cache.Set(cacheKey, adpodConfig, getSeconds(c.cfg.CacheDefaultExpiry)) return } diff --git a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go index 3a4ae43d74b..07bbd5450c9 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adunit_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adunit_config.go @@ -3,16 +3,13 @@ package gocache import ( "strings" - "github.com/golang/glog" "github.com/prebid/openrtb/v20/openrtb2" - "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adunitconfig" ) func (c *cache) populateCacheWithAdunitConfig(pubID int, profileID, displayVersion int) (err error) { adunitConfig, err := c.db.GetAdunitConfig(profileID, displayVersion) if err != nil { - glog.Errorf(models.ErrDBQueryFailed, models.AdunitConfigQuery, pubID, profileID, err) return err } diff --git a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go index 5c6cd1cdfa4..fa938ead1af 100644 --- a/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go +++ b/modules/pubmatic/openwrap/cache/gocache/slot_mappings.go @@ -29,7 +29,6 @@ func (c *cache) populateCacheWithPubSlotNameHash(pubID int) (err error) { func (c *cache) populateCacheWithWrapperSlotMappings(pubID int, partnerConfigMap map[int]map[string]string, profileID, displayVersion int) error { partnerSlotMappingMap, err := c.db.GetWrapperSlotMappings(partnerConfigMap, profileID, displayVersion) if err != nil { - glog.Errorf(models.ErrDBQueryFailed, models.WrapperSlotMappingsQuery+"/"+models.WrapperLiveVersionSlotMappings, pubID, profileID, err) return err } From fabc657b72d0203b4cc0433f40f7b79c1d11c7b7 Mon Sep 17 00:00:00 2001 From: Priyanka Bagade Date: Tue, 26 Nov 2024 11:26:39 +0530 Subject: [PATCH 16/16] resolved comments --- modules/pubmatic/openwrap/cache/gocache/adpod_config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go index 436dc9e94d7..b152a60de7b 100644 --- a/modules/pubmatic/openwrap/cache/gocache/adpod_config.go +++ b/modules/pubmatic/openwrap/cache/gocache/adpod_config.go @@ -16,7 +16,8 @@ func (c *cache) populateCacheWithAdpodConfig(pubID, profileID, displayVersion in if err != nil { if errors.Is(err, sql.ErrNoRows) { c.metricEngine.RecordDBQueryFailure(models.LiveVersionInnerQuery, strconv.Itoa(pubID), strconv.Itoa(profileID)) - c.cache.Set(cacheKey, adpodConfig, getSeconds(c.cfg.CacheDefaultExpiry)) + } else { + c.metricEngine.RecordDBQueryFailure(models.GetAdpodConfig, strconv.Itoa(pubID), strconv.Itoa(profileID)) } glog.Errorf(models.ErrDBQueryFailed, models.GetAdpodConfig, pubID, profileID, err) return err @@ -40,7 +41,6 @@ func (c *cache) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodconf if err := c.LockAndLoad(lockKey, func() error { return c.populateCacheWithAdpodConfig(pubID, profileID, displayVersion) }); err != nil { - c.metricEngine.RecordDBQueryFailure(models.GetAdpodConfig, strconv.Itoa(pubID), strconv.Itoa(profileID)) return nil, err }