Trim tag keys, and prevent duplicate tag keys (#2043)

This pull request addresses issue #2043.
* trims extra whitespace from tag keys
* prevents duplicate tag keys

The duplicate check will add a numeric suffix to the tag key (e.g. 'name_1') if a conflict is detected. This is a little friendlier than the old code which just wipes out the existing key-value if the user accidentally tries to enter a tag key that is already used.