boynet / cf-logdna-worker

simple cloudflare worker recipe to send logs into logdna
The Unlicense
26 stars 6 forks source link

Worker Inception, Non Sequence Logging #4

Closed adaptive closed 6 years ago

adaptive commented 6 years ago

A Worker with the same inception had wrong chronological order when logging. Reporting, to understand if this phenomenon has occurred with other users.

screenshot 2018-10-26 at 19 51 03
boynet commented 6 years ago

I made a little changes to make it easy debugging it (I Still not seeing it happening):

workerInception = makeid();
...
data.line = workerInception + " " + data.meta.countryCode + " " + data.meta.ip + " " + data.meta.url;

...
function makeid() {
  var text = "";
  var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

  for (var i = 0; i < 5; i++)
    text += possible.charAt(Math.floor(Math.random() * possible.length));

  return text;
}

the makeid make it easier to see distinguish workers

adaptive commented 6 years ago

workerInception is good to understand the lifespan of a worker. workerId could be a go idea.

Something that crossed my mind was the possibility of two or more workers being born at the same time, to the millisecond precision.

I suggest something like this for ID based on your random function. I reduced the characters for easy ready.

function makeid(lenght) {
  let text = ''
  const possible = 'ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789'
  for (let i = 0; i < lenght ; i++)
    text += possible.charAt(Math.floor(Math.random() * possible.length));
  return text;
}

I will add a PR