Commit a0b15826 by amir

add dropwizard metrics

parent e6902158
Pipeline #83 skipped in 0 seconds
...@@ -13,15 +13,16 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) ...@@ -13,15 +13,16 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# linked libs and their locations # linked libs and their locations
set ( PROJECT_LINK_LIBS -ljson -lhiredis -lcpprest -lboost_random -lboost_chrono set ( PROJECT_LINK_LIBS -ljson -lhiredis -lcpprest -lcppmetrics -lboost_random -lboost_chrono
-lboost_system -lboost_thread -lboost_regex -lboost_filesystem -lpthread -lboost_system -lboost_thread -lboost_regex -lboost_filesystem -lpthread
-lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl -lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl
-lcrypto -lrabbitmq -llog4cpp) -lcrypto -lrabbitmq -llog4cpp -lglog )
link_directories( ../3party/lib ) link_directories( ../3party/lib )
# h files locations # h files locations
include_directories(src) include_directories(src)
include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson) include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson)
include_directories(SYSTEM ../3party/cppmetrics-0.1.1-Linux/include)
include_directories(SYSTEM ../3party/mongoose) include_directories(SYSTEM ../3party/mongoose)
include_directories(SYSTEM /usr/include/hiredis) include_directories(SYSTEM /usr/include/hiredis)
# recursive search files cpp files # recursive search files cpp files
......
...@@ -5,4 +5,5 @@ ...@@ -5,4 +5,5 @@
# #
# Created on May 8, 2016, 9:59:18 AM # Created on May 8, 2016, 9:59:18 AM
# #
sudo apt-get install -y libhiredis0.10 libhiredis-dev libzmq3 libzmq3-dev liblog4cpp5 liblog4cpp5-dev sudo apt-get install -y libhiredis0.10 libhiredis-dev libzmq3 libzmq3-dev liblog4cpp5 liblog4cpp5-dev \
\ No newline at end of file libgoogle-glog-dev
\ No newline at end of file
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <condition_variable> #include <condition_variable>
#include <signal.h> #include <signal.h>
#include "impl/MSIMetricsFactoryDropwisardImpl.h"
static bool exit_app = false; static bool exit_app = false;
// sync // sync
...@@ -39,6 +41,7 @@ cMicroservice_App::cMicroservice_App(const char* appName) { ...@@ -39,6 +41,7 @@ cMicroservice_App::cMicroservice_App(const char* appName) {
mpc_PubSubClient = nullptr; mpc_PubSubClient = nullptr;
mpc_ServiceDiscovery = nullptr; mpc_ServiceDiscovery = nullptr;
enableMetrics = false; enableMetrics = false;
metricsFactory_ = nullptr;
mc_AppName.assign(appName); mc_AppName.assign(appName);
} }
...@@ -239,6 +242,11 @@ cMicroservice_App& cMicroservice_App::build() { ...@@ -239,6 +242,11 @@ cMicroservice_App& cMicroservice_App::build() {
mpc_Configuration->AddConfigurationProvider(mpc_ServiceDiscovery->getConfigurationProvider()); mpc_Configuration->AddConfigurationProvider(mpc_ServiceDiscovery->getConfigurationProvider());
} }
if(enableMetrics)
{
metricsFactory_ = new MSIMetricsFactoryDropwisardImpl();
metricsFactory_->startReporting();
}
mpc_Configuration->Reload(); mpc_Configuration->Reload();
/* /*
* post setting params for all handlers * post setting params for all handlers
...@@ -270,7 +278,7 @@ cMicroservice_App& cMicroservice_App::build() { ...@@ -270,7 +278,7 @@ cMicroservice_App& cMicroservice_App::build() {
*/ */
for(auto& server : mc_ServerList) for(auto& server : mc_ServerList)
{ {
server->build(this->mc_AppName,mc_HandlersMap,mpc_Logger,mpc_PubSubClient,enableMetrics); server->build(this->mc_AppName,mc_HandlersMap,mpc_Logger,mpc_PubSubClient,metricsFactory_);
} }
/* /*
......
...@@ -51,6 +51,7 @@ private: ...@@ -51,6 +51,7 @@ private:
IPubSub* mpc_PubSubClient; IPubSub* mpc_PubSubClient;
IConfiguration* mpc_Configuration; IConfiguration* mpc_Configuration;
cMicroservice_MonitorHandler* mpc_MonitorHandler; cMicroservice_MonitorHandler* mpc_MonitorHandler;
IMetricsFactory* metricsFactory_;
// servers // servers
// cMicroservice_RestServer* mpc_RestServer; // cMicroservice_RestServer* mpc_RestServer;
// cMicroservice_RMQServer* mpc_RMQServer; // cMicroservice_RMQServer* mpc_RMQServer;
...@@ -85,7 +86,7 @@ public: ...@@ -85,7 +86,7 @@ public:
*/ */
cMicroservice_App& withMetrics() cMicroservice_App& withMetrics()
{ {
// enableMetrics = true; enableMetrics = true;
return *this; return *this;
} }
/** /**
...@@ -141,6 +142,7 @@ public: ...@@ -141,6 +142,7 @@ public:
return mc_ClientMap[ms_name]; return mc_ClientMap[ms_name];
} }
std::map<std::string, cMicroservice_Client*>& GetClientMap() { return mc_ClientMap; } std::map<std::string, cMicroservice_Client*>& GetClientMap() { return mc_ClientMap; }
IMetricsFactory* GetMetricsFactory() const { return metricsFactory_; }
}; };
......
...@@ -147,8 +147,7 @@ namespace nsMicroservice_Iface ...@@ -147,8 +147,7 @@ namespace nsMicroservice_Iface
virtual IMeter* createMeter(std::string& name) = 0; virtual IMeter* createMeter(std::string& name) = 0;
virtual ICounter* createCounter(std::string& name) = 0; virtual ICounter* createCounter(std::string& name) = 0;
virtual ITimer* createTimer(std::string& name) = 0; virtual ITimer* createTimer(std::string& name) = 0;
virtual void GetMetrics(std::map<std::string,long>& metrics_map) = 0;
}; };
...@@ -184,7 +183,7 @@ namespace nsMicroservice_Iface ...@@ -184,7 +183,7 @@ namespace nsMicroservice_Iface
std::map<std::string, cMicroservice_BaseHandler*>& msHandlersMap, std::map<std::string, cMicroservice_BaseHandler*>& msHandlersMap,
ILogger* pc_Logger, ILogger* pc_Logger,
IPubSub* pc_PubSub, IPubSub* pc_PubSub,
bool withMetrics) = 0; IMetricsFactory* p_metrics_factory) = 0;
virtual void run() = 0; virtual void run() = 0;
virtual void stop() = 0; virtual void stop() = 0;
virtual void registerService(IServiceDiscovery* pc_ServiceDiscovery, std::string& id) = 0; virtual void registerService(IServiceDiscovery* pc_ServiceDiscovery, std::string& id) = 0;
......
...@@ -93,6 +93,22 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext ...@@ -93,6 +93,22 @@ void cMicroservice_MonitorHandler::HandleStatistics(cMicroservice_RequestContext
doc.AddMember(client.first.c_str(),counters,rpj_Alloc); doc.AddMember(client.first.c_str(),counters,rpj_Alloc);
} }
} }
/*
* metrics registry
*/
metrics_map.clear();
rapidjson::Value counters(rapidjson::kObjectType);
this->mpc_msApp->GetMetricsFactory()->GetMetrics(metrics_map);
if(!metrics_map.empty())
{
for(auto counter : metrics_map)
{
counters.AddMember(counter.first.c_str(),counter.second,rpj_Alloc);
}
doc.AddMember("handlers",counters,rpj_Alloc);
}
// for (auto p_handler : handlers_) // for (auto p_handler : handlers_)
// { // {
// doc.AddMember(name,counters,rpj_Alloc); // doc.AddMember(name,counters,rpj_Alloc);
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
#include <sstream> #include <sstream>
#include "impl/MSIMetricsFactoryDropwisardImpl.h"
cMicroservice_RestHandler::cMicroservice_RestHandler(std::string apiContextPath,cMicroservice_BaseHandler* pc_Handler): cMicroservice_RestHandler::cMicroservice_RestHandler(std::string apiContextPath,cMicroservice_BaseHandler* pc_Handler):
mpc_Handler(pc_Handler),mpc_Logger(nullptr),mpc_PubSub(nullptr) mpc_Handler(pc_Handler),mpc_Logger(nullptr),mpc_PubSub(nullptr),p_metrics_factory_(nullptr)
{ {
mpc_Buffer = new rapidjson::StringBuffer(0,nsMicroservice_Constants::MAX_JSON_BUFFER); mpc_Buffer = new rapidjson::StringBuffer(0,nsMicroservice_Constants::MAX_JSON_BUFFER);
mpc_Writer = new JsonStringWriter(*mpc_Buffer); mpc_Writer = new JsonStringWriter(*mpc_Buffer);
...@@ -40,6 +42,7 @@ mpc_Handler(pc_Handler),mpc_Logger(nullptr),mpc_PubSub(nullptr) ...@@ -40,6 +42,7 @@ mpc_Handler(pc_Handler),mpc_Logger(nullptr),mpc_PubSub(nullptr)
*/ */
void cMicroservice_RestHandler::HandleRequest(mg_connection *conn,http_message *msg) void cMicroservice_RestHandler::HandleRequest(mg_connection *conn,http_message *msg)
{ {
cppmetrics::core::TimerContextPtr timer;
/* /*
* get request context * get request context
*/ */
...@@ -52,9 +55,13 @@ void cMicroservice_RestHandler::HandleRequest(mg_connection *conn,http_message * ...@@ -52,9 +55,13 @@ void cMicroservice_RestHandler::HandleRequest(mg_connection *conn,http_message *
* now check the method * now check the method
*/ */
cMicroservice_Enums::eMethod e_Method = GetMethod(msg); cMicroservice_Enums::eMethod e_Method = GetMethod(msg);
if(p_metrics_factory_)
PreHandleMetrics(e_Method);
switch (e_Method) switch (e_Method)
{ {
case cMicroservice_Enums::eGet: case cMicroservice_Enums::eGet:
DoGet(mpc_RequestContext); DoGet(mpc_RequestContext);
break; break;
case cMicroservice_Enums::ePost: case cMicroservice_Enums::ePost:
...@@ -71,7 +78,8 @@ void cMicroservice_RestHandler::HandleRequest(mg_connection *conn,http_message * ...@@ -71,7 +78,8 @@ void cMicroservice_RestHandler::HandleRequest(mg_connection *conn,http_message *
break; break;
} }
if(p_metrics_factory_)
PostHandleMetrics(e_Method);
} }
/** /**
...@@ -244,3 +252,57 @@ void cMicroservice_RestHandler::LogRequest(http_message* msg) { ...@@ -244,3 +252,57 @@ void cMicroservice_RestHandler::LogRequest(http_message* msg) {
str.append(", query string: ").append(msg->query_string.p,msg->query_string.len); str.append(", query string: ").append(msg->query_string.p,msg->query_string.len);
mpc_Logger->debug(str); mpc_Logger->debug(str);
} }
void cMicroservice_RestHandler::CreateMetrics() {
std::string str;
p_get_meter_ = p_metrics_factory_->createMeter(apiContextPath.substr(1).append(".get.requests.count"));
p_post_meter_ = p_metrics_factory_->createMeter(apiContextPath.substr(1).append(".post.requests.count"));
p_put_meter_ = p_metrics_factory_->createMeter(apiContextPath.substr(1).append(".put.requests.count"));
p_delete_meter_ = p_metrics_factory_->createMeter(apiContextPath.substr(1).append(".delete.requests.count"));
p_get_timer_ = p_metrics_factory_->createTimer(apiContextPath.substr(1).append(".get.requests.timer"));
p_post_timer_ = p_metrics_factory_->createTimer(apiContextPath.substr(1).append(".post.requests.timer"));
}
void cMicroservice_RestHandler::PreHandleMetrics(cMicroservice_Enums::eMethod e_Method) {
switch(e_Method)
{
case cMicroservice_Enums::eGet:
p_get_meter_->mark();
p_get_timer_->start();
break;
case cMicroservice_Enums::ePost:
p_post_meter_->mark();
p_post_timer_->start();
break;
case cMicroservice_Enums::ePut:
p_put_meter_->mark();
break;
case cMicroservice_Enums::eDelete:
p_delete_meter_->mark();
break;
default:
break;
}
}
void cMicroservice_RestHandler::PostHandleMetrics(cMicroservice_Enums::eMethod e_Method)
{
switch(e_Method)
{
case cMicroservice_Enums::eGet:
p_get_timer_->stop();
break;
case cMicroservice_Enums::ePost:
p_post_timer_->stop();
break;
case cMicroservice_Enums::ePut:
break;
case cMicroservice_Enums::eDelete:
break;
default:
break;
}
}
...@@ -32,7 +32,15 @@ private: ...@@ -32,7 +32,15 @@ private:
cMicroservice_RequestContext* mpc_RequestContext; cMicroservice_RequestContext* mpc_RequestContext;
char mba_Buff[nsMicroservice_Constants::MAX_URI_LENGTH]; char mba_Buff[nsMicroservice_Constants::MAX_URI_LENGTH];
char mba_ErrorBuff[nsMicroservice_Constants::MAX_ERROR_BUFF_URI_LENGTH]; char mba_ErrorBuff[nsMicroservice_Constants::MAX_ERROR_BUFF_URI_LENGTH];
bool mb_EnableMetrics; nsMicroservice_Iface::IMetricsFactory* p_metrics_factory_;
// metrics
nsMicroservice_Iface::IMetricsFactory::IMeter* p_get_meter_;
nsMicroservice_Iface::IMetricsFactory::IMeter* p_post_meter_;
nsMicroservice_Iface::IMetricsFactory::IMeter* p_put_meter_;
nsMicroservice_Iface::IMetricsFactory::IMeter* p_delete_meter_;
nsMicroservice_Iface::IMetricsFactory::ITimer* p_get_timer_;
nsMicroservice_Iface::IMetricsFactory::ITimer* p_post_timer_;
cMicroservice_Enums::eMethod GetMethod(http_message *msg); cMicroservice_Enums::eMethod GetMethod(http_message *msg);
...@@ -49,10 +57,17 @@ private: ...@@ -49,10 +57,17 @@ private:
void SetRequestContext(mg_connection *conn,http_message *msg); void SetRequestContext(mg_connection *conn,http_message *msg);
void GetQueryParams(http_message *msg); void GetQueryParams(http_message *msg);
void LogRequest(http_message *msg); void LogRequest(http_message *msg);
void CreateMetrics();
void PreHandleMetrics(cMicroservice_Enums::eMethod e_Method);
void PostHandleMetrics(cMicroservice_Enums::eMethod e_Method);
public: public:
cMicroservice_RestHandler(std::string apiContextPath,cMicroservice_BaseHandler* pc_Handler); cMicroservice_RestHandler(std::string apiContextPath,cMicroservice_BaseHandler* pc_Handler);
void enableMetrics(bool b_EnableMetrics) { this->mb_EnableMetrics = b_EnableMetrics;} void withMetrics(nsMicroservice_Iface::IMetricsFactory* p_metrics_factory) {
this->p_metrics_factory_ = p_metrics_factory;
CreateMetrics();
}
void withLogger(nsMicroservice_Iface::ILogger* pc_Logger) { this->mpc_Logger = pc_Logger; } void withLogger(nsMicroservice_Iface::ILogger* pc_Logger) { this->mpc_Logger = pc_Logger; }
void withPubSub(nsMicroservice_Iface::IPubSub* pc_PubSub) { this->mpc_PubSub = pc_PubSub; } void withPubSub(nsMicroservice_Iface::IPubSub* pc_PubSub) { this->mpc_PubSub = pc_PubSub; }
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: MSIMetricsFactoryDropwisardImpl.cpp
* Author: amir
*
* Created on May 22, 2016, 11:24 AM
*/
#include "MSIMetricsFactoryDropwisardImpl.h"
#include <boost/chrono.hpp>
#include <chrono>
#define NANOS_IN_MILLI 1000000
thread_local boost::chrono::high_resolution_clock::time_point start_time;//cppmetrics::core::TimerContextPtr timer_ctx_;
MSIMetricsFactoryDropwisardImpl::MSIMetricsFactoryDropwisardImpl() :
registry_(cppmetrics::core::MetricRegistry::DEFAULT_REGISTRY())
{
}
MSIMetricsFactoryDropwisardImpl::MSIMetricsFactoryDropwisardImpl(const MSIMetricsFactoryDropwisardImpl& orig) {
}
MSIMetricsFactoryDropwisardImpl::~MSIMetricsFactoryDropwisardImpl() {
}
IMetricsFactory::ICounter* MSIMetricsFactoryDropwisardImpl::createCounter(std::string& name){
return new ICounterDropwisardImpl(registry_->counter(name));
}
IMetricsFactory::IMeter* MSIMetricsFactoryDropwisardImpl::createMeter(std::string& name)
{
return new IMeterDropwisardImpl(registry_->meter(name));
}
IMetricsFactory::ITimer* MSIMetricsFactoryDropwisardImpl::createTimer(std::string& name)
{
return new ITimerDropwisardImpl(registry_->timer(name));
}
void MSIMetricsFactoryDropwisardImpl::startReporting()
{
}
void MSIMetricsFactoryDropwisardImpl::ITimerDropwisardImpl::start() {
//timer_->clear();
start_time = boost::chrono::high_resolution_clock::now();// Clock::now();
}
void MSIMetricsFactoryDropwisardImpl::ITimerDropwisardImpl::stop() {
//auto timer_ctx = timer_->timerContextPtr();
boost::chrono::nanoseconds dur = boost::chrono::high_resolution_clock::now() - start_time;
timer_->update(dur);
}
void MSIMetricsFactoryDropwisardImpl::GetMetrics(std::map<std::string, long>& metrics_map) {
std::string str;
for (auto counter : registry_->getCounters())
{
metrics_map["counter." + counter.first] = counter.second->getCount();
}
for (auto meter : registry_->getMeters())
{
register auto meter_ptr = meter.second;
str.assign("meter." + meter.first);
metrics_map[str] = meter_ptr->getCount();
metrics_map[str + ".mean_rate"] = meter_ptr->getMeanRate();
metrics_map[str + ".1m_rate"] = meter_ptr->getOneMinuteRate();
metrics_map[str + ".5m_rate"] = meter_ptr->getFiveMinuteRate();
metrics_map[str + ".15m_rate"] = meter_ptr->getFifteenMinuteRate();
}
for (auto timer : registry_->getTimers())
{
register auto timer_snapshot_ptr = timer.second->getSnapshot();
str.assign("timer." + timer.first);
metrics_map[str + ".mean_rate(ms)"] = timer_snapshot_ptr->getMean() / NANOS_IN_MILLI;
metrics_map[str + ".min(ms)"] = timer_snapshot_ptr->getMin() / NANOS_IN_MILLI;
metrics_map[str + ".max(ms)"] = timer_snapshot_ptr->getMax() / NANOS_IN_MILLI;
metrics_map[str + ".median(ms)"] = timer_snapshot_ptr->getMedian() / NANOS_IN_MILLI;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: MSIMetricsFactoryDropwisardImpl.h
* Author: amir
*
* Created on May 22, 2016, 11:24 AM
*/
#ifndef MSIMETRICSFACTORYDROPWISARDIMPL_H
#define MSIMETRICSFACTORYDROPWISARDIMPL_H
#include "../Microservice_Iface.h"
#include <cppmetrics/cppmetrics.h>
using namespace nsMicroservice_Iface;
class MSIMetricsFactoryDropwisardImpl : public IMetricsFactory {
public:
MSIMetricsFactoryDropwisardImpl();
MSIMetricsFactoryDropwisardImpl(const MSIMetricsFactoryDropwisardImpl& orig);
virtual ~MSIMetricsFactoryDropwisardImpl();
IMetricsFactory::ICounter* createCounter(std::string& name) override;
IMetricsFactory::IMeter* createMeter(std::string& name) override;
IMetricsFactory::ITimer* createTimer(std::string& name) override;
void startReporting() override;
void GetMetrics(std::map<std::string, long>& metrics_map) override;
cppmetrics::core::MetricRegistryPtr GetRegistry() const {
return registry_;
}
private:
cppmetrics::core::MetricRegistryPtr registry_;
public:
class IMeterDropwisardImpl : public IMeter
{
public:
IMeterDropwisardImpl(cppmetrics::core::MeterPtr p_meter) : meter_(p_meter){
}
long getCount() { return meter_->getCount(); }
void mark() { meter_->mark(1); }
void mark(long n) { meter_->mark(n);}
private:
cppmetrics::core::MeterPtr meter_;
};
class ICounterDropwisardImpl : public ICounter
{
public:
void dec(long n) { counter_->decrement(n); }
void dec() { counter_->decrement(1);}
long getCount() { return counter_->getCount();}
void inc(long n) { counter_->increment(n); }
void inc() { counter_->increment(1); }
ICounterDropwisardImpl(cppmetrics::core::CounterPtr p_counter) : counter_(p_counter){
counter_->setCount(0);
}
private:
cppmetrics::core::CounterPtr counter_;
};
class ITimerDropwisardImpl : public ITimer
{
public:
ITimerDropwisardImpl(cppmetrics::core::TimerPtr timer_) :
timer_(timer_) {
}
template<class Function>
void measure_func(Function fn){
auto timer_ctx = timer_->timerContextPtr();
fn();
}
virtual void start();
virtual void stop();
private:
cppmetrics::core::TimerPtr timer_;
};
};
#endif /* MSIMETRICSFACTORYDROPWISARDIMPL_H */
...@@ -44,3 +44,7 @@ IMetricsFactory::ITimer* MSIMetricsFactoryStdImpl::createTimer(std::string& name ...@@ -44,3 +44,7 @@ IMetricsFactory::ITimer* MSIMetricsFactoryStdImpl::createTimer(std::string& name
void MSIMetricsFactoryStdImpl::startReporting() { void MSIMetricsFactoryStdImpl::startReporting() {
} }
void MSIMetricsFactoryStdImpl::GetMetrics(std::map<std::string, long>& metrics_map) {
}
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
using namespace nsMicroservice_Iface; using namespace nsMicroservice_Iface;
class MSIMetricsFactoryStdImpl : public IMetricsFactory { class MSIMetricsFactoryStdImpl : public IMetricsFactory {
...@@ -58,6 +59,7 @@ public: ...@@ -58,6 +59,7 @@ public:
IMetricsFactory::IMeter* createMeter(std::string& name) override; IMetricsFactory::IMeter* createMeter(std::string& name) override;
IMetricsFactory::ITimer* createTimer(std::string& name) override; IMetricsFactory::ITimer* createTimer(std::string& name) override;
void startReporting() override; void startReporting() override;
void GetMetrics(std::map<std::string, long>& metrics_map) override;
......
...@@ -84,6 +84,8 @@ void MSICommandClientHttpImpl::HandleCommand(HandleCommandData* p_cmd_data){ ...@@ -84,6 +84,8 @@ void MSICommandClientHttpImpl::HandleCommand(HandleCommandData* p_cmd_data){
p_cmd_data->p_retstat->SetError(NULL_REST_RESPONSE_OBJECT); p_cmd_data->p_retstat->SetError(NULL_REST_RESPONSE_OBJECT);
return; return;
} }
try
{
if(BuildUrl(p_cmd_data->p_cmd_params,url)) if(BuildUrl(p_cmd_data->p_cmd_params,url))
{ {
p_cmd_data->p_response->Reset(); p_cmd_data->p_response->Reset();
...@@ -142,6 +144,13 @@ void MSICommandClientHttpImpl::HandleCommand(HandleCommandData* p_cmd_data){ ...@@ -142,6 +144,13 @@ void MSICommandClientHttpImpl::HandleCommand(HandleCommandData* p_cmd_data){
{ {
p_cmd_data->p_retstat->SetError(FAILED_BUILD_URL); p_cmd_data->p_retstat->SetError(FAILED_BUILD_URL);
} }
}
catch (web::http::http_exception exp)
{
p_cmd_data->p_retstat->SetError(exp.what());
LOG_ERROR(exp.what());
p_cmd_data->p_command_counters->failed++;
}
} }
MSRetStat MSICommandClientHttpImpl::Create(MSCommandParams* p_cmd_params, cMicroservice_BaseRestResponse* p_response) { MSRetStat MSICommandClientHttpImpl::Create(MSCommandParams* p_cmd_params, cMicroservice_BaseRestResponse* p_response) {
......
...@@ -63,7 +63,7 @@ cMicroservice_IRestServerMongooseImpl::~cMicroservice_IRestServerMongooseImpl() ...@@ -63,7 +63,7 @@ cMicroservice_IRestServerMongooseImpl::~cMicroservice_IRestServerMongooseImpl()
bool cMicroservice_IRestServerMongooseImpl::build(std::string& appName, std::map<std::string, cMicroservice_BaseHandler*>& msHandlersMap, bool cMicroservice_IRestServerMongooseImpl::build(std::string& appName, std::map<std::string, cMicroservice_BaseHandler*>& msHandlersMap,
nsMicroservice_Iface::ILogger* pc_Logger, nsMicroservice_Iface::ILogger* pc_Logger,
nsMicroservice_Iface::IPubSub* pc_PubSub, nsMicroservice_Iface::IPubSub* pc_PubSub,
bool withMetrics) { nsMicroservice_Iface::IMetricsFactory* p_metrics_factory) {
bool result = false; bool result = false;
if (this->mpc_Param) if (this->mpc_Param)
...@@ -103,7 +103,7 @@ bool cMicroservice_IRestServerMongooseImpl::build(std::string& appName, std::map ...@@ -103,7 +103,7 @@ bool cMicroservice_IRestServerMongooseImpl::build(std::string& appName, std::map
cMicroservice_RestHandler* pc_RestHandler = new cMicroservice_RestHandler(prfxHandler.first,prfxHandler.second); cMicroservice_RestHandler* pc_RestHandler = new cMicroservice_RestHandler(prfxHandler.first,prfxHandler.second);
pc_RestHandler->withLogger(pc_Logger); pc_RestHandler->withLogger(pc_Logger);
pc_RestHandler->withPubSub(pc_PubSub); pc_RestHandler->withPubSub(pc_PubSub);
pc_RestHandler->enableMetrics(withMetrics); pc_RestHandler->withMetrics(p_metrics_factory);
this->mc_HandlersMap[prfxHandler.first] = pc_RestHandler; this->mc_HandlersMap[prfxHandler.first] = pc_RestHandler;
} }
result = true; result = true;
......
...@@ -32,7 +32,7 @@ public: ...@@ -32,7 +32,7 @@ public:
bool build(std::string& appName, std::map<std::string,cMicroservice_BaseHandler*>& msHandlersMap, bool build(std::string& appName, std::map<std::string,cMicroservice_BaseHandler*>& msHandlersMap,
nsMicroservice_Iface::ILogger* pc_Logger, nsMicroservice_Iface::ILogger* pc_Logger,
nsMicroservice_Iface::IPubSub* pc_PubSub, nsMicroservice_Iface::IPubSub* pc_PubSub,
bool withMetrics) override; nsMicroservice_Iface::IMetricsFactory* p_metrics_factory) override;
void registerService(nsMicroservice_Iface::IServiceDiscovery* pc_ServiceDiscovery, std::string& id) override; void registerService(nsMicroservice_Iface::IServiceDiscovery* pc_ServiceDiscovery, std::string& id) override;
......
...@@ -62,7 +62,10 @@ public: ...@@ -62,7 +62,10 @@ public:
.WithParamsString("search") .WithParamsString("search")
.WithRequestParams("q=base"); .WithRequestParams("q=base");
MSRetStat retstat = p_client_->Read(&cmd_params,&rest_response); MSRetStat retstat = p_client_->Read(&cmd_params,&rest_response);
if(retstat.IsSuccess())
this->WriteObjectToResponse(pc_reqCtx,rest_response); this->WriteObjectToResponse(pc_reqCtx,rest_response);
else
this->SendErrorResp(pc_reqCtx,retstat.GetError());
//this->WriteObjectToResponse(pc_reqCtx,rpj_Doc); //this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment