[SPARK-3377] [Metrics] Metrics can be accidentally aggregated(Another solution)

This PR is another solution for #2250 

Closes #2250