Commit e82cf73f authored by Yoshitaka Aharen's avatar Yoshitaka Aharen
Browse files

Revert "Merge branch 'master' into trac510"

This reverts commit 662233a1, reversing
changes made to b41b7dc3.
parent 777d6f30
339. [func] y-aharen
src/lib/statistics: Added statistics counter library for entire server
items and per zone items. Also, modified b10-auth to use it. It is
also intended to use in the other modules such as b10-resolver.
(Trac #510, git TBD)
338. [bug] jinmei
b10-xfrin didn't check SOA serials of SOA and IXFR responses,
which resulted in unnecessary transfer or unexpected IXFR
......
......@@ -933,8 +933,6 @@ AC_CONFIG_FILES([Makefile
src/lib/util/tests/Makefile
src/lib/acl/Makefile
src/lib/acl/tests/Makefile
src/lib/statistics/Makefile
src/lib/statistics/tests/Makefile
tests/Makefile
tests/system/Makefile
tests/tools/Makefile
......
......@@ -71,7 +71,6 @@ b10_auth_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
b10_auth_LDADD += $(top_builddir)/src/lib/log/liblog.la
b10_auth_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
b10_auth_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
b10_auth_LDADD += $(top_builddir)/src/lib/statistics/libstatistics.la
b10_auth_LDADD += $(SQLITE_LIBS)
# TODO: config.h.in is wrong because doesn't honor pkgdatadir
......
......@@ -671,9 +671,9 @@ void
AuthSrvImpl::incCounter(const int protocol) {
// Increment query counter.
if (protocol == IPPROTO_UDP) {
counters_.inc(AuthCounters::SERVER_UDP_QUERY);
counters_.inc(AuthCounters::COUNTER_UDP_QUERY);
} else if (protocol == IPPROTO_TCP) {
counters_.inc(AuthCounters::SERVER_TCP_QUERY);
counters_.inc(AuthCounters::COUNTER_TCP_QUERY);
} else {
// unknown protocol
isc_throw(Unexpected, "Unknown protocol: " << protocol);
......@@ -766,7 +766,7 @@ bool AuthSrv::submitStatistics() const {
}
uint64_t
AuthSrv::getCounter(const AuthCounters::ServerCounterType type) const {
AuthSrv::getCounter(const AuthCounters::CounterType type) const {
return (impl_->counters_.getCounter(type));
}
......
......@@ -343,7 +343,7 @@ public:
/// \param type Type of a counter to get the value of
///
/// \return the value of the counter.
uint64_t getCounter(const AuthCounters::ServerCounterType type) const;
uint64_t getCounter(const AuthCounters::CounterType type) const;
/**
* \brief Set and get the addresses we listen on.
......
......@@ -35,6 +35,5 @@ query_bench_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
query_bench_LDADD += $(top_builddir)/src/lib/asiodns/libasiodns.la
query_bench_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
query_bench_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
query_bench_LDADD += $(top_builddir)/src/lib/statistics/libstatistics.la
query_bench_LDADD += $(SQLITE_LIBS)
......@@ -18,67 +18,48 @@
#include <cc/data.h>
#include <cc/session.h>
#include <statistics/counter.h>
#include <statistics/counter_dict.h>
#include <sstream>
#include <iostream>
#include <boost/noncopyable.hpp>
using namespace isc::auth;
using namespace isc::statistics;
// TODO: We need a namespace ("auth_server"?) to hold
// AuthSrv and AuthCounters.
// TODO: Make use of wrappers like isc::dns::Opcode
// for counter item type.
// AuthSrv and AuthCounters.
class AuthCountersImpl : boost::noncopyable {
class AuthCountersImpl {
private:
// prohibit copy
AuthCountersImpl(const AuthCountersImpl& source);
AuthCountersImpl& operator=(const AuthCountersImpl& source);
public:
AuthCountersImpl();
~AuthCountersImpl();
void inc(const AuthCounters::ServerCounterType type);
void inc(const std::string& zone,
const AuthCounters::PerZoneCounterType type);
void inc(const AuthCounters::CounterType type);
bool submitStatistics() const;
void setStatisticsSession(isc::cc::AbstractSession* statistics_session);
void registerStatisticsValidator
(AuthCounters::validator_type validator);
// Currently for testing purpose only
uint64_t getCounter(const AuthCounters::ServerCounterType type) const;
uint64_t getCounter(const AuthCounters::CounterType type) const;
private:
Counter server_counter_;
CounterDictionary per_zone_counter_;
std::vector<uint64_t> counters_;
isc::cc::AbstractSession* statistics_session_;
AuthCounters::validator_type validator_;
};
AuthCountersImpl::AuthCountersImpl() :
// initialize counter
// size of server_counter_: AuthCounters::SERVER_COUNTER_TYPES
// size of per_zone_counter_: AuthCounters::PER_ZONE_COUNTER_TYPES
server_counter_(AuthCounters::SERVER_COUNTER_TYPES),
per_zone_counter_(AuthCounters::PER_ZONE_COUNTER_TYPES),
// size: AuthCounters::COUNTER_TYPES, initial value: 0
counters_(AuthCounters::COUNTER_TYPES, 0),
statistics_session_(NULL)
{
per_zone_counter_.addElement("_SERVER_");
}
{}
AuthCountersImpl::~AuthCountersImpl()
{}
void
AuthCountersImpl::inc(const AuthCounters::ServerCounterType type) {
server_counter_.inc(type);
}
void
AuthCountersImpl::inc(const std::string& zone,
const AuthCounters::PerZoneCounterType type)
{
per_zone_counter_[zone].inc(type);
AuthCountersImpl::inc(const AuthCounters::CounterType type) {
++counters_.at(type);
}
bool
......@@ -92,9 +73,9 @@ AuthCountersImpl::submitStatistics() const {
<< "{ \"owner\": \"Auth\","
<< " \"data\":"
<< "{ \"queries.udp\": "
<< server_counter_.get(AuthCounters::SERVER_UDP_QUERY)
<< counters_.at(AuthCounters::COUNTER_UDP_QUERY)
<< ", \"queries.tcp\": "
<< server_counter_.get(AuthCounters::SERVER_TCP_QUERY)
<< counters_.at(AuthCounters::COUNTER_TCP_QUERY)
<< " }"
<< "}"
<< "]}";
......@@ -145,17 +126,19 @@ AuthCountersImpl::registerStatisticsValidator
// Currently for testing purpose only
uint64_t
AuthCountersImpl::getCounter(const AuthCounters::ServerCounterType type) const {
return (server_counter_.get(type));
AuthCountersImpl::getCounter(const AuthCounters::CounterType type) const {
return (counters_.at(type));
}
AuthCounters::AuthCounters() : impl_(new AuthCountersImpl())
{}
AuthCounters::~AuthCounters() {}
AuthCounters::~AuthCounters() {
delete impl_;
}
void
AuthCounters::inc(const AuthCounters::ServerCounterType type) {
AuthCounters::inc(const AuthCounters::CounterType type) {
impl_->inc(type);
}
......@@ -172,7 +155,7 @@ AuthCounters::setStatisticsSession
}
uint64_t
AuthCounters::getCounter(const AuthCounters::ServerCounterType type) const {
AuthCounters::getCounter(const AuthCounters::CounterType type) const {
return (impl_->getCounter(type));
}
......
......@@ -17,7 +17,6 @@
#include <cc/session.h>
#include <stdint.h>
#include <boost/scoped_ptr.hpp>
class AuthCountersImpl;
......@@ -52,18 +51,13 @@ class AuthCountersImpl;
/// \todo Consider overhead of \c AuthCounters::inc()
class AuthCounters {
private:
boost::scoped_ptr<AuthCountersImpl> impl_;
AuthCountersImpl* impl_;
public:
// Enum for the type of counter
enum ServerCounterType {
SERVER_UDP_QUERY, ///< SERVER_UDP_QUERY: counter for UDP queries
SERVER_TCP_QUERY, ///< SERVER_TCP_QUERY: counter for TCP queries
SERVER_COUNTER_TYPES ///< The number of defined counters
};
enum PerZoneCounterType {
ZONE_UDP_QUERY, ///< ZONE_UDP_QUERY: counter for UDP queries
ZONE_TCP_QUERY, ///< ZONE_TCP_QUERY: counter for TCP queries
PER_ZONE_COUNTER_TYPES ///< The number of defined counters
enum CounterType {
COUNTER_UDP_QUERY = 0, ///< COUNTER_UDP_QUERY: counter for UDP queries
COUNTER_TCP_QUERY = 1, ///< COUNTER_TCP_QUERY: counter for TCP queries
COUNTER_TYPES = 2 ///< The number of defined counters
};
/// The constructor.
///
......@@ -83,9 +77,9 @@ public:
///
/// \throw std::out_of_range \a type is unknown.
///
/// usage: counter.inc(AuthCounters::SERVER_UDP_QUERY);
/// usage: counter.inc(CounterType::COUNTER_UDP_QUERY);
///
void inc(const ServerCounterType type);
void inc(const CounterType type);
/// \brief Submit statistics counters to statistics module.
///
......@@ -136,7 +130,7 @@ public:
///
/// \return the value of the counter specified by \a type.
///
uint64_t getCounter(const AuthCounters::ServerCounterType type) const;
uint64_t getCounter(const AuthCounters::CounterType type) const;
/// \brief A type of validation function for the specification in
/// isc::config::ModuleSpec.
......
......@@ -64,7 +64,6 @@ run_unittests_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
run_unittests_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
run_unittests_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
run_unittests_LDADD += $(top_builddir)/src/lib/statistics/libstatistics.la
run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
endif
......
......@@ -779,7 +779,7 @@ TEST_F(AuthSrvTest, cacheSlots) {
// Submit UDP normal query and check query counter
TEST_F(AuthSrvTest, queryCounterUDPNormal) {
// The counter should be initialized to 0.
EXPECT_EQ(0, server.getCounter(AuthCounters::SERVER_UDP_QUERY));
EXPECT_EQ(0, server.getCounter(AuthCounters::COUNTER_UDP_QUERY));
// Create UDP message and process.
UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(),
default_qid, Name("example.com"),
......@@ -788,13 +788,13 @@ TEST_F(AuthSrvTest, queryCounterUDPNormal) {
server.processMessage(*io_message, parse_message, response_obuffer,
&dnsserv);
// After processing UDP query, the counter should be 1.
EXPECT_EQ(1, server.getCounter(AuthCounters::SERVER_UDP_QUERY));
EXPECT_EQ(1, server.getCounter(AuthCounters::COUNTER_UDP_QUERY));
}
// Submit TCP normal query and check query counter
TEST_F(AuthSrvTest, queryCounterTCPNormal) {
// The counter should be initialized to 0.
EXPECT_EQ(0, server.getCounter(AuthCounters::SERVER_TCP_QUERY));
EXPECT_EQ(0, server.getCounter(AuthCounters::COUNTER_TCP_QUERY));
// Create TCP message and process.
UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(),
default_qid, Name("example.com"),
......@@ -803,13 +803,13 @@ TEST_F(AuthSrvTest, queryCounterTCPNormal) {
server.processMessage(*io_message, parse_message, response_obuffer,
&dnsserv);
// After processing TCP query, the counter should be 1.
EXPECT_EQ(1, server.getCounter(AuthCounters::SERVER_TCP_QUERY));
EXPECT_EQ(1, server.getCounter(AuthCounters::COUNTER_TCP_QUERY));
}
// Submit TCP AXFR query and check query counter
TEST_F(AuthSrvTest, queryCounterTCPAXFR) {
// The counter should be initialized to 0.
EXPECT_EQ(0, server.getCounter(AuthCounters::SERVER_TCP_QUERY));
EXPECT_EQ(0, server.getCounter(AuthCounters::COUNTER_TCP_QUERY));
UnitTestUtil::createRequestMessage(request_message, opcode, default_qid,
Name("example.com"), RRClass::IN(), RRType::AXFR());
createRequestPacket(request_message, IPPROTO_TCP);
......@@ -818,7 +818,7 @@ TEST_F(AuthSrvTest, queryCounterTCPAXFR) {
server.processMessage(*io_message, parse_message, response_obuffer, &dnsserv);
EXPECT_FALSE(dnsserv.hasAnswer());
// After processing TCP AXFR query, the counter should be 1.
EXPECT_EQ(1, server.getCounter(AuthCounters::SERVER_TCP_QUERY));
EXPECT_EQ(1, server.getCounter(AuthCounters::COUNTER_TCP_QUERY));
}
// Submit TCP IXFR query and check query counter
......
......@@ -150,24 +150,25 @@ AuthCountersTest::MockSession::setThrowSessionTimeout(bool flag) {
TEST_F(AuthCountersTest, incrementUDPCounter) {
// The counter should be initialized to 0.
EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_UDP_QUERY));
EXPECT_NO_THROW(counters.inc(AuthCounters::SERVER_UDP_QUERY));
EXPECT_EQ(0, counters.getCounter(AuthCounters::COUNTER_UDP_QUERY));
EXPECT_NO_THROW(counters.inc(AuthCounters::COUNTER_UDP_QUERY));
// After increment, the counter should be 1.
EXPECT_EQ(1, counters.getCounter(AuthCounters::SERVER_UDP_QUERY));
EXPECT_EQ(1, counters.getCounter(AuthCounters::COUNTER_UDP_QUERY));
}
TEST_F(AuthCountersTest, incrementTCPCounter) {
// The counter should be initialized to 0.
EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_TCP_QUERY));
EXPECT_NO_THROW(counters.inc(AuthCounters::SERVER_TCP_QUERY));
EXPECT_EQ(0, counters.getCounter(AuthCounters::COUNTER_TCP_QUERY));
EXPECT_NO_THROW(counters.inc(AuthCounters::COUNTER_TCP_QUERY));
// After increment, the counter should be 1.
EXPECT_EQ(1, counters.getCounter(AuthCounters::SERVER_TCP_QUERY));
EXPECT_EQ(1, counters.getCounter(AuthCounters::COUNTER_TCP_QUERY));
}
TEST_F(AuthCountersTest, incrementInvalidCounter) {
// Expect to throw an isc::OutOfRange
EXPECT_THROW(counters.inc(AuthCounters::SERVER_COUNTER_TYPES),
isc::OutOfRange);
// Expect to throw isc::InvalidParameter if the type of the counter is
// invalid.
EXPECT_THROW(counters.inc(AuthCounters::COUNTER_TYPES),
std::out_of_range);
}
TEST_F(AuthCountersTest, submitStatisticsWithoutSession) {
......@@ -194,14 +195,14 @@ TEST_F(AuthCountersTest, submitStatisticsWithoutValidator) {
// Validate if it submits correct data.
// Counters should be initialized to 0.
EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_UDP_QUERY));
EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_TCP_QUERY));
EXPECT_EQ(0, counters.getCounter(AuthCounters::COUNTER_UDP_QUERY));
EXPECT_EQ(0, counters.getCounter(AuthCounters::COUNTER_TCP_QUERY));
// UDP query counter is set to 2.
counters.inc(AuthCounters::SERVER_UDP_QUERY);
counters.inc(AuthCounters::SERVER_UDP_QUERY);
counters.inc(AuthCounters::COUNTER_UDP_QUERY);
counters.inc(AuthCounters::COUNTER_UDP_QUERY);
// TCP query counter is set to 1.
counters.inc(AuthCounters::SERVER_TCP_QUERY);
counters.inc(AuthCounters::COUNTER_TCP_QUERY);
counters.submitStatistics();
// Destination is "Stats".
......@@ -236,14 +237,14 @@ TEST_F(AuthCountersTest, submitStatisticsWithValidator) {
counters.registerStatisticsValidator(validator);
// Counters should be initialized to 0.
EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_UDP_QUERY));
EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_TCP_QUERY));
EXPECT_EQ(0, counters.getCounter(AuthCounters::COUNTER_UDP_QUERY));
EXPECT_EQ(0, counters.getCounter(AuthCounters::COUNTER_TCP_QUERY));
// UDP query counter is set to 2.
counters.inc(AuthCounters::SERVER_UDP_QUERY);
counters.inc(AuthCounters::SERVER_UDP_QUERY);
counters.inc(AuthCounters::COUNTER_UDP_QUERY);
counters.inc(AuthCounters::COUNTER_UDP_QUERY);
// TCP query counter is set to 1.
counters.inc(AuthCounters::SERVER_TCP_QUERY);
counters.inc(AuthCounters::COUNTER_TCP_QUERY);
// checks the value returned by submitStatistics
EXPECT_TRUE(counters.submitStatistics());
......
SUBDIRS = exceptions util log cryptolink dns cc config acl xfr bench \
asiolink asiodns nsas cache resolve testutils datasrc \
server_common python dhcp statistics
server_common python dhcp
SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES) $(MULTITHREADING_FLAG)
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/statistics -I$(top_builddir)/src/lib/statistics
AM_CXXFLAGS = $(B10_CXXFLAGS)
# Some versions of GCC warn about some versions of Boost regarding
# missing initializer for members in its posix_time.
# https://svn.boost.org/trac/boost/ticket/3477
# But older GCC compilers don't have the flag.
AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
if USE_CLANGPP
# clang++ complains about unused function parameters in some boost header
# files.
AM_CXXFLAGS += -Wno-unused-parameter
endif
lib_LTLIBRARIES = libstatistics.la
libstatistics_la_SOURCES = counter.h counter.cc
libstatistics_la_SOURCES += counter_dict.h counter_dict.cc
CLEANFILES = *.gcno *.gcda
#include <vector>
#include <boost/noncopyable.hpp>
#include <statistics/counter.h>
namespace {
const unsigned int InitialValue = 0;
} // namespace
namespace isc {
namespace statistics {
class CounterImpl : boost::noncopyable {
private:
std::vector<Counter::Value> counters_;
public:
CounterImpl(const size_t nelements);
~CounterImpl();
void inc(const Counter::Type&);
const Counter::Value& get(const Counter::Type&) const;
};
CounterImpl::CounterImpl(const size_t items) :
counters_(items, InitialValue)
{
if (items == 0) {
isc_throw(isc::InvalidParameter, "Items must not be 0");
}
}
CounterImpl::~CounterImpl() {}
void
CounterImpl::inc(const Counter::Type& type) {
if(type >= counters_.size()) {
isc_throw(isc::OutOfRange, "Counter type is out of range");
}
++counters_.at(type);
return;
}
const Counter::Value&
CounterImpl::get(const Counter::Type& type) const {
if(type >= counters_.size()) {
isc_throw(isc::OutOfRange, "Counter type is out of range");
}
return (counters_.at(type));
}
Counter::Counter(const size_t items) : impl_(new CounterImpl(items))
{}
Counter::~Counter() {}
void
Counter::inc(const Type& type) {
impl_->inc(type);
return;
}
const Counter::Value&
Counter::get(const Type& type) const {
return (impl_->get(type));
}
} // namespace statistics
} // namespace isc
#ifndef __COUNTER_H
#define __COUNTER_H 1
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <exceptions/exceptions.h>
namespace isc {
namespace statistics {
// forward declaration for pImpl idiom
class CounterImpl;
class Counter : boost::noncopyable {
private:
boost::scoped_ptr<CounterImpl> impl_;
public:
typedef unsigned int Type;
typedef unsigned int Value;
/// The constructor.
///
/// This constructor is mostly exception free. But it may still throw
/// a standard exception if memory allocation fails inside the method.
///
/// \param items A number of counter items to hold (greater than 0)
///
/// \throw isc::InvalidParameter \a items is 0
Counter(const size_t items);
/// The destructor.
///
/// This method never throws an exception.
~Counter();
/// \brief Increment a counter item specified with \a type.
///
/// \param type %Counter item to increment
///
/// \throw isc::OutOfRange \a type is invalid
void inc(const Type& type);
/// \brief Get the value of a counter item specified with \a type.
///
/// \param type %Counter item to get the value of
///
/// \throw isc::OutOfRange \a type is invalid
const Value& get(const Type& type) const;
};
} // namespace statistics
} // namespace isc
#endif
#include <cassert>
#include <stdexcept>
#include <iterator>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>
#include <statistics/counter_dict.h>
namespace {
typedef boost::shared_ptr<isc::statistics::Counter> CounterPtr;
typedef boost::unordered_map<std::string, CounterPtr> DictionaryMap;
}
namespace isc {
namespace statistics {
// Implementation detail class for CounterDictionary::ConstIterator
class CounterDictionaryConstIteratorImpl;
class CounterDictionaryImpl : boost::noncopyable {
private:
DictionaryMap dictionary_;
std::vector<std::string> elements_;
const size_t items_;
// Default constructor is forbidden; number of counter items must be
// specified at the construction of this class.
CounterDictionaryImpl();
public:
CounterDictionaryImpl(const size_t items);
~CounterDictionaryImpl();
void addElement(const std::string& name);
void deleteElement(const std::string& name);
Counter& getElement(const std::string& name);
public:
CounterDictionaryConstIteratorImpl begin() const;
CounterDictionaryConstIteratorImpl end() const;
};
// Constructor with number of items
CounterDictionaryImpl::CounterDictionaryImpl(const size_t items) :
items_(items)
{
// The number of items must not be 0
if (items == 0) {
isc_throw(isc::InvalidParameter, "Items must not be 0");
}
}
// Destructor
CounterDictionaryImpl::~CounterDictionaryImpl() {}
void
CounterDictionaryImpl::addElement(const std::string& name) {
// throw if the element already exists
if (dictionary_.count(name) != 0) {
isc_throw(isc::InvalidParameter,
"Element " << name << " already exists");
}
assert(items_ != 0);
// Create a new Counter and add to the map
dictionary_.insert(
DictionaryMap::value_type(name, CounterPtr(new Counter(items_))));
}
void
CounterDictionaryImpl::deleteElement(const std::string& name) {
size_t result = dictionary_.erase(name);
if (result != 1) {
// If an element with specified name does not exist, throw
// isc::OutOfRange.
isc_throw(isc::OutOfRange, "Element " << name << " does not exist");
}
}
Counter&