NervesHubLink.Extensions.ErrorReports.Collector (nerves_hub_link v2.14.0)

Copy Markdown View Source

Holds the device's error reports until the extension sends them.

Runs from application start, not from the extension being attached. A crash during boot is the one an operator most wants, and by the time NervesHub has decided it wants error reports at all, it is long gone.

The bound

A supervisor restart storm produces reports faster than they can be sent, and a device the platform never attaches keeps crashing regardless. So this holds a fixed number and drops the oldest past it, counting what went. The count goes out as a report of its own ahead of the survivors, because a gap someone can see beats a gap they cannot.

Where the reports come from

A :logger handler, which runs in the process that crashed. Everything it does is a send/2 to this process: anything slower would charge the application for the reporting, and anything that logs would recurse.

Summary

Functions

Returns a specification to start this module under a supervisor.

How many reports are waiting, the drop notice included.

Forget the first count reports take/1 returned, now that they have gone.

Start collecting.

The next reports to send, oldest first, at most max of them.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

count()

@spec count() :: non_neg_integer()

How many reports are waiting, the drop notice included.

sent(count)

@spec sent(non_neg_integer()) :: :ok

Forget the first count reports take/1 returned, now that they have gone.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start collecting.

Options

take(max)

The next reports to send, oldest first, at most max of them.

Left where they are. Paired with sent/1 rather than handing them over, because a push can fail, and reports taken out of here and then not sent are exactly what this exists to prevent.