[BZ 1092756] check for invalid max and update it with the avg

We also log a warning to indicate that we have come across an invalid metric.
We then update and persist the max.