From aa115afbaa765b95f29ffb346f22c054d18f74d1 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Tue, 11 Jul 2023 10:52:44 +0200 Subject: [PATCH] Loki: Reset `data.js` after PR (#71328) reset data.js --- devenv/docker/blocks/loki/data/data.js | 30 ++++++++------------------ 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/devenv/docker/blocks/loki/data/data.js b/devenv/docker/blocks/loki/data/data.js index 9cae56328b3..b08a494ef4e 100644 --- a/devenv/docker/blocks/loki/data/data.js +++ b/devenv/docker/blocks/loki/data/data.js @@ -170,45 +170,33 @@ async function sendOldLogs() { const delays = calculateDelays(DAYS * POINTS_PER_DAY); const timeRange = DAYS * 24 * 60 * 60 * 1000; let timestampMs = new Date().getTime() - timeRange; - for (let i = 0; i < delays.length; i++) { // i cannot do a forEach because of the `await` inside + for(let i =0; i < delays.length; i++ ) { // i cannot do a forEach because of the `await` inside const delay = delays[i]; timestampMs += Math.trunc(delay * timeRange); const timestampNs = `${timestampMs}${getRandomNanosecPart()}`; globalCounter += 1; const item = getRandomLogItem(globalCounter) - await lokiSendLogLine(timestampNs, JSON.stringify(item), { age: 'old', place: 'moon', ...sharedLabels }); - await lokiSendLogLine(timestampNs, logFmtLine(item), { age: 'old', place: 'luna', ...sharedLabels }); + await lokiSendLogLine(timestampNs, JSON.stringify(item), {age:'old', place:'moon', ...sharedLabels}); + await lokiSendLogLine(timestampNs, logFmtLine(item), {age:'old', place:'luna', ...sharedLabels}); }; } async function sendNewLogs() { - while (true) { + while(true) { globalCounter += 1; const nowMs = new Date().getTime(); - const rnd = Math.random() - const ns = Math.trunc(rnd * 1000000).toString().padStart(6, '0'); - const ns1 = Math.trunc((rnd * 1000000)+1).toString().padStart(6, '0'); - const ns2 = Math.trunc((rnd * 1000000)+2).toString().padStart(6, '0'); - - const timestampNs = `${nowMs}${ns}`; - const timestampNs1 = `${nowMs}${ns1}`; - const timestampNs2 = `${nowMs}${ns2}`; - + const timestampNs = `${nowMs}${getRandomNanosecPart()}`; const item = getRandomLogItem(globalCounter) - - await lokiSendLogLine(timestampNs, JSON.stringify(item), { time: 'ns', age: 'new', place: 'moon', ...sharedLabels }); - await lokiSendLogLine(timestampNs1, JSON.stringify(item), { time: 'ns', age: 'new', place: 'moon', ...sharedLabels }); - await lokiSendLogLine(timestampNs2, JSON.stringify(item), { time: 'ns', age: 'new', place: 'moon', ...sharedLabels }); - - const sleepDuration = 200 + Math.random() * 800; // between 0.2 and 1 seconds + await lokiSendLogLine(timestampNs, JSON.stringify(item), {age:'new', place:'moon', ...sharedLabels}); + await lokiSendLogLine(timestampNs, logFmtLine(item), {age:'new', place:'luna', ...sharedLabels}); + const sleepDuration = 200 + Math.random() * 800; // between 0.2 and 1 seconds await sleep(sleepDuration); - process.exit(0); } } async function main() { // we generate both old-logs and new-logs at the same time - await Promise.all([sendNewLogs()]) + await Promise.all([sendOldLogs(), sendNewLogs()]) } // when running in docker, we catch the needed stop-signal, to shutdown fast