From: Dan Theisen Date: Sun, 3 Jul 2022 19:28:27 +0000 (-0700) Subject: [#2419] Begin adding stats to track HR assignment conflicts X-Git-Tag: Kea-2.2.0~68 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e53b1a434f8a5d047d8fa1a14e4f449b9ac0bd09;p=thirdparty%2Fkea.git [#2419] Begin adding stats to track HR assignment conflicts --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 939f55904b..406c0ff4a4 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -134,7 +134,8 @@ std::set dhcp4_statistics = { "v4-allocation-fail-shared-network", "v4-allocation-fail-subnet", "v4-allocation-fail-no-pools", - "v4-allocation-fail-classes" + "v4-allocation-fail-classes", + "v4-reservation-conflicts" }; } // end of anonymous namespace diff --git a/src/bin/dhcp4/tests/shared_network_unittest.cc b/src/bin/dhcp4/tests/shared_network_unittest.cc index 6dffbefa4c..5fb3b30efc 100644 --- a/src/bin/dhcp4/tests/shared_network_unittest.cc +++ b/src/bin/dhcp4/tests/shared_network_unittest.cc @@ -1768,6 +1768,16 @@ TEST_F(Dhcpv4SharedNetworkTest, reservationInSharedNetworkTwoClientsSameIdentifi testAssigned([this, &client2]() { doRequest(client2, "10.0.0.1"); }); + + // Ensure stats are being recorded for HR conflicts + ObservationPtr subnet_conflicts = StatsMgr::instance().getObservation( + "subnet[100].reservation-conflicts"); + ASSERT_TRUE(subnet_conflicts); + ASSERT_EQ(1, subnet_conflicts->getInteger().first); + ObservationPtr global_conflicts = StatsMgr::instance().getObservation( + "v4-reservation-conflicts"); + ASSERT_TRUE(global_conflicts); + ASSERT_EQ(1, global_conflicts->getInteger().first); } // Reserved address can't be assigned as long as access to a subnet is diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 7070b53d10..350cc46758 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -3701,6 +3701,13 @@ AllocEngine::discoverLease4(AllocEngine::ClientContext4& ctx) { .arg(ctx.currentHost()->getIPv4Reservation().toText()) .arg(ctx.conflicting_lease_ ? ctx.conflicting_lease_->toText() : "(no lease info)"); + StatsMgr::instance().addValue(StatsMgr::generateName( + "subnet", + new_lease->subnet_id_, + "reservation-conflicts"), + static_cast(1)); + StatsMgr::instance().addValue("v4-reservation-conflicts", + static_cast(1)); } } else { diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc index d74a4c52e6..f6fce4a79f 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.cc +++ b/src/lib/dhcpsrv/cfg_subnets4.cc @@ -527,11 +527,15 @@ CfgSubnets4::updateStatistics() { generateName("subnet", subnet_id, "total-addresses"), static_cast (subnet4->getPoolCapacity(Lease::TYPE_V4))); - const std::string& name = + std::string name = StatsMgr::generateName("subnet", subnet_id, "cumulative-assigned-addresses"); if (!stats_mgr.getObservation(name)) { stats_mgr.setValue(name, static_cast(0)); } + name = StatsMgr::generateName("subnet", subnet_id, "reservation-conflicts"); + if (!stats_mgr.getObservation(name)) { + stats_mgr.setValue(name, static_cast(0)); + } } // Only recount the stats if we have subnets.