Skip to content

Commit

Permalink
feat(core)!: remove nonstandard append mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gjasny committed Nov 14, 2021
1 parent 1b01f36 commit 3202b37
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
4 changes: 0 additions & 4 deletions core/include/prometheus/registry.h
Expand Up @@ -50,10 +50,6 @@ class PROMETHEUS_CPP_CORE_EXPORT Registry : public Collectable {
Merge,
/// \brief Throws if a family with the same name already exists.
Throw,
/// \brief Never merge and always create a new family. This violates the
/// prometheus specification but was the default behavior in earlier
/// versions
NonStandardAppend,
};

/// \brief name Create a new registry.
Expand Down
14 changes: 6 additions & 8 deletions core/src/registry.cc
Expand Up @@ -120,15 +120,13 @@ Family<T>& Registry::Add(const std::string& name, const std::string& help,
}
}

if (insert_behavior_ != InsertBehavior::NonStandardAppend) {
auto same_name = [&name](const std::unique_ptr<Family<T>>& family) {
return name == family->GetName();
};
auto same_name = [&name](const std::unique_ptr<Family<T>>& family) {
return name == family->GetName();
};

auto it = std::find_if(families.begin(), families.end(), same_name);
if (it != families.end()) {
throw std::invalid_argument("Family name already exists");
}
auto it = std::find_if(families.begin(), families.end(), same_name);
if (it != families.end()) {
throw std::invalid_argument("Family name already exists");
}

auto family = detail::make_unique<Family<T>>(name, help, labels);
Expand Down
17 changes: 0 additions & 17 deletions core/tests/registry_test.cc
Expand Up @@ -81,23 +81,6 @@ TEST(RegistryTest, reject_different_type_than_summary) {
EXPECT_ANY_THROW(BuildHistogram().Name(same_name).Register(registry));
}

TEST(RegistryTest, append_same_families) {
Registry registry{Registry::InsertBehavior::NonStandardAppend};

std::size_t loops = 4;

while (loops-- > 0) {
BuildCounter()
.Name("counter")
.Help("Test Counter")
.Register(registry)
.Add({{"name", "test_counter"}});
}

auto collected = registry.Collect();
EXPECT_EQ(4U, collected.size());
}

TEST(RegistryTest, throw_for_same_family_name) {
const auto same_name = std::string{"same_name"};
Registry registry{Registry::InsertBehavior::Throw};
Expand Down

0 comments on commit 3202b37

Please sign in to comment.