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

[7.x] [CSM] fix ingest data retry order messed up (#78163) #78405

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Changes from all commits
Commits
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
55 changes: 31 additions & 24 deletions x-pack/plugins/apm/e2e/ingest-data/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,40 @@ function incrementSpinnerCount({ success }) {
}
let iterIndex = 0;

function setItemMetaAndHeaders(item) {
const headers = {
'content-type': 'application/x-ndjson',
};

if (SECRET_TOKEN) {
headers.Authorization = `Bearer ${SECRET_TOKEN}`;
}

if (item.url === '/intake/v2/rum/events') {
if (iterIndex === userAgents.length) {
// set some event agent to opbean
setRumAgent(item);
iterIndex = 0;
}
headers['User-Agent'] = userAgents[iterIndex];
headers['X-Forwarded-For'] = userIps[iterIndex];
iterIndex++;
}
return headers;
}

function setRumAgent(item) {
item.body = item.body.replace(
'"name":"client"',
'"name":"opbean-client-rum"'
);
if (item.body) {
item.body = item.body.replace(
'"name":"client"',
'"name":"opbean-client-rum"'
);
}
}

async function insertItem(item) {
async function insertItem(item, headers) {
try {
const url = `${APM_SERVER_URL}${item.url}`;
const headers = {
'content-type': 'application/x-ndjson',
};

if (item.url === '/intake/v2/rum/events') {
if (iterIndex === userAgents.length) {
// set some event agent to opbean
setRumAgent(item);
iterIndex = 0;
}
headers['User-Agent'] = userAgents[iterIndex];
headers['X-Forwarded-For'] = userIps[iterIndex];
iterIndex++;
}

if (SECRET_TOKEN) {
headers.Authorization = `Bearer ${SECRET_TOKEN}`;
}

await axios({
method: item.method,
Expand Down Expand Up @@ -133,8 +139,9 @@ async function init() {
await Promise.all(
items.map(async (item) => {
try {
const headers = setItemMetaAndHeaders(item);
// retry 5 times with exponential backoff
await pRetry(() => limit(() => insertItem(item)), {
await pRetry(() => limit(() => insertItem(item, headers)), {
retries: 5,
});
incrementSpinnerCount({ success: true });
Expand Down