Skip to content

Commit

Permalink
Rename pbsmetrics to metrics (prebid#1624)
Browse files Browse the repository at this point in the history
  • Loading branch information
mansinahar authored and shunj-nb committed Nov 8, 2022
1 parent f815a36 commit 607973e
Show file tree
Hide file tree
Showing 54 changed files with 671 additions and 680 deletions.
4 changes: 2 additions & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
jsonpatch "github.com/evanphx/json-patch"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/pbsmetrics"
"github.com/prebid/prebid-server/metrics"
"github.com/prebid/prebid-server/stored_requests"
)

Expand All @@ -20,7 +20,7 @@ func GetAccount(ctx context.Context, cfg *config.Configuration, fetcher stored_r
Message: fmt.Sprintf("Prebid-server has disabled Account ID: %s, please reach out to the prebid server host.", accountID),
}}
}
if cfg.AccountRequired && accountID == pbsmetrics.PublisherUnknown {
if cfg.AccountRequired && accountID == metrics.PublisherUnknown {
return nil, []error{&errortypes.AcctRequired{
Message: fmt.Sprintf("Prebid-server has been configured to discard requests without a valid Account ID. Please reach out to the prebid server host."),
}}
Expand Down
4 changes: 2 additions & 2 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/pbsmetrics"
"github.com/prebid/prebid-server/metrics"
"github.com/prebid/prebid-server/stored_requests"
"github.com/stretchr/testify/assert"
)
Expand All @@ -29,7 +29,7 @@ func (af mockAccountFetcher) FetchAccount(ctx context.Context, accountID string)
}

func TestGetAccount(t *testing.T) {
unknown := pbsmetrics.PublisherUnknown
unknown := metrics.PublisherUnknown
testCases := []struct {
accountID string
// account_required
Expand Down
6 changes: 3 additions & 3 deletions adapters/appnexus/appnexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/metrics"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbsmetrics"
)

const defaultPlatformID int = 5
Expand Down Expand Up @@ -336,9 +336,9 @@ func (a *AppNexusAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *ada

// Add Appnexus request level extension
var isAMP, isVIDEO int
if reqInfo.PbsEntryPoint == pbsmetrics.ReqTypeAMP {
if reqInfo.PbsEntryPoint == metrics.ReqTypeAMP {
isAMP = 1
} else if reqInfo.PbsEntryPoint == pbsmetrics.ReqTypeVideo {
} else if reqInfo.PbsEntryPoint == metrics.ReqTypeVideo {
isVIDEO = 1
}

Expand Down
4 changes: 2 additions & 2 deletions adapters/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/golang/glog"
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/metrics"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbsmetrics"
yaml "gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -258,5 +258,5 @@ func parseBidderInfo(info BidderInfo) parsedBidderInfo {
}

type ExtraRequestInfo struct {
PbsEntryPoint pbsmetrics.RequestType
PbsEntryPoint metrics.RequestType
}
4 changes: 2 additions & 2 deletions adapters/invibes/invibes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/macros"
"github.com/prebid/prebid-server/metrics"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbsmetrics"
)

const adapterVersion = "prebid_1.0.0"
Expand Down Expand Up @@ -133,7 +133,7 @@ func (a *InvibesAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap
}
invibesInternalParams.TestLog = invibesExt.Debug.TestLog
}
if reqInfo.PbsEntryPoint == pbsmetrics.ReqTypeAMP {
if reqInfo.PbsEntryPoint == metrics.ReqTypeAMP {
invibesInternalParams.IsAMP = true
}

Expand Down
72 changes: 36 additions & 36 deletions endpoints/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/exchange"
"github.com/prebid/prebid-server/gdpr"
"github.com/prebid/prebid-server/metrics"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbs"
"github.com/prebid/prebid-server/pbsmetrics"
pbc "github.com/prebid/prebid-server/prebid_cache_client"
"github.com/prebid/prebid-server/privacy"
gdprPrivacy "github.com/prebid/prebid-server/privacy/gdpr"
Expand Down Expand Up @@ -60,12 +60,12 @@ type auction struct {
cfg *config.Configuration
syncers map[openrtb_ext.BidderName]usersync.Usersyncer
gdprPerms gdpr.Permissions
metricsEngine pbsmetrics.MetricsEngine
metricsEngine metrics.MetricsEngine
dataCache cache.Cache
exchanges map[string]adapters.Adapter
}

func Auction(cfg *config.Configuration, syncers map[openrtb_ext.BidderName]usersync.Usersyncer, gdprPerms gdpr.Permissions, metricsEngine pbsmetrics.MetricsEngine, dataCache cache.Cache, exchanges map[string]adapters.Adapter) httprouter.Handle {
func Auction(cfg *config.Configuration, syncers map[openrtb_ext.BidderName]usersync.Usersyncer, gdprPerms gdpr.Permissions, metricsEngine metrics.MetricsEngine, dataCache cache.Cache, exchanges map[string]adapters.Adapter) httprouter.Handle {
a := &auction{
cfg: cfg,
syncers: syncers,
Expand All @@ -89,7 +89,7 @@ func (a *auction) auction(w http.ResponseWriter, r *http.Request, _ httprouter.P
glog.Infof("Failed to parse /auction request: %v", err)
}
writeAuctionError(w, "Error parsing request", err)
labels.RequestStatus = pbsmetrics.RequestStatusBadInput
labels.RequestStatus = metrics.RequestStatusBadInput
return
}
status := "OK"
Expand All @@ -102,7 +102,7 @@ func (a *auction) auction(w http.ResponseWriter, r *http.Request, _ httprouter.P
glog.Infof("Invalid account id: %v", err)
}
writeAuctionError(w, "Unknown account id", fmt.Errorf("Unknown account"))
labels.RequestStatus = pbsmetrics.RequestStatusBadInput
labels.RequestStatus = metrics.RequestStatusBadInput
return
}
labels.PubID = req.AccountID
Expand All @@ -116,19 +116,19 @@ func (a *auction) auction(w http.ResponseWriter, r *http.Request, _ httprouter.P
for _, bidder := range req.Bidders {
if ex, ok := a.exchanges[bidder.BidderCode]; ok {
// Make sure we have an independent label struct for each bidder. We don't want to run into issues with the goroutine below.
blabels := pbsmetrics.AdapterLabels{
blabels := metrics.AdapterLabels{
Source: labels.Source,
RType: labels.RType,
Adapter: openrtb_ext.BidderName(bidder.BidderCode),
PubID: labels.PubID,
CookieFlag: labels.CookieFlag,
AdapterBids: pbsmetrics.AdapterBidPresent,
AdapterBids: metrics.AdapterBidPresent,
}
if skip := a.processUserSync(req, bidder, blabels, ex, &ctx); skip == true {
continue
}
sentBids++
bidderRunner := a.recoverSafely(func(bidder *pbs.PBSBidder, aLabels pbsmetrics.AdapterLabels) {
bidderRunner := a.recoverSafely(func(bidder *pbs.PBSBidder, aLabels metrics.AdapterLabels) {

start := time.Now()
bidList, err := ex.Call(ctx, req, bidder)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (a *auction) auction(w http.ResponseWriter, r *http.Request, _ httprouter.P
}
if err := cacheAccordingToMarkup(req, &resp, ctx, a, &labels); err != nil {
writeAuctionError(w, "Prebid cache failed", err)
labels.RequestStatus = pbsmetrics.RequestStatusErr
labels.RequestStatus = metrics.RequestStatusErr
return
}
if req.SortBids == 1 {
Expand All @@ -172,8 +172,8 @@ func (a *auction) auction(w http.ResponseWriter, r *http.Request, _ httprouter.P
enc.Encode(resp)
}

func (a *auction) recoverSafely(inner func(*pbs.PBSBidder, pbsmetrics.AdapterLabels)) func(*pbs.PBSBidder, pbsmetrics.AdapterLabels) {
return func(bidder *pbs.PBSBidder, labels pbsmetrics.AdapterLabels) {
func (a *auction) recoverSafely(inner func(*pbs.PBSBidder, metrics.AdapterLabels)) func(*pbs.PBSBidder, metrics.AdapterLabels) {
return func(bidder *pbs.PBSBidder, labels metrics.AdapterLabels) {
defer func() {
if r := recover(); r != nil {
if bidder == nil {
Expand Down Expand Up @@ -207,7 +207,7 @@ func (a *auction) shouldUsersync(ctx context.Context, bidder openrtb_ext.BidderN
}

// cache video bids only for Web
func cacheVideoOnly(bids pbs.PBSBidSlice, ctx context.Context, deps *auction, labels *pbsmetrics.Labels) error {
func cacheVideoOnly(bids pbs.PBSBidSlice, ctx context.Context, deps *auction, labels *metrics.Labels) error {
var cobjs []*pbc.CacheObject
for _, bid := range bids {
if bid.CreativeMediaType == "video" {
Expand Down Expand Up @@ -362,31 +362,31 @@ func sortBidsAddKeywordsMobile(bids pbs.PBSBidSlice, pbs_req *pbs.PBSRequest, pr
}
}

func getDefaultLabels(r *http.Request) pbsmetrics.Labels {
return pbsmetrics.Labels{
Source: pbsmetrics.DemandUnknown,
RType: pbsmetrics.ReqTypeLegacy,
func getDefaultLabels(r *http.Request) metrics.Labels {
return metrics.Labels{
Source: metrics.DemandUnknown,
RType: metrics.ReqTypeLegacy,
PubID: "",
CookieFlag: pbsmetrics.CookieFlagUnknown,
RequestStatus: pbsmetrics.RequestStatusOK,
CookieFlag: metrics.CookieFlagUnknown,
RequestStatus: metrics.RequestStatusOK,
}
}

func setLabelSource(labels *pbsmetrics.Labels, req *pbs.PBSRequest, status *string) {
func setLabelSource(labels *metrics.Labels, req *pbs.PBSRequest, status *string) {
if req.App != nil {
labels.Source = pbsmetrics.DemandApp
labels.Source = metrics.DemandApp
} else {
labels.Source = pbsmetrics.DemandWeb
labels.Source = metrics.DemandWeb
if req.Cookie.LiveSyncCount() == 0 {
labels.CookieFlag = pbsmetrics.CookieFlagNo
labels.CookieFlag = metrics.CookieFlagNo
*status = "no_cookie"
} else {
labels.CookieFlag = pbsmetrics.CookieFlagYes
labels.CookieFlag = metrics.CookieFlagYes
}
}
}

func cacheAccordingToMarkup(req *pbs.PBSRequest, resp *pbs.PBSResponse, ctx context.Context, a *auction, labels *pbsmetrics.Labels) error {
func cacheAccordingToMarkup(req *pbs.PBSRequest, resp *pbs.PBSResponse, ctx context.Context, a *auction, labels *metrics.Labels) error {
if req.CacheMarkup == 1 {
cobjs := make([]*pbc.CacheObject, len(resp.Bids))
for i, bid := range resp.Bids {
Expand Down Expand Up @@ -422,45 +422,45 @@ func cacheAccordingToMarkup(req *pbs.PBSRequest, resp *pbs.PBSResponse, ctx cont
return nil
}

func processBidResult(bidList pbs.PBSBidSlice, bidder *pbs.PBSBidder, aLabels *pbsmetrics.AdapterLabels, metrics pbsmetrics.MetricsEngine, err error) {
func processBidResult(bidList pbs.PBSBidSlice, bidder *pbs.PBSBidder, aLabels *metrics.AdapterLabels, metricsEngine metrics.MetricsEngine, err error) {
if err != nil {
var s struct{}
if err == context.DeadlineExceeded {
aLabels.AdapterErrors = map[pbsmetrics.AdapterError]struct{}{pbsmetrics.AdapterErrorTimeout: s}
aLabels.AdapterErrors = map[metrics.AdapterError]struct{}{metrics.AdapterErrorTimeout: s}
bidder.Error = "Timed out"
} else if err != context.Canceled {
bidder.Error = err.Error()
switch err.(type) {
case *errortypes.BadInput:
aLabels.AdapterErrors = map[pbsmetrics.AdapterError]struct{}{pbsmetrics.AdapterErrorBadInput: s}
aLabels.AdapterErrors = map[metrics.AdapterError]struct{}{metrics.AdapterErrorBadInput: s}
case *errortypes.BadServerResponse:
aLabels.AdapterErrors = map[pbsmetrics.AdapterError]struct{}{pbsmetrics.AdapterErrorBadServerResponse: s}
aLabels.AdapterErrors = map[metrics.AdapterError]struct{}{metrics.AdapterErrorBadServerResponse: s}
default:
glog.Warningf("Error from bidder %v. Ignoring all bids: %v", bidder.BidderCode, err)
aLabels.AdapterErrors = map[pbsmetrics.AdapterError]struct{}{pbsmetrics.AdapterErrorUnknown: s}
aLabels.AdapterErrors = map[metrics.AdapterError]struct{}{metrics.AdapterErrorUnknown: s}
}
}
} else if bidList != nil {
bidList = checkForValidBidSize(bidList, bidder)
bidder.NumBids = len(bidList)
for _, bid := range bidList {
var cpm = float64(bid.Price * 1000)
metrics.RecordAdapterPrice(*aLabels, cpm)
metricsEngine.RecordAdapterPrice(*aLabels, cpm)
switch bid.CreativeMediaType {
case "banner":
metrics.RecordAdapterBidReceived(*aLabels, openrtb_ext.BidTypeBanner, bid.Adm != "")
metricsEngine.RecordAdapterBidReceived(*aLabels, openrtb_ext.BidTypeBanner, bid.Adm != "")
case "video":
metrics.RecordAdapterBidReceived(*aLabels, openrtb_ext.BidTypeVideo, bid.Adm != "")
metricsEngine.RecordAdapterBidReceived(*aLabels, openrtb_ext.BidTypeVideo, bid.Adm != "")
}
bid.ResponseTime = bidder.ResponseTime
}
} else {
bidder.NoBid = true
aLabels.AdapterBids = pbsmetrics.AdapterBidNone
aLabels.AdapterBids = metrics.AdapterBidNone
}
}

func (a *auction) recordMetrics(req *pbs.PBSRequest, labels pbsmetrics.Labels) {
func (a *auction) recordMetrics(req *pbs.PBSRequest, labels metrics.Labels) {
a.metricsEngine.RecordRequest(labels)
if req == nil {
a.metricsEngine.RecordLegacyImps(labels, 0)
Expand All @@ -470,7 +470,7 @@ func (a *auction) recordMetrics(req *pbs.PBSRequest, labels pbsmetrics.Labels) {
a.metricsEngine.RecordRequestTime(labels, time.Since(req.Start))
}

func (a *auction) processUserSync(req *pbs.PBSRequest, bidder *pbs.PBSBidder, blabels pbsmetrics.AdapterLabels, ex adapters.Adapter, ctx *context.Context) bool {
func (a *auction) processUserSync(req *pbs.PBSRequest, bidder *pbs.PBSBidder, blabels metrics.AdapterLabels, ex adapters.Adapter, ctx *context.Context) bool {
var skip bool = false
if req.App != nil {
return skip
Expand Down Expand Up @@ -501,7 +501,7 @@ func (a *auction) processUserSync(req *pbs.PBSRequest, bidder *pbs.PBSBidder, bl
glog.Errorf("Failed to get usersync info for %s: %v", syncerCode, err)
}
}
blabels.CookieFlag = pbsmetrics.CookieFlagNo
blabels.CookieFlag = metrics.CookieFlagNo
if ex.SkipNoCookies() {
skip = true
}
Expand Down
10 changes: 5 additions & 5 deletions endpoints/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/prebid/prebid-server/cache/dummycache"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/gdpr"
"github.com/prebid/prebid-server/metrics"
metricsConf "github.com/prebid/prebid-server/metrics/config"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbs"
"github.com/prebid/prebid-server/pbsmetrics"
metricsConf "github.com/prebid/prebid-server/pbsmetrics/config"
"github.com/prebid/prebid-server/prebid_cache_client"
gdprPolicy "github.com/prebid/prebid-server/privacy/gdpr"
"github.com/prebid/prebid-server/usersync/usersyncers"
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestCacheVideoOnly(t *testing.T) {
HostVendorID: 0,
}, nil, nil)
prebid_cache_client.InitPrebidCache(server.URL)
var labels = &pbsmetrics.Labels{}
var labels = &metrics.Labels{}
if err := cacheVideoOnly(bids, ctx, &auction{cfg: cfg, syncers: syncers, gdprPerms: gdprPerms, metricsEngine: &metricsConf.DummyMetricsEngine{}}, labels); err != nil {
t.Errorf("Prebid cache failed: %v \n", err)
return
Expand Down Expand Up @@ -615,9 +615,9 @@ func TestPanicRecovery(t *testing.T) {
},
metricsEngine: &metricsConf.DummyMetricsEngine{},
}
panicker := func(bidder *pbs.PBSBidder, blables pbsmetrics.AdapterLabels) {
panicker := func(bidder *pbs.PBSBidder, blables metrics.AdapterLabels) {
panic("panic!")
}
recovered := dummy.recoverSafely(panicker)
recovered(nil, pbsmetrics.AdapterLabels{})
recovered(nil, metrics.AdapterLabels{})
}
6 changes: 3 additions & 3 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/prebid/prebid-server/analytics"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/gdpr"
"github.com/prebid/prebid-server/metrics"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbsmetrics"
"github.com/prebid/prebid-server/privacy"
"github.com/prebid/prebid-server/privacy/ccpa"
gdprPrivacy "github.com/prebid/prebid-server/privacy/gdpr"
Expand All @@ -28,7 +28,7 @@ func NewCookieSyncEndpoint(
syncers map[openrtb_ext.BidderName]usersync.Usersyncer,
cfg *config.Configuration,
syncPermissions gdpr.Permissions,
metrics pbsmetrics.MetricsEngine,
metrics metrics.MetricsEngine,
pbsAnalytics analytics.PBSAnalyticsModule,
bidderMap map[string]openrtb_ext.BidderName) httprouter.Handle {

Expand All @@ -55,7 +55,7 @@ type cookieSyncDeps struct {
hostCookie *config.HostCookie
gDPR *config.GDPR
syncPermissions gdpr.Permissions
metrics pbsmetrics.MetricsEngine
metrics metrics.MetricsEngine
pbsAnalytics analytics.PBSAnalyticsModule
enforceCCPA bool
bidderLookup map[string]struct{}
Expand Down
2 changes: 1 addition & 1 deletion endpoints/cookie_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
analyticsConf "github.com/prebid/prebid-server/analytics/config"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/gdpr"
metricsConf "github.com/prebid/prebid-server/metrics/config"
"github.com/prebid/prebid-server/openrtb_ext"
metricsConf "github.com/prebid/prebid-server/pbsmetrics/config"
"github.com/prebid/prebid-server/usersync"
"github.com/stretchr/testify/assert"
)
Expand Down
Loading

0 comments on commit 607973e

Please sign in to comment.