kutuluk / loglevel-plugin-remote

A loglevel plugin for sending browser logs to a server
MIT License
102 stars 36 forks source link

Add backoff strategy and max queue size #4

Closed Looooopy closed 6 years ago

Looooopy commented 6 years ago

Problem before:

  1. If the logserver goes down the client keeps sending requests with an interval of 0ms, resulting in unnecessary network traffic and a performance hit on the client.
  2. The message queue grows on the client when the logserver is down and we do not want the browser to crash or become unresponsive.

Our Solution:

  1. Add a support for using a backoff strategy. We start on an interval of 1ms and the interval is doubled with each failed attempt until we reach an interval of 30s. Requests are then continiously made in 30s intervals. Unpon a successful request the interval is reset to 1ms.
  2. Add a max queue size. We set a default max queue size of 500 items. When the queue’s max size is reached we start dropping the oldest message in queue before pushing a new one onto the queue. So in case of a logserver outage, only the 500 most recent messages (stored in the queue of the the client) will be sent to the logserver once it becomes available again. 2.1 Add ability to do something with dropped messages in a callback function, e.g) (msg) => console.log(msg)
Looooopy commented 6 years ago

We know that you merged our previous pull request.

Let us know if you need us to rebase our new pull request with the changes you made!

kutuluk commented 6 years ago

No need =)

kutuluk commented 6 years ago

2.1 Add ability to do something with dropped messages in a callback function, e.g) (msg) => console.log(msg)

console.log(msg) will be called in any case by the loglevel. Is it really necessary to have an onMessageDropped handler? I just do not want to complicate the API without the urgent need.