Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into refactoring-functional-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/test/groovy/org/prebid/server/functional/tests/AmpFpdSpec.groovy
  • Loading branch information
osulzhenko committed Jan 14, 2025
2 parents c6ddf01 + 579de03 commit f10db31
Show file tree
Hide file tree
Showing 67 changed files with 2,533 additions and 931 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/code-path-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Notify Code Path Changes

on:
pull_request:
types: [opened, synchronize]
paths:
- '**'

env:
OAUTH2_CLIENT_ID: ${{ secrets.OAUTH2_CLIENT_ID }}
OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }}
OAUTH2_REFRESH_TOKEN: ${{ secrets.OAUTH2_REFRESH_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: npm install axios nodemailer

- name: Run Notification Script
run: |
node .github/workflows/scripts/send-notification-on-change.js
1 change: 1 addition & 0 deletions .github/workflows/pr-java-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
with:
distribution: 'temurin'
cache: 'maven'
cache-dependency-path: extra/pom.xml
java-version: ${{ matrix.java }}

- name: Build with Maven
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/scripts/codepath-notification
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# when a changed file paths matches the regex, send an alert email
# structure of the file is:
#
# javascriptRegex : email address
#
# For example, in PBS Java, there are many paths that can belong to bid adapter:
#
# /src/main/java/org/prebid/server/bidder/BIDDER
# /src/main/resources/static/bidder-params/BIDDER.json
# /src/main/resources/bidder-config/BIDDER.yaml
# /src//main/java/org/prebid/server/proto/openrtb/ext/request/BIDDER
# /src/test/resources/org/prebid/server/it/openrtb2/BIDDER
# /src/test/java/org/prebid/server/it/BIDDERTest.java
# /src/test/java/org/prebid/server/bidder/BIDDER
# /src/main/java/org/prebid/server/spring/config/bidder/BIDDERConfiguration.java
#
# The aim is to find a minimal set of regex patterns that matches any file in these paths

/ix|Ix|ix.json|ix.yaml: [email protected]
139 changes: 139 additions & 0 deletions .github/workflows/scripts/send-notification-on-change.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// send-notification-on-change.js
//
// called by the code-path-changes.yml workflow, this script queries github for
// the changes in the current PR, checkes the config file for whether any of those
// file paths are set to alert an email address, and sends email to multiple
// parties if needed

const fs = require('fs');
const path = require('path');
const axios = require('axios');
const nodemailer = require('nodemailer');

async function getAccessToken(clientId, clientSecret, refreshToken) {
try {
const response = await axios.post('https://oauth2.googleapis.com/token', {
client_id: clientId,
client_secret: clientSecret,
refresh_token: refreshToken,
grant_type: 'refresh_token',
});
return response.data.access_token;
} catch (error) {
console.error('Failed to fetch access token:', error.response?.data || error.message);
process.exit(1);
}
}

(async () => {
const configFilePath = path.join(__dirname, 'codepath-notification');
const repo = process.env.GITHUB_REPOSITORY;
const prNumber = process.env.GITHUB_PR_NUMBER;
const token = process.env.GITHUB_TOKEN;

// Generate OAuth2 access token
const clientId = process.env.OAUTH2_CLIENT_ID;
const clientSecret = process.env.OAUTH2_CLIENT_SECRET;
const refreshToken = process.env.OAUTH2_REFRESH_TOKEN;

// validate params
if (!repo || !prNumber || !token || !clientId || !clientSecret || !refreshToken) {
console.error('Missing required environment variables.');
process.exit(1);
}

// the whole process is in a big try/catch. e.g. if the config file doesn't exist, github is down, etc.
try {
// Read and process the configuration file
const configFileContent = fs.readFileSync(configFilePath, 'utf-8');
const configRules = configFileContent
.split('\n')
.filter(line => line.trim() !== '' && !line.trim().startsWith('#')) // Ignore empty lines and comments
.map(line => {
const [regex, email] = line.split(':').map(part => part.trim());
return { regex: new RegExp(regex), email };
});

// Fetch changed files from github
const [owner, repoName] = repo.split('/');
const apiUrl = `https://api.github.com/repos/${owner}/${repoName}/pulls/${prNumber}/files`;
const response = await axios.get(apiUrl, {
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/vnd.github.v3+json',
},
});

const changedFiles = response.data.map(file => file.filename);
console.log('Changed files:', changedFiles);

// match file pathnames that are in the config and group them by email address
const matchesByEmail = {};
changedFiles.forEach(file => {
configRules.forEach(rule => {
if (rule.regex.test(file)) {
if (!matchesByEmail[rule.email]) {
matchesByEmail[rule.email] = [];
}
matchesByEmail[rule.email].push(file);
}
});
});

// Exit successfully if no matches were found
if (Object.keys(matchesByEmail).length === 0) {
console.log('No matches found. Exiting successfully.');
process.exit(0);
}

console.log('Grouped matches by email:', matchesByEmail);

// get ready to email the changes
const accessToken = await getAccessToken(clientId, clientSecret, refreshToken);

// Configure Nodemailer with OAuth2
// service: 'Gmail',
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: '[email protected]',
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
accessToken: accessToken
},
});

// Send one email per recipient
for (const [email, files] of Object.entries(matchesByEmail)) {
const emailBody = `
${email},
<p>
Files owned by you have been changed in open source ${repo}. The <a href="https://github.com/${repo}/pull/${prNumber}">pull request is #${prNumber}</a>. These are the files you own that have been modified:
<ul>
${files.map(file => `<li>${file}</li>`).join('')}
</ul>
`;

try {
await transporter.sendMail({
from: `"Prebid Info" <[email protected]>`,
to: email,
subject: `Files have been changed in open source ${repo}`,
html: emailBody,
});

console.log(`Email sent successfully to ${email}`);
console.log(`${emailBody}`);
} catch (error) {
console.error(`Failed to send email to ${email}:`, error.message);
}
}
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
})();
1 change: 1 addition & 0 deletions docs/config-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ There are several typical keys:
- `adapters.<BIDDER_NAME>.usersync.type` - usersync type (i.e. redirect, iframe).
- `adapters.<BIDDER_NAME>.usersync.support-cors` - flag signals if CORS supported by usersync.
- `adapters.<BIDDER_NAME>.debug.allow` - enables debug output in the auction response for the given bidder. Default `true`.
- `adapters.<BIDDER_NAME>.tmax-deduction-ms` - adjusts the tmax sent to the bidder by deducting the provided value (ms). Default `0 ms` - no deduction.

In addition, each bidder could have arbitrary aliases configured that will look and act very much the same as the bidder itself.
Aliases are configured by adding child configuration object at `adapters.<BIDDER_NAME>.aliases.<BIDDER_ALIAS>.`, aliases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ private static BidderInfo bidderInfo(OrtbVersion ortbVersion) {
false,
false,
null,
Ortb.of(false));
Ortb.of(false),
0L);
}

private static BidRequest emptyRequest() {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/prebid/server/auction/BidderAliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ public boolean isAliasDefined(String alias) {
}

public String resolveBidder(String aliasOrBidder) {
return aliasToBidder.getOrDefault(aliasOrBidder, aliasOrBidder);
return bidderCatalog.isValidName(aliasOrBidder)
? aliasOrBidder
: aliasToBidder.getOrDefault(aliasOrBidder, aliasOrBidder);
}

public boolean isSame(String bidder1, String bidder2) {
return StringUtils.equalsIgnoreCase(resolveBidder(bidder1), resolveBidder(bidder2));
}

public Integer resolveAliasVendorId(String alias) {
return aliasToVendorId.containsKey(alias)
? aliasToVendorId.get(alias)
: resolveAliasVendorIdViaCatalog(alias);
final Integer vendorId = resolveAliasVendorIdViaCatalog(alias);
return vendorId == null ? aliasToVendorId.get(alias) : vendorId;
}

private Integer resolveAliasVendorIdViaCatalog(String alias) {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/org/prebid/server/auction/ExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,7 @@ private Future<BidderResponse> requestBids(BidderRequest bidderRequest,
final String bidderName = bidderRequest.getBidder();
final String resolvedBidderName = aliases.resolveBidder(bidderName);
final Bidder<?> bidder = bidderCatalog.bidderByName(resolvedBidderName);
final long bidderTmaxDeductionMs = bidderCatalog.bidderInfoByName(resolvedBidderName).getTmaxDeductionMs();
final BidRejectionTracker bidRejectionTracker = auctionContext.getBidRejectionTrackers().get(bidderName);

final TimeoutContext timeoutContext = auctionContext.getTimeoutContext();
Expand All @@ -1225,7 +1226,8 @@ private Future<BidderResponse> requestBids(BidderRequest bidderRequest,
final long bidderRequestStartTime = clock.millis();

return Future.succeededFuture(bidderRequest.getBidRequest())
.map(bidRequest -> adjustTmax(bidRequest, auctionStartTime, adjustmentFactor, bidderRequestStartTime))
.map(bidRequest -> adjustTmax(
bidRequest, auctionStartTime, adjustmentFactor, bidderRequestStartTime, bidderTmaxDeductionMs))
.map(bidRequest -> ortbVersionConversionManager.convertFromAuctionSupportedVersion(
bidRequest, bidderRequest.getOrtbVersion()))
.map(bidderRequest::with)
Expand All @@ -1240,9 +1242,16 @@ private Future<BidderResponse> requestBids(BidderRequest bidderRequest,
.map(seatBid -> BidderResponse.of(bidderName, seatBid, responseTime(bidderRequestStartTime)));
}

private BidRequest adjustTmax(BidRequest bidRequest, long startTime, int adjustmentFactor, long currentTime) {
private BidRequest adjustTmax(BidRequest bidRequest,
long startTime,
int adjustmentFactor,
long currentTime,
long bidderTmaxDeductionMs) {

final long tmax = timeoutResolver.limitToMax(bidRequest.getTmax());
final long adjustedTmax = timeoutResolver.adjustForBidder(tmax, adjustmentFactor, currentTime - startTime);
final long adjustedTmax = timeoutResolver.adjustForBidder(
tmax, adjustmentFactor, currentTime - startTime, bidderTmaxDeductionMs);

return tmax != adjustedTmax
? bidRequest.toBuilder().tmax(adjustedTmax).build()
: bidRequest;
Expand Down
Loading

0 comments on commit f10db31

Please sign in to comment.