watermill icon indicating copy to clipboard operation
watermill copied to clipboard

Add a method which can be used to get the age of the oldest event in the queue

Open boreq opened this issue 2 years ago • 0 comments
trafficstars

I couldn't figure out how to do this easily in a reasonable way so I will describe it here in case someone has any ideas.

Currently there already exists a method Subscriber.QueueLength which allows users to get the number of events in a particular subscription. While this is normally enough to determine subscription health it doesn't always tell us the full picture. If a subscription gets a lot of traffic we may end up in the situation where the subscription always has events in it but the events are not stuck in the subscription, they are simply being added all the time and are consumed within seconds. In that case a more useful metric would be checking what the age of the oldest event in the subscription is. Currently there is no builtin way of doing this.

I thought about adding a method which would do this to the Subscriber but I don't really see how to do it in an elegant way. My idea was:

  • change the default marshaler to add createdAt fields when saving events
  • add a method to do this in Subscriber which would look at createdAt fields

The problem with this is that if someone uses a custom marshaler (which we enable them to do) this wouldn't work for them. And if we want to add those fields outside of the marshaler we may overwrite their own field.

If someone has thoughts on this let me know.

boreq avatar Jul 27 '23 15:07 boreq