prometheus-community / pro-bing

A library for creating continuous probers
MIT License
309 stars 52 forks source link

Add support for OnSendError and OnRecvError handlers #44

Closed floatingstatic closed 1 year ago

floatingstatic commented 1 year ago

Following on to discussion in https://github.com/prometheus-community/pro-bing/pull/40#issuecomment-1563213985 I would like to propose an alternative based on comments from @SuperQ for adding send and receive packet error handlers.

For my own use case this would allow to optionally receive error signals in callback functions and terminate (pinger.Stop()) a running ping under certain error conditions without altering the behavior of this library in terms of its existing error handling (which is basically just logging the error and continuing at present). The only difference between the two error handlers is that OnSendError() sends both info for the packet that Pinger was attempting to send and the error that was returned, while OnRecvError() only sends the error. The reason for this is due to receive errors are generally related to packets that cannot be read and thus we do not have packet details, while in the sending case we have this information available. I'm open to renaming these functions to something like OnSendPacketError() if that makes it more obvious that we get packet details with that specific callback.