Add COWMetric and do some code cleanups.

This is required for https://github.com/prometheus/prometheus/pull/420.