Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

U0E-10990: Log error when a partial read of any DB Query. #932

Merged
merged 26 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6fe26cc
error for partial read of query
pm-priyanka-bagade Oct 4, 2024
de78de3
resolved error
pm-priyanka-bagade Oct 4, 2024
98ae508
added glog at cache level
pm-priyanka-bagade Oct 10, 2024
fd74284
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Oct 10, 2024
5187ff0
added glog
pm-priyanka-bagade Oct 21, 2024
ef486fb
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Oct 21, 2024
dbf2298
resolved all comments
pm-priyanka-bagade Oct 22, 2024
81f382f
fixed UT
pm-priyanka-bagade Oct 24, 2024
6d636de
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Oct 24, 2024
d6a4b4e
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Nov 6, 2024
8957e84
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Nov 6, 2024
6af358e
resolved comments
pm-priyanka-bagade Nov 6, 2024
e2abc6f
formatted error log
pm-priyanka-bagade Nov 7, 2024
21cc349
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Nov 7, 2024
7f077d4
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Nov 17, 2024
0ac7132
returned query specific error
pm-priyanka-bagade Nov 17, 2024
c1e8a61
wrapped error
pm-priyanka-bagade Nov 19, 2024
45da947
cached for ErrNoRows
pm-priyanka-bagade Nov 19, 2024
3f2491c
added assertion on error
pm-priyanka-bagade Nov 20, 2024
f074861
resolved comments
pm-priyanka-bagade Nov 21, 2024
1caf3d2
changed logic
pm-priyanka-bagade Nov 22, 2024
22a9559
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Nov 22, 2024
0b9bd69
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Nov 25, 2024
48dc8e5
resolved comments
pm-priyanka-bagade Nov 25, 2024
fabc657
resolved comments
pm-priyanka-bagade Nov 26, 2024
a7b925b
Merge branch 'ci' into UOE-10990-NEW
pm-priyanka-bagade Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +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)
return result, err
return result, errors.New("invalid profile data")
}

if rCtx.IsCTVRequest && rCtx.Endpoint == models.EndpointJson {
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/beforevalidationhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3858,7 +3858,7 @@ 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: true,
nilCurrencyConversion: true,
Expand Down
12 changes: 10 additions & 2 deletions modules/pubmatic/openwrap/cache/gocache/adpod_config.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package gocache

import (
"database/sql"
"errors"
"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"
)

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) {
Pubmatic-Dhruv-Sonone marked this conversation as resolved.
Show resolved Hide resolved
c.metricEngine.RecordDBQueryFailure(models.LiveVersionInnerQuery, strconv.Itoa(pubID), strconv.Itoa(profileID))
} else {
c.metricEngine.RecordDBQueryFailure(models.GetAdpodConfig, strconv.Itoa(pubID), strconv.Itoa(profileID))
}
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
}
Expand All @@ -32,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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gocache
import (
"fmt"

"github.com/golang/glog"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

Expand All @@ -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(models.ErrDBQueryFailed, models.AppIntegrationPathMapQuery, "", "", err)
return appIntegrationPathMap, fmt.Errorf(errorAppIntegrationPathMapUpdate, err)
}
return appIntegrationPathMap, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gocache
import (
"fmt"

"github.com/golang/glog"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

Expand All @@ -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(models.ErrDBQueryFailed, models.AppSubIntegrationPathMapQuery, "", "", err)
return appSubIntegrationPathMap, fmt.Errorf(errorAppSubIntegrationPathMapUpdate, err)
}
return appSubIntegrationPathMap, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gocache
import (
"fmt"

"github.com/golang/glog"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

Expand All @@ -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(models.ErrDBQueryFailed, models.AllDspFscPcntQuery, "", "", err)
return fscThreshold, fmt.Errorf(errorFscDspMsg, err)
}
return fscThreshold, nil
Expand Down
16 changes: 13 additions & 3 deletions modules/pubmatic/openwrap/cache/gocache/partner_config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package gocache

import (
"database/sql"
"errors"
"fmt"
"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"
)
Expand Down Expand Up @@ -67,13 +69,19 @@ 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 {
c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID))
return
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))
}
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)
Expand All @@ -83,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
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gocache
import (
"fmt"

"github.com/golang/glog"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

Expand All @@ -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(models.ErrDBQueryFailed, models.ProfileTypePlatformMapQuery, "", "", err)
return profileTypePlatformMap, fmt.Errorf(errorProfileTypePlatformMapUpdate, err)
}
return profileTypePlatformMap, nil
Expand Down
2 changes: 2 additions & 0 deletions modules/pubmatic/openwrap/cache/gocache/publisher_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gocache
import (
"fmt"

"github.com/golang/glog"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

Expand All @@ -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(models.ErrDBQueryFailed, models.PublisherFeatureMapQuery, "", "", err)
return publisherFeatureMap, fmt.Errorf(errorPubFeatureUpdate, err)
}
return publisherFeatureMap, nil
Expand Down
8 changes: 8 additions & 0 deletions modules/pubmatic/openwrap/cache/gocache/slot_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -15,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(models.ErrDBQueryFailed, models.SlotNameHash, pubID, "", err)
return
}
//This call may set nil publisherSlotNameHashMap in cache
c.cache.Set(cacheKey, publisherSlotNameHashMap, getSeconds(c.cfg.CacheDefaultExpiry))
return
Expand All @@ -23,6 +28,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 {
return err
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
}

//put a version level dummy entry in cache denoting mappings are present for this version
cacheKey := key(PUB_SLOT_INFO, pubID, profileID, displayVersion, 0)
Expand Down
25 changes: 17 additions & 8 deletions modules/pubmatic/openwrap/cache/gocache/slot_mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,6 +70,7 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) {
want: want{
publisherSlotNameHashMap: nil,
err: fmt.Errorf("Error from the DB"),
foundCacheKey: false,
},
},
{
Expand All @@ -93,6 +95,7 @@ func Test_cache_populateCacheWithPubSlotNameHash(t *testing.T) {
publisherSlotNameHashMap: map[string]string{
testSlotName: testHashValue,
},
foundCacheKey: true,
},
},
{
Expand All @@ -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,
},
},
}
Expand All @@ -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)
})
}
Expand All @@ -157,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
Expand Down Expand Up @@ -186,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,
},
},
{
Expand All @@ -211,6 +217,7 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) {
want: want{
partnerSlotMapping: map[string]models.SlotMapping{},
err: nil,
foundCacheKey: true,
},
},
{
Expand Down Expand Up @@ -261,7 +268,8 @@ func Test_cache_populateCacheWithWrapperSlotMappings(t *testing.T) {
OrderID: 0,
},
},
err: nil,
err: nil,
foundCacheKey: true,
},
},
{
Expand Down Expand Up @@ -295,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,
Expand Down Expand Up @@ -331,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)

})
Expand Down
6 changes: 2 additions & 4 deletions modules/pubmatic/openwrap/cache/gocache/vast_tags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gocache

import (
"github.com/golang/glog"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

Expand All @@ -11,13 +12,10 @@ 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.ErrDBQueryFailed, models.PublisherVASTTagsQuery, pubID, "", err)
return err
}

if publisherVASTTags == nil {
publisherVASTTags = models.PublisherVASTTags{}
}

c.cache.Set(cacheKey, publisherVASTTags, getSeconds(c.cfg.VASTTagCacheExpiry))
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/cache/gocache/vast_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Test_cache_populatePublisherVASTTags(t *testing.T) {
want: want{
cacheEntry: true,
err: nil,
PublisherVASTTags: models.PublisherVASTTags{},
PublisherVASTTags: models.PublisherVASTTags(nil),
},
},
}
Expand Down
Loading
Loading