As the source code indicates, nomad only maintains the most recent 10 events for every task.
// defaultMaxEvents is the default max capacity for task events on the
// task state. Overrideable for testing.
defaultMaxEvents = 10
So, is there any way to get all the events of a task?
If i use the blocking query API
/v1/allocation/<allocationID>?index=<N>, i can get the task event set in most case.
However, is there a possibility that task events are produced too fast, and I call this api as soon as receving task events from last call, but more than 10 events have been produced, so some events are lost, that is, I cannot get them forever.
That’s right, Nomad only keeps the latest task events stored to avoid bloating its database. You can use the Event Stream to subscribe to the
Allocation topic and collect and store the events somewhere else that you can query later on.
Thanks for your response.
I remember the event stream requires for Nomad v1.0.0+. But I am still developing on v0.12.0. If I use it, I have to think about upgrading.
Yes, Event Streams is a 1.0 feature.
Unfortunately, without upgrading, you would have to manually track the list of jobs, then the list of allocations to collect their events…
I’ll implement it by myself through calling blocking query API with long polling.