Skip to content

Commit

Permalink
[CSM] fix ingest data retry order messed up (elastic#78163)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Sep 24, 2020
1 parent e581a75 commit 3747b34
Showing 1 changed file with 31 additions and 24 deletions.
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

0 comments on commit 3747b34

Please sign in to comment.