summaryrefslogtreecommitdiffstats
path: root/src/lib/d2srv
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2021-08-18 20:15:18 +0200
committerRazvan Becheriu <razvan@isc.org>2021-09-03 16:10:59 +0200
commitd2015a065a7fc46403464f1051d02476b6299156 (patch)
tree089c625bfadbeac826d94bd7d559ea642ea1570d /src/lib/d2srv
parent[#2011] documentation fixes (diff)
downloadkea-d2015a065a7fc46403464f1051d02476b6299156.tar.xz
kea-d2015a065a7fc46403464f1051d02476b6299156.zip
[#2040] Checkpoint: began D2 stats
Diffstat (limited to 'src/lib/d2srv')
-rw-r--r--src/lib/d2srv/Makefile.am2
-rw-r--r--src/lib/d2srv/d2_tsig_key.cc70
-rw-r--r--src/lib/d2srv/d2_tsig_key.h58
-rw-r--r--src/lib/d2srv/tests/Makefile.am3
-rw-r--r--src/lib/d2srv/tests/d2_tsig_key_unittest.cc87
5 files changed, 219 insertions, 1 deletions
diff --git a/src/lib/d2srv/Makefile.am b/src/lib/d2srv/Makefile.am
index 78de1a20a2..af8a226565 100644
--- a/src/lib/d2srv/Makefile.am
+++ b/src/lib/d2srv/Makefile.am
@@ -16,6 +16,7 @@ libkea_d2srv_la_SOURCES += d2_config.cc d2_config.h
libkea_d2srv_la_SOURCES += d2_log.cc d2_log.h
libkea_d2srv_la_SOURCES += d2_messages.cc d2_messages.h
libkea_d2srv_la_SOURCES += d2_simple_parser.cc d2_simple_parser.h
+libkea_d2srv_la_SOURCES += d2_tsig_key.cc d2_tsig_key.h
EXTRA_DIST += d2_messages.mes
libkea_d2srv_la_CXXFLAGS = $(AM_CXXFLAGS)
@@ -25,6 +26,7 @@ libkea_d2srv_la_LIBADD =
libkea_d2srv_la_LIBADD += $(top_builddir)/src/lib/process/libkea-process.la
libkea_d2srv_la_LIBADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
libkea_d2srv_la_LIBADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
+libkea_d2srv_la_LIBADD += $(top_builddir)/src/lib/stats/libkea-stats.la
libkea_d2srv_la_LIBADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
libkea_d2srv_la_LIBADD += $(top_builddir)/src/lib/http/libkea-http.la
libkea_d2srv_la_LIBADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
diff --git a/src/lib/d2srv/d2_tsig_key.cc b/src/lib/d2srv/d2_tsig_key.cc
new file mode 100644
index 0000000000..229f7c06b0
--- /dev/null
+++ b/src/lib/d2srv/d2_tsig_key.cc
@@ -0,0 +1,70 @@
+// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/// Defines the logger used by the top-level component of kea-dhcp-ddns.
+
+#include <config.h>
+
+#include <d2srv/d2_tsig_key.h>
+#include <stats/stats_mgr.h>
+
+using namespace isc::dns;
+using namespace isc::stats;
+using namespace std;
+
+namespace isc {
+namespace d2 {
+
+set<string>
+D2TsigKey::keyStats = {
+ "sent",
+ "signed",
+// "unsigned",
+ "success",
+ "timeout",
+ "error"
+};
+
+set<string>
+D2TsigKey::globalStats = {
+ "sent",
+ "signed",
+ "unsigned",
+ "success",
+ "timeout",
+ "error"
+};
+
+D2TsigKey::D2TsigKey(const std::string& key_name) : TSIGKey(key_name) {
+ StatsMgr& stats_mgr = StatsMgr::instance();
+ const string& kname = getKeyName().toText();
+ for (const auto& name : keyStats) {
+ const string& sname = StatsMgr::generateName("key", kname, name);
+ stats_mgr.setValue(sname, static_cast<int64_t>(0));
+ }
+}
+
+D2TsigKey::~D2TsigKey() {
+ StatsMgr& stats_mgr = StatsMgr::instance();
+ const string& kname = getKeyName().toText();
+ for (const auto& name : keyStats) {
+ string sname = StatsMgr::generateName("key", kname, name);
+ stats_mgr.del(sname);
+ }
+}
+
+void
+D2TsigKey::resetStats() {
+ StatsMgr& stats_mgr = StatsMgr::instance();
+ const string& kname = getKeyName().toText();
+ for (const auto& name : keyStats) {
+ string sname = StatsMgr::generateName("key", kname, name);
+ stats_mgr.reset(sname);
+ }
+}
+
+} // namespace d2
+} // namespace isc
diff --git a/src/lib/d2srv/d2_tsig_key.h b/src/lib/d2srv/d2_tsig_key.h
new file mode 100644
index 0000000000..615996ab91
--- /dev/null
+++ b/src/lib/d2srv/d2_tsig_key.h
@@ -0,0 +1,58 @@
+// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef D2_TSIG_KEY_H
+#define D2_TSIG_KEY_H
+
+#include <dns/name.h>
+#include <dns/tsigkey.h>
+#include <boost/shared_ptr.hpp>
+
+#include <set>
+
+namespace isc {
+namespace d2 {
+
+/// @brief Statistics keeping extension of the DNS TSIGKey class.
+///
+/// Implements a TSIGKey derived class which can be used as the value
+/// of TSIGKeyPtr so with minimal or no update to the DNS++ library.
+class D2TsigKey : public dns::TSIGKey {
+public:
+ /// @brief Constructor.
+ ///
+ /// Initialize the key statistics.
+ ///
+ /// @param key_name Domain name of the key.
+ D2TsigKey(const std::string& key_name);
+
+ /// @brief Destructor.
+ ///
+ /// Remove the key statistics.
+ virtual ~D2TsigKey();
+
+ /// @brief Reset statistics.
+ ///
+ virtual void resetStats();
+
+ /// @brief Statistics names (key).
+ ///
+ /// The list of statistic names for keys.
+ static std::set<std::string> keyStats;
+
+ /// @brief Statistics names (global).
+ ///
+ /// The list of global statistic names.
+ static std::set<std::string> globalStats;
+};
+
+/// @brief Type of pointer to a D2 TSIG key.
+typedef boost::shared_ptr<D2TsigKey> D2TsigKeyPtr;
+
+} // namespace d2
+} // namespace isc
+
+#endif // D2_TSIG_KEY_H
diff --git a/src/lib/d2srv/tests/Makefile.am b/src/lib/d2srv/tests/Makefile.am
index fb7c76003d..caede036f9 100644
--- a/src/lib/d2srv/tests/Makefile.am
+++ b/src/lib/d2srv/tests/Makefile.am
@@ -19,7 +19,7 @@ if HAVE_GTEST
TESTS += libd2srv_unittests
libd2srv_unittests_SOURCES = run_unittests.cc
-# Currently no unit test file was moved even partially.
+libd2srv_unittests_SOURCES += d2_tsig_key_unittest.cc
libd2srv_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
libd2srv_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
@@ -27,6 +27,7 @@ libd2srv_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
libd2srv_unittests_LDADD = $(top_builddir)/src/lib/d2srv/libkea-d2srv.la
libd2srv_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
libd2srv_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
+libd2srv_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
libd2srv_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
libd2srv_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
libd2srv_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
diff --git a/src/lib/d2srv/tests/d2_tsig_key_unittest.cc b/src/lib/d2srv/tests/d2_tsig_key_unittest.cc
new file mode 100644
index 0000000000..c73ed1bb12
--- /dev/null
+++ b/src/lib/d2srv/tests/d2_tsig_key_unittest.cc
@@ -0,0 +1,87 @@
+// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <cc/data.h>
+#include <d2srv/d2_tsig_key.h>
+#include <stats/stats_mgr.h>
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+#include <sstream>
+
+using namespace isc::d2;
+using namespace isc::data;
+using namespace isc::stats;
+using namespace std;
+
+namespace {
+
+/// @brief Fixture class for TSIG key / DNS update statictics.
+class D2TsigKeyTest : public ::testing::Test {
+public:
+ /// @brief Constructor.
+ D2TsigKeyTest() {
+ StatsMgr::instance();
+ StatsMgr::instance().removeAll();
+ StatsMgr::instance().setMaxSampleCountDefault(0);
+ }
+
+ /// @brief Destructor.
+ ~D2TsigKeyTest() {
+ StatsMgr::instance().removeAll();
+ StatsMgr::instance().setMaxSampleCountDefault(0);
+ }
+};
+
+/// @brief Check TSIG key life.
+TEST_F(D2TsigKeyTest, key) {
+ // Statistics names.
+ ASSERT_EQ(5, D2TsigKey::keyStats.size());
+ ASSERT_EQ(6, D2TsigKey::globalStats.size());
+
+ // Get the statistics manager.
+ StatsMgr& stat_mgr = StatsMgr::instance();
+ ASSERT_EQ(0, stat_mgr.count());
+
+ // Create a key.
+ const string& key_spec = "foo.bar.::test";
+ D2TsigKeyPtr key(new D2TsigKey(key_spec));
+ EXPECT_EQ(5, stat_mgr.count());
+
+ // Get the 'sent' statistics.
+ const string& stat_name = "key[foo.bar.].sent";
+ EXPECT_EQ(1, stat_mgr.getSize(stat_name));
+ ObservationPtr stat = stat_mgr.getObservation(stat_name);
+ ASSERT_TRUE(stat);
+ IntegerSample sample;
+ ASSERT_NO_THROW(sample = stat->getInteger());
+ EXPECT_EQ(0, sample.first);
+
+ // Increment the 'sent' statistics.
+ stat_mgr.addValue(stat_name, static_cast<int64_t>(1));
+ stat = stat_mgr.getObservation(stat_name);
+ ASSERT_TRUE(stat);
+ ASSERT_NO_THROW(sample = stat->getInteger());
+ EXPECT_EQ(1, sample.first);
+
+ // Reset the key statistics.
+ ASSERT_NO_THROW(key->resetStats());
+ stat = stat_mgr.getObservation(stat_name);
+ ASSERT_TRUE(stat);
+ ASSERT_NO_THROW(sample = stat->getInteger());
+ EXPECT_EQ(0, sample.first);
+
+ // Destroy the key: its stats are removed.
+ key.reset();
+ EXPECT_EQ(0, stat_mgr.count());
+ stat = stat_mgr.getObservation(stat_name);
+ EXPECT_FALSE(stat);
+}
+
+} // end of anonymous namespace