forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* blocking by creative ids * update blocking list
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
blocking "github.com/ParticleMedia/msp/pkg/modules/blocking/module" | ||
"github.com/prebid/prebid-server/modules/moduledeps" | ||
) | ||
|
||
type builder struct{} | ||
|
||
func (b builder) Build(rawConfig json.RawMessage, deps moduledeps.ModuleDeps) (interface{}, error) { | ||
return blocking.New(), nil | ||
} | ||
|
||
var Builder builder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package blocking | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/prebid/prebid-server/adapters" | ||
"github.com/prebid/prebid-server/hooks/hookstage" | ||
) | ||
|
||
func handleRawBidderResponseHook( | ||
creativeBlockingList map[string]int, | ||
payload hookstage.RawBidderResponsePayload, | ||
moduleCtx hookstage.ModuleContext, | ||
) (result hookstage.HookResult[hookstage.RawBidderResponsePayload], err error) { | ||
allowedBids := make([]*adapters.TypedBid, 0) | ||
for _, bid := range payload.Bids { | ||
if _, ok := creativeBlockingList[bid.Bid.CrID]; !ok { | ||
allowedBids = append(allowedBids, bid) | ||
} else if time.Now().Second()%100 < 20 { | ||
fmt.Printf("blocking by createive id: %s, bidder: %s, sampled adm: %s \n", bid.Bid.CrID, payload.Bidder, bid.Bid.AdM) | ||
} | ||
} | ||
|
||
changeSet := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{} | ||
if len(payload.Bids) != len(allowedBids) { | ||
changeSet.RawBidderResponse().Bids().Update(allowedBids) | ||
result.ChangeSet = changeSet | ||
} | ||
|
||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package blocking | ||
|
||
import ( | ||
"context" | ||
"encoding/csv" | ||
"log" | ||
"os" | ||
|
||
"github.com/golang/glog" | ||
"github.com/prebid/prebid-server/hooks/hookstage" | ||
) | ||
|
||
const ( | ||
blocking_creative_file_path = "./static/blocking_creatives.csv" | ||
) | ||
|
||
type Module struct { | ||
creativeBlockingList map[string]int | ||
} | ||
|
||
func New() *Module { | ||
return &Module{ | ||
creativeBlockingList: parseBlockingCreativeMap(blocking_creative_file_path), | ||
} | ||
} | ||
|
||
func parseBlockingCreativeMap(path string) map[string]int { | ||
f, err := os.Open(path) | ||
if err != nil { | ||
glog.Fatal("Unable to read input file "+path, err) | ||
} | ||
defer f.Close() | ||
|
||
csvReader := csv.NewReader(f) | ||
records, err := csvReader.ReadAll() | ||
if err != nil { | ||
log.Fatal("Unable to parse file as CSV for "+path, err) | ||
} | ||
|
||
result := map[string]int{} | ||
for _, col := range records { | ||
result[col[0]] = 1 | ||
} | ||
|
||
return result | ||
} | ||
|
||
func (m Module) HandleRawBidderResponseHook( | ||
_ context.Context, | ||
miCtx hookstage.ModuleInvocationContext, | ||
payload hookstage.RawBidderResponsePayload, | ||
) (hookstage.HookResult[hookstage.RawBidderResponsePayload], error) { | ||
return handleRawBidderResponseHook(m.creativeBlockingList, payload, miCtx.ModuleContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<adv>6bf6dff898144f7cb9326d1a1cd9029a<crid>4083164 | ||
4083164 |