Skip to content

Commit

Permalink
Change SUM and AVG DerivedStats to be time-range based.
Browse files Browse the repository at this point in the history
Sandesh Message Stats are changed to us this instead of periodic processing.
Closes-Bug: 1619156

Change-Id: If2172bbe3b8b95df543fe79e999f0076eb5cba30
  • Loading branch information
anishmehta committed Sep 2, 2016
1 parent c8aec3b commit 7247c12
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 199 deletions.
18 changes: 9 additions & 9 deletions compiler/generate/t_cpp_generator.cc
Expand Up @@ -2009,7 +2009,7 @@ void t_cpp_generator::generate_sandesh_definition(ofstream& out,
assert((*f_iter)->get_name() == "data");

indent(out) << "static void Send(const " << type_name((*f_iter)->get_type()) <<
"& data, std::string table = \"\");" << endl;
"& data, std::string table = \"\", uint64_t mono_usec=0);" << endl;

indent(out) << "static void Send(const " << type_name((*f_iter)->get_type()) <<
"& cdata, SandeshUVE::SendType stype, uint32_t seqno," <<
Expand Down Expand Up @@ -2069,7 +2069,7 @@ void t_cpp_generator::generate_sandesh_definition(ofstream& out,
" & _data, const map<string,string> & _dsconf);" << endl;
out << indent() << "static bool UpdateUVE(" << dtype <<
" & _data, " << dtype <<
" & tdata);" << endl;
" & tdata, uint64_t mono_usec);" << endl;
out << indent() << "bool LoadUVE(SendType stype, uint32_t cycle);" << endl;
}

Expand Down Expand Up @@ -3809,7 +3809,7 @@ void t_cpp_generator::generate_sandesh_updater(ofstream& out,
indent(out) << "bool " << tsandesh->get_name() <<
"::UpdateUVE(" << dtype <<
" & _data, " << dtype <<
" & tdata) {" << endl;
" & tdata, uint64_t mono_usec) {" << endl;

indent_up();

Expand Down Expand Up @@ -3863,11 +3863,11 @@ void t_cpp_generator::generate_sandesh_updater(ofstream& out,
if (c_iter->second.compattr_.empty()) {
if (!c_iter->second.is_map_) {
indent(out) << "tdata.__dsobj_" << *d_iter <<
"->Update(_data.get_" << snm << "());" << endl;
"->Update(_data.get_" << snm << "(), mono_usec);" << endl;
} else {
indent(out) << "tdata.__dsobj_" << *d_iter <<
"->Update(_data.get_" << snm << "(), _delmap_" <<
snm << ");" << endl;
snm << ", mono_usec);" << endl;
}
} else {
string getexpr = string("get_") + c_iter->second.compattr_ +
Expand All @@ -3878,7 +3878,7 @@ void t_cpp_generator::generate_sandesh_updater(ofstream& out,
}
if (!c_iter->second.is_map_) {
indent(out) << "tdata.__dsobj_" << *d_iter << "->Update(_data.get_" <<
snm << "()." << getexpr << ");" << endl;
snm << "()." << getexpr << ", mono_usec);" << endl;
} else {
indent(out) << "std::map<string," << c_iter->second.rawtype_ << "> temp_" <<
*d_iter << ";" << endl;
Expand All @@ -3891,7 +3891,7 @@ void t_cpp_generator::generate_sandesh_updater(ofstream& out,
indent_down();
indent(out) << "}" << endl;
indent(out) << "tdata.__dsobj_" << *d_iter << "->Update(temp_" <<
*d_iter << ", _delmap_" << snm << ");" << endl;
*d_iter << ", _delmap_" << snm << ", mono_usec);" << endl;
indent(out) << "temp_" << *d_iter << ".clear();" << endl;
}
}
Expand Down Expand Up @@ -4217,7 +4217,7 @@ void t_cpp_generator::generate_sandesh_uve_creator(

indent(out) << "void " << sname <<
"::Send(const " << type_name((*f_iter)->get_type()) <<
"& data, std::string table) {" << endl;
"& data, std::string table, uint64_t mono_usec) {" << endl;
indent_up();

indent(out) << type_name((*f_iter)->get_type()) <<
Expand All @@ -4227,7 +4227,7 @@ void t_cpp_generator::generate_sandesh_uve_creator(
indent(out) << "if (!table.empty()) cdata.table_ = table;" << endl;

indent(out) << "if (uvemap" << sname <<
".UpdateUVE(cdata, msg_seqno)) {" << endl;
".UpdateUVE(cdata, msg_seqno, mono_usec)) {" << endl;
indent_up();
indent(out) << sname << " *snh = new " << sname << "(msg_seqno, cdata);" << endl;
indent(out) << "snh->Dispatch();" << endl;
Expand Down
28 changes: 8 additions & 20 deletions library/common/sandesh_uve.sandesh
Expand Up @@ -242,18 +242,6 @@ struct SandeshSessionStats {
9: u64 num_write_ready_cb_error
}

typedef u64 mcs_uint
struct mcs_uint_P_ {
1: optional mcs_uint staging
2: optional mcs_uint value
}

typedef SandeshMessageStats SnhMsgStats
struct SnhMsgStats_P_ {
1: optional SnhMsgStats staging
2: optional SnhMsgStats value
}

struct ModuleClientState {
1: string name (key="ObjectGeneratorInfo")
2: optional bool deleted
Expand All @@ -266,18 +254,18 @@ struct ModuleClientState {

10: optional map<string, SandeshMessageStats> msg_type_agg (metric="agg", hidden="yes")
/** @display_name:Sandesh Client Message Type Stats*/
11: optional map<string, SandeshMessageStats> msg_type_diff (mstats="0-msg_type_agg:DSNon0:", tags=".__key")
12: optional map<string, SnhMsgStats_P_> msg_type_1h (mstats="60-msg_type_agg:DSSum:", hidden="yes")
13: optional map<string, mcs_uint_P_> msg_type_tx_10m (mstats="10-msg_type_agg.messages_sent:DSSum:")
11: optional map<string, SandeshMessageStats> msg_type_diff (mstats="msg_type_agg:DSNon0:", tags=".__key")
12: optional map<string, SandeshMessageStats> msg_type_1h (mstats="msg_type_agg:DSSum:3600", hidden="yes")
13: optional map<string, u64> msg_type_tx_10m (mstats="msg_type_agg.messages_sent:DSSum:600")

/** @display_name:Sandesh Client Message Stats*/
20: optional map<string, u64> tx_msg_agg (metric="agg", hidden="yes")
21: optional map<string, u64> tx_msg_diff (mstats="0-tx_msg_agg:DSNon0:",tags=".__key")
22: optional map<string, mcs_uint_P_> tx_msg_1h (mstats="60-tx_msg_agg:DSSum:", hidden="yes")
23: optional map<string, mcs_uint_P_> tx_msg_10m (mstats="10-tx_msg_agg:DSSum:")
20: optional map<string, u64> tx_msg_agg (metric="agg", hidden="yes")
21: optional map<string, u64> tx_msg_diff (mstats="tx_msg_agg:DSNon0:",tags=".__key")
22: optional map<string, u64> tx_msg_1h (mstats="tx_msg_agg:DSSum:3600", hidden="yes")
23: optional map<string, u64> tx_msg_10m (mstats="tx_msg_agg:DSSum:600")

14: optional u64 max_sm_queue_count
} (period="60")
}

uve sandesh SandeshModuleClientTrace {
1: ModuleClientState data
Expand Down
58 changes: 38 additions & 20 deletions library/cpp/derived_stats.h
Expand Up @@ -25,6 +25,12 @@ class SandeshStructDeleteTrait;
namespace contrail {
namespace sandesh {

enum DSReturnType {
DSR_INVALID=0,
DSR_SKIP,
DSR_OK
};

template<typename ElemT>
std::map<std::string, ElemT> DerivedStatsAgg(const std::map<std::string, ElemT> & raw,
std::map<std::string, ElemT> & agg,
Expand Down Expand Up @@ -57,7 +63,8 @@ std::map<std::string, ElemT> DerivedStatsAgg(const std::map<std::string, ElemT>
template<template<class,class> class DSTT, typename ElemT, typename ResultT>
void DerivedStatsMerge(const std::map<std::string, ElemT> & raw,
std::map<std::string, boost::shared_ptr<DSTT<ElemT,ResultT> > > & dsm,
std::string annotation, const std::map<std::string, bool> &del) {
std::string annotation, const std::map<std::string, bool> &del,
uint64_t mono_usec) {

std::map<std::string, bool> srcmap;
typename std::map<std::string, ElemT>::const_iterator rit;
Expand Down Expand Up @@ -92,7 +99,7 @@ void DerivedStatsMerge(const std::map<std::string, ElemT> & raw,
dt++;
dsm.erase(et);
} else {
dt->second->Update(rit->second);
dt->second->Update(rit->second, mono_usec);
++dt;
}
} else {
Expand All @@ -109,7 +116,7 @@ void DerivedStatsMerge(const std::map<std::string, ElemT> & raw,
if ((mt->second == false) && (!dlt->second)) {
assert(dsm.find(mt->first) == dsm.end());
dsm[mt->first] = boost::make_shared<DSTT<ElemT,ResultT> >(annotation);
dsm[mt->first]->Update((raw.find(mt->first))->second);
dsm[mt->first]->Update((raw.find(mt->first))->second, mono_usec);
}
}
}
Expand Down Expand Up @@ -146,7 +153,8 @@ class DerivedStatsIf {
void FillResult(ResultT &res, bool& isset, bool force=false) const {
isset = false;
if (ds_) {
if (ds_->FillResult(res) || force) {
DSReturnType rt = ds_->FillResult(res);
if ((force && rt) || (!force && rt == DSR_OK)) {
isset = true;
}
}
Expand All @@ -158,7 +166,8 @@ class DerivedStatsIf {
for (typename result_map::const_iterator dit = dsm_->begin();
dit != dsm_->end(); dit++) {
ResultT res;
if (dit->second->FillResult(res) || force) {
DSReturnType rt = dit->second->FillResult(res);
if ((force && rt) || (!force && rt == DSR_OK)) {
mres.insert(std::make_pair(dit->first, res));
}
}
Expand All @@ -169,7 +178,7 @@ class DerivedStatsIf {

// This is the interface to feed in all updates to the raw stat
// on which the derived stat will be based.
void Update(ElemT raw) {
void Update(ElemT raw, uint64_t mono_usec) {
if (!ds_) {
ds_ = boost::make_shared<DSTT<ElemT,ResultT> >(annotation_);
if (is_agg_) {
Expand All @@ -182,19 +191,20 @@ class DerivedStatsIf {
agg_ = agg_ + diff_;
}
}
if (is_agg_) ds_->Update(diff_);
else ds_->Update(raw);
if (is_agg_) ds_->Update(diff_, mono_usec);
else ds_->Update(raw, mono_usec);
}

void Update(const std::map<std::string, ElemT> & raw, const std::map<std::string, bool> &del) {
void Update(const std::map<std::string, ElemT> & raw,
const std::map<std::string, bool> &del, uint64_t mono_usec) {
if (!dsm_) {
dsm_ = boost::make_shared<result_map>();
}
if (is_agg_) {
diffm_ = DerivedStatsAgg<ElemT>(raw, aggm_, del);
DerivedStatsMerge<DSTT,ElemT,ResultT>(diffm_, *dsm_, annotation_, del);
DerivedStatsMerge<DSTT,ElemT,ResultT>(diffm_, *dsm_, annotation_, del, mono_usec);
} else {
DerivedStatsMerge<DSTT,ElemT,ResultT>(raw, *dsm_, annotation_, del);
DerivedStatsMerge<DSTT,ElemT,ResultT>(raw, *dsm_, annotation_, del, mono_usec);
}
}
};
Expand Down Expand Up @@ -231,7 +241,7 @@ class DerivedStatsPeriodicIf {

// This is the interface to feed in all updates to the raw stat
// on which the derived stat will be based.
void Update(ElemT raw) {
void Update(ElemT raw, uint64_t mono_usec) {
if (!ds_) {
ds_ = boost::make_shared<DSTT<ElemT,SubResultT> >(annotation_);
}
Expand All @@ -243,19 +253,22 @@ class DerivedStatsPeriodicIf {
diff_ = raw - agg_;
agg_ = agg_ + diff_;
}
ds_->Update(diff_);
} else ds_->Update(raw);
ds_->Update(diff_, mono_usec);
} else ds_->Update(raw, mono_usec);
init_ = true;
}

void Update(const std::map<std::string, ElemT> & raw, const std::map<std::string, bool> &del) {
void Update(const std::map<std::string, ElemT> & raw,
const std::map<std::string, bool> &del, uint64_t mono_usec) {
if (!dsm_) {
dsm_ = boost::make_shared<result_map>();
}
if (is_agg_) {
diffm_ = DerivedStatsAgg<ElemT>(raw, aggm_, del);
DerivedStatsMerge<DSTT,ElemT,SubResultT>(diffm_, *dsm_, annotation_, del);
} else DerivedStatsMerge<DSTT,ElemT,SubResultT>(raw, *dsm_, annotation_, del);
DerivedStatsMerge<DSTT,ElemT,SubResultT>(
diffm_, *dsm_, annotation_, del, mono_usec);
} else DerivedStatsMerge<DSTT,ElemT,SubResultT>(
raw, *dsm_, annotation_, del, mono_usec);
init_ = true;
}

Expand Down Expand Up @@ -290,7 +303,8 @@ class DerivedStatsPeriodicIf {
}
if (ds_) {
// Fill in current information
if (ds_->FillResult(res.staging) || force) {
DSReturnType rt = ds_->FillResult(res.staging);
if ((force && rt) || (!force && rt == DSR_OK)) {
res.__isset.staging = true;
isset = true;
}
Expand Down Expand Up @@ -343,12 +357,16 @@ class DerivedStatsPeriodicIf {
typename std::map<std::string, ResultT>::iterator wit =
mres.find(dit->first);
if (wit != mres.end()) {
if (dit->second->FillResult(wit->second.staging) || force) {
DSReturnType rt =
dit->second->FillResult(wit->second.staging);
if ((force && rt) || (!force && rt == DSR_OK)) {
wit->second.__isset.staging = true;
}
} else {
ResultT res;
if (dit->second->FillResult(res.staging) || force) {
DSReturnType rt =
dit->second->FillResult(res.staging);
if ((force && rt) || (!force && rt == DSR_OK)) {
res.__isset.staging = true;
mres.insert(std::make_pair(dit->first, res));
}
Expand Down

0 comments on commit 7247c12

Please sign in to comment.