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 18 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
2 changes: 2 additions & 0 deletions modules/pubmatic/openwrap/cache/gocache/adpod_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ 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"
)

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.GetAdpodConfig, pubID, profileID, err)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
return err
}

Expand Down
3 changes: 3 additions & 0 deletions modules/pubmatic/openwrap/cache/gocache/adunit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ 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)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
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) 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
9 changes: 8 additions & 1 deletion 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,8 +69,13 @@ 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)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
}
c.metricEngine.RecordDBQueryFailure(models.PartnerConfigQuery, strconv.Itoa(pubID), strconv.Itoa(profileID))
return
glog.Errorf(models.ErrDBQueryFailed, models.PartnerConfigQuery, pubID, profileID, err)
return err
}

if len(partnerConfigMap) == 0 {
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
9 changes: 9 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 err
}
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
//This call may set nil publisherSlotNameHashMap in cache
c.cache.Set(cacheKey, publisherSlotNameHashMap, getSeconds(c.cfg.CacheDefaultExpiry))
return
Expand All @@ -23,6 +28,10 @@ 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(models.ErrDBQueryFailed, models.WrapperSlotMappingsQuery+"/"+models.WrapperLiveVersionSlotMappings, pubID, profileID, err)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 2 additions & 0 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,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(models.ErrDBQueryFailed, models.PublisherVASTTagsQuery, pubID, "", err)
return err
}

Expand Down
10 changes: 5 additions & 5 deletions modules/pubmatic/openwrap/database/mysql/adpod_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ package mysql
import (
"context"
"encoding/json"
"fmt"
"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"
)

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, fmt.Errorf("LiveVersionInnerQuery/DisplayVersionInnerQuery Failure Error: %w", err)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
}

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, err
return nil, fmt.Errorf("GetAdpodConfigQuery Failure Error: %w", err)
}
defer rows.Close()

Expand All @@ -49,12 +49,12 @@ func (db *mySqlDB) GetAdpodConfig(pubID, profileID, displayVersion int) (*adpodc
}

pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
return nil, fmt.Errorf("Unmarshal Error: %w", err)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
}
}

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, fmt.Errorf("Row scan Failure Error: %w", err)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
}

return config, nil
Expand Down
Loading
Loading