How to get allocation version from a stream?

The Nomad stream does not transfer job version in allocations because that information is explicitly removed in the source code before sending.

Assuming I am observing everything from Nomad stream - allocations, deployments, evaluations and job updates about a specific job - how do I get the job version of an allocation?

An allocation has EvalID, so I can find evaluation. However, some evaluations do not have JobModifyIndex and some have JobModifyIndex equal to 0 (??). Is it quaranteed that every evaluation has DeploymentID? Then I could do:
deployments[evaluations[allocation.EvalID].DeploymentID].JobVersion. Is this the preferred way?

There may be no deployment of an evaluation in case evaluation results from a user action. The actual logic I ended up with, is:

  • use allocation.JobVersion if exists
  • if deployments[evaluations[allocation.EvalID]] exists, use it’s JobVersion
  • otherwise, take evaluations[allocation.EvalID].JobModifyIndex and find the job version associated with that job modify index.

This assumes that we have cached all job versions and deployments and evaluations of a job.