Fix metric reading race conditions
What does this MR do?
Fixes several races that occur because we have different go routines writing and reading statuses (stage, state, executor state) from the job.
Why was this MR needed?
The prometheus metric collection reads this state periodically. We also need to guard these variables for !2342 (merged).
What's the best way to test this MR?
cd commands
go test -race -run TestBuildsHelperCollect
Without the mutexes in place, running this is sure to find a race condition. If you get lucky enough that it doesn't, pass -count 100
.
What are the relevant issue numbers?
closes #26787 (closed)