Merge pull request #8842 from ctiller/metadata_filter

Metadata handling rewrite