diff --git a/source/server/http/admin.cc b/source/server/http/admin.cc index 0049da8be99ee..6cb19190dc222 100644 --- a/source/server/http/admin.cc +++ b/source/server/http/admin.cc @@ -441,7 +441,7 @@ std::string PrometheusStatsFormatter::sanitizeName(const std::string& name) { std::string PrometheusStatsFormatter::formattedTags(const std::vector& tags) { std::vector buf; for (const Stats::Tag& tag : tags) { - buf.push_back(fmt::format("{}=\"{}\"", sanitizeName(tag.name_), tag.value_)); + buf.push_back(fmt::format("{}=\"{}\"", sanitizeName(tag.name_), sanitizeName(tag.value_))); } return StringUtil::join(buf, ","); } diff --git a/test/server/http/admin_test.cc b/test/server/http/admin_test.cc index a2ee1f35d0fe4..a9ce5d3a3e918 100644 --- a/test/server/http/admin_test.cc +++ b/test/server/http/admin_test.cc @@ -377,12 +377,13 @@ TEST(PrometheusStatsFormatter, MetricName) { } TEST(PrometheusStatsFormatter, FormattedTags) { + // If value has - then it should be replaced by _ . std::vector tags; Stats::Tag tag1 = {"a.tag-name", "a.tag-value"}; - Stats::Tag tag2 = {"another_tag_name", "another_tag-value"}; + Stats::Tag tag2 = {"another_tag_name", "another.tag-value"}; tags.push_back(tag1); tags.push_back(tag2); - std::string expected = "a_tag_name=\"a.tag-value\",another_tag_name=\"another_tag-value\""; + std::string expected = "a_tag_name=\"a_tag_value\",another_tag_name=\"another_tag_value\""; auto actual = PrometheusStatsFormatter::formattedTags(tags); EXPECT_EQ(expected, actual); }