Commit df65b049 authored by Vaastav Anand's avatar Vaastav Anand

Add instrumentation for UserHandler and UserReviewHandler

parent c2dbd92c
......@@ -14,6 +14,8 @@
#include "../ClientPool.h"
#include "../RedisClient.h"
#include "../ThriftClient.h"
#include <xtrace/xtrace.h>
#include <xtrace/baggage.h>
namespace media_service {
class UserReviewHandler : public UserReviewServiceIf {
......@@ -51,6 +53,15 @@ void UserReviewHandler::UploadUserReview(
int64_t timestamp,
const std::map<std::string, std::string> &carrier) {
std::map<std::string, std::string>::const_iterator baggage_it = carrier.find("baggage");
if (baggage_it != carrier.end()) {
SET_CURRENT_BAGGAGE(Baggage::deserialize(baggage_it->second));
}
if (!XTrace::IsTracing()) {
XTrace::StartTrace("UserReviewHandler");
}
XTRACE("UserReviewHandler::UploadUserReview", {{"RequestID", std::to_string(req_id)}});
// Initialize a span
TextMapReader reader(carrier);
std::map<std::string, std::string> writer_text_map;
......@@ -67,6 +78,7 @@ void UserReviewHandler::UploadUserReview(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = "Failed to pop a client from MongoDB pool";
XTRACE("Failed to pop a client from MongoDB pool");
throw se;
}
......@@ -76,16 +88,19 @@ void UserReviewHandler::UploadUserReview(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = "Failed to create collection user-review from DB user-review";
XTRACE("Failed to create collection user-review from DB user-review");
mongoc_client_pool_push(_mongodb_client_pool, mongodb_client);
throw se;
}
bson_t *query = bson_new();
BSON_APPEND_INT64(query, "user_id", user_id);
XTRACE("MongoFindUser start");
auto find_span = opentracing::Tracer::Global()->StartSpan(
"MongoFindUser", {opentracing::ChildOf(&span->context())});
mongoc_cursor_t *cursor = mongoc_collection_find_with_opts(
collection, query, nullptr, nullptr);
XTRACE("MongoFindUser complete");
const bson_t *doc;
bool found = mongoc_cursor_next(cursor, &doc);
if (!found) {
......@@ -96,14 +111,17 @@ void UserReviewHandler::UploadUserReview(
"timestamp", BCON_INT64(timestamp), "}", "]"
);
bson_error_t error;
XTRACE("MongoInsert start");
auto insert_span = opentracing::Tracer::Global()->StartSpan(
"MongoInsert", {opentracing::ChildOf(&span->context())});
bool plotinsert = mongoc_collection_insert_one(
collection, new_doc, nullptr, nullptr, &error);
insert_span->Finish();
XTRACE("MongoInsert finish");
if (!plotinsert) {
LOG(error) << "Failed to insert user review of user " << user_id
<< " to MongoDB: " << error.message;
XTRACE("Failed to insert user review of user " + std::to_string(user_id) + "to MongoDB");
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = error.message;
......@@ -129,15 +147,18 @@ void UserReviewHandler::UploadUserReview(
);
bson_error_t error;
bson_t reply;
XTRACE("MongoUpdate start");
auto update_span = opentracing::Tracer::Global()->StartSpan(
"MongoUpdate", {opentracing::ChildOf(&span->context())});
bool plotupdate = mongoc_collection_find_and_modify(
collection, query, nullptr, update, nullptr, false, false,
true, &reply, &error);
update_span->Finish();
XTRACE("MongoUpdate finish");
if (!plotupdate) {
LOG(error) << "Failed to update user-review for user " << user_id
<< " to MongoDB: " << error.message;
XTRACE("Failed to update user-review for user " + std::to_string(user_id) + " to MongoDB");
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = error.message;
......@@ -162,9 +183,11 @@ void UserReviewHandler::UploadUserReview(
ServiceException se;
se.errorCode = ErrorCode::SE_REDIS_ERROR;
se.message = "Cannot connected to Redis server";
XTRACE("Cannot connect to Redis server");
throw se;
}
auto redis_client = redis_client_wrapper->GetClient();
XTRACE("RedisUpdate start");
auto redis_span = opentracing::Tracer::Global()->StartSpan(
"RedisUpdate", {opentracing::ChildOf(&span->context())});
auto num_reviews = redis_client->zcard(std::to_string(user_id));
......@@ -179,7 +202,9 @@ void UserReviewHandler::UploadUserReview(
}
_redis_client_pool->Push(redis_client_wrapper);
redis_span->Finish();
XTRACE("RedisUpdate complete");
span->Finish();
XTRACE("UserReviewHandler::WriteReview complete");
}
void UserReviewHandler::ReadUserReviews(
......@@ -187,6 +212,15 @@ void UserReviewHandler::ReadUserReviews(
int64_t user_id, int32_t start, int32_t stop,
const std::map<std::string, std::string> & carrier) {
std::map<std::string, std::string>::const_iterator baggage_it = carrier.find("baggage");
if (baggage_it != carrier.end()) {
SET_CURRENT_BAGGAGE(Baggage::deserialize(baggage_it->second));
}
if (!XTrace::IsTracing()) {
XTrace::StartTrace("UserReviewHandler");
}
XTRACE("UserReviewHandler::ReadUserReviews", {{"RequestID", std::to_string(req_id)}});
// Initialize a span
TextMapReader reader(carrier);
std::map<std::string, std::string> writer_text_map;
......@@ -206,9 +240,11 @@ void UserReviewHandler::ReadUserReviews(
ServiceException se;
se.errorCode = ErrorCode::SE_REDIS_ERROR;
se.message = "Cannot connected to Redis server";
XTRACE("Cannot connect to Redis server");
throw se;
}
auto redis_client = redis_client_wrapper->GetClient();
XTRACE("RedisFind start");
auto redis_span = opentracing::Tracer::Global()->StartSpan(
"RedisFind", {opentracing::ChildOf(&span->context())});
auto review_ids_future = redis_client->zrevrange(
......@@ -221,6 +257,7 @@ void UserReviewHandler::ReadUserReviews(
review_ids_reply = review_ids_future.get();
} catch (...) {
LOG(error) << "Failed to read review_ids from user-review-redis";
XTRACE("Failed to read review_ids from user-review-redis");
_redis_client_pool->Push(redis_client_wrapper);
throw;
}
......@@ -241,6 +278,7 @@ void UserReviewHandler::ReadUserReviews(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = "Failed to pop a client from MongoDB pool";
XTRACE("Failed to pop a client from MongoDB pool");
throw se;
}
auto collection = mongoc_client_get_collection(
......@@ -249,6 +287,7 @@ void UserReviewHandler::ReadUserReviews(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = "Failed to create collection user-review from MongoDB";
XTRACE("Failed to create collection user-review from MongoDB");
throw se;
}
......@@ -259,11 +298,13 @@ void UserReviewHandler::ReadUserReviews(
"$slice", "[",
BCON_INT32(0), BCON_INT32(stop),
"]", "}", "}");
XTRACE("MongoFindUserReviews start");
auto find_span = opentracing::Tracer::Global()->StartSpan(
"MongoFindUserReviews", {opentracing::ChildOf(&span->context())});
mongoc_cursor_t *cursor = mongoc_collection_find_with_opts(
collection, query, opts, nullptr);
find_span->Finish();
XTRACE("MongoFindUserReviews finish");
const bson_t *doc;
bool found = mongoc_cursor_next(cursor, &doc);
if (found) {
......@@ -302,23 +343,28 @@ void UserReviewHandler::ReadUserReviews(
mongoc_client_pool_push(_mongodb_client_pool, mongodb_client);
}
Baggage review_baggage = BRANCH_CURRENT_BAGGAGE();
std::future<std::vector<Review>> review_future = std::async(
std::launch::async, [&]() {
BAGGAGE(review_baggage);
auto review_client_wrapper = _review_client_pool->Pop();
if (!review_client_wrapper) {
ServiceException se;
se.errorCode = ErrorCode::SE_THRIFT_CONN_ERROR;
se.message = "Failed to connected to review-storage-service";
XTRACE("Failed to connect to review-storage-service");
throw se;
}
std::vector<Review> _return_reviews;
auto review_client = review_client_wrapper->GetClient();
try {
writer_text_map["baggage"] = GET_CURRENT_BAGGAGE().str();
review_client->ReadReviews(
_return_reviews, req_id, review_ids, writer_text_map);
} catch (...) {
_review_client_pool->Push(review_client_wrapper);
LOG(error) << "Failed to read review from review-storage-service";
XTRACE("Failed to read review from review-storage-service");
throw;
}
_review_client_pool->Push(review_client_wrapper);
......@@ -333,9 +379,11 @@ void UserReviewHandler::ReadUserReviews(
ServiceException se;
se.errorCode = ErrorCode::SE_REDIS_ERROR;
se.message = "Cannot connected to Redis server";
XTRACE("Cannot connect to Redis server");
throw se;
}
redis_client = redis_client_wrapper->GetClient();
XTRACE("RedisUpdate start");
auto redis_update_span = opentracing::Tracer::Global()->StartSpan(
"RedisUpdate", {opentracing::ChildOf(&span->context())});
redis_client->del(std::vector<std::string>{std::to_string(user_id)});
......@@ -344,17 +392,21 @@ void UserReviewHandler::ReadUserReviews(
std::to_string(user_id), options, redis_update_map);
redis_client->commit();
redis_update_span->Finish();
XTRACE("RedisUpdate finish");
}
try {
_return = review_future.get();
JOIN_CURRENT_BAGGAGE(review_baggage);
} catch (...) {
LOG(error) << "Failed to get review from review-storage-service";
XTRACE("Failed to get review from review-storage-service");
if (!redis_update_map.empty()) {
try {
zadd_reply_future.get();
} catch (...) {
LOG(error) << "Failed to Update Redis Server";
XTRACE("Failed to Update Redis Server");
}
_redis_client_pool->Push(redis_client_wrapper);
}
......@@ -366,6 +418,7 @@ void UserReviewHandler::ReadUserReviews(
zadd_reply_future.get();
} catch (...) {
LOG(error) << "Failed to Update Redis Server";
XTRACE("Failed to Update Redis Server");
_redis_client_pool->Push(redis_client_wrapper);
throw;
}
......@@ -373,6 +426,8 @@ void UserReviewHandler::ReadUserReviews(
}
span->Finish();
XTRACE("UserReviewHandler::ReadUserReviews complete");
DELETE_CURRENT_BAGGAGE();
}
......
......@@ -24,6 +24,8 @@
#include "../../gen-cpp/ComposeReviewService.h"
#include "../../third_party/PicoSHA2/picosha2.h"
#include "../logger.h"
#include <xtrace/xtrace.h>
#include <xtrace/baggage.h>
// Custom Epoch (January 1, 2018 Midnight GMT = 2018-01-01T00:00:00Z)
#define CUSTOM_EPOCH 1514764800000
......@@ -137,6 +139,15 @@ void UserHandler::RegisterUser(
const std::string &password,
const std::map<std::string, std::string> &carrier) {
std::map<std::string, std::string>::const_iterator baggage_it = carrier.find("baggage");
if (baggage_it != carrier.end()) {
SET_CURRENT_BAGGAGE(Baggage::deserialize(baggage_it->second));
}
if (!XTrace::IsTracing()) {
XTrace::StartTrace("UserHandler");
}
XTRACE("UserHandler::RegisterUser", {{"RequestID", std::to_string(req_id)}});
// Initialize a span
TextMapReader reader(carrier);
std::map<std::string, std::string> writer_text_map;
......@@ -177,6 +188,7 @@ void UserHandler::RegisterUser(
std::string user_id_str = _machine_id + timestamp_hex + counter_hex;
int64_t user_id = stoul(user_id_str, nullptr, 16) & 0x7FFFFFFFFFFFFFFF;
LOG(debug) << "The user_id of the request " << req_id << " is " << user_id;
XTRACE("The user_id of the request " + std::to_string(req_id) + " is " + std::to_string(user_id));
mongoc_client_t *mongodb_client = mongoc_client_pool_pop(
_mongodb_client_pool);
......@@ -184,6 +196,7 @@ void UserHandler::RegisterUser(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = "Failed to pop a client from MongoDB pool";
XTRACE("Failed to pop a client from MongoDB pool");
throw se;
}
auto collection = mongoc_client_get_collection(
......@@ -206,9 +219,11 @@ void UserHandler::RegisterUser(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = error.message;
XTRACE(std::string(error.message));
throw se;
} else {
LOG(warning) << "User " << username << " already existed.";
XTRACE("User " + username + " already existed.");
ServiceException se;
se.errorCode = ErrorCode::SE_THRIFT_HANDLER_ERROR;
se.message = "User " + username + " already existed";
......@@ -230,6 +245,7 @@ void UserHandler::RegisterUser(
BSON_APPEND_UTF8(new_doc, "password", password_hashed.c_str());
bson_error_t error;
XTRACE("MongoInsertUser start");
auto user_insert_span = opentracing::Tracer::Global()->StartSpan(
"MongoInsertUser", { opentracing::ChildOf(&span->context()) });
if (!mongoc_collection_insert_one(
......@@ -240,6 +256,7 @@ void UserHandler::RegisterUser(
se.errorCode = ErrorCode::SE_THRIFT_HANDLER_ERROR;
se.message = "Failed to insert user " + username + " to MongoDB: "
+ error.message;
XTRACE("Failed to insert user " + username + " to MongoDB");
bson_destroy(query);
mongoc_cursor_destroy(cursor);
mongoc_collection_destroy(collection);
......@@ -247,8 +264,10 @@ void UserHandler::RegisterUser(
throw se;
} else {
LOG(debug) << "User: " << username << " registered";
XTRACE("User: " + username + " registered");
}
user_insert_span->Finish();
XTRACE("MongoInsertUser finish");
bson_destroy(new_doc);
}
mongoc_cursor_destroy(cursor);
......@@ -256,6 +275,8 @@ void UserHandler::RegisterUser(
mongoc_client_pool_push(_mongodb_client_pool, mongodb_client);
span->Finish();
XTRACE("UserHandler::RegisterUser complete");
DELETE_CURRENT_BAGGAGE();
}
void UserHandler::RegisterUserWithId(
......@@ -264,6 +285,15 @@ void UserHandler::RegisterUserWithId(
const std::string& password, int64_t user_id,
const std::map<std::string, std::string> & carrier) {
std::map<std::string, std::string>::const_iterator baggage_it = carrier.find("baggage");
if (baggage_it != carrier.end()) {
SET_CURRENT_BAGGAGE(Baggage::deserialize(baggage_it->second));
}
if (!XTrace::IsTracing()) {
XTrace::StartTrace("UserHandler");
}
XTRACE("UserHandler::RegisterUserWithId", {{"RequestID", std::to_string(req_id)}});
// Initialize a span
TextMapReader reader(carrier);
std::map<std::string, std::string> writer_text_map;
......@@ -280,6 +310,7 @@ void UserHandler::RegisterUserWithId(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = "Failed to pop a client from MongoDB pool";
XTRACE("Failed to pop a client from MongoDB pool");
throw se;
}
auto collection = mongoc_client_get_collection(
......@@ -302,9 +333,11 @@ void UserHandler::RegisterUserWithId(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = error.message;
XTRACE(std::string(error.message));
throw se;
} else {
LOG(warning) << "User " << username << " already existed.";
XTRACE("User " + username + " already existed");
ServiceException se;
se.errorCode = ErrorCode::SE_THRIFT_HANDLER_ERROR;
se.message = "User " + username + " already existed";
......@@ -326,6 +359,7 @@ void UserHandler::RegisterUserWithId(
BSON_APPEND_UTF8(new_doc, "password", password_hashed.c_str());
bson_error_t error;
XTRACE("MongoInsertUser start");
auto user_insert_span = opentracing::Tracer::Global()->StartSpan(
"MongoInsertUser", { opentracing::ChildOf(&span->context()) });
if (!mongoc_collection_insert_one(
......@@ -336,6 +370,7 @@ void UserHandler::RegisterUserWithId(
se.errorCode = ErrorCode::SE_THRIFT_HANDLER_ERROR;
se.message = "Failed to insert user " + username + " to MongoDB: "
+ error.message;
XTRACE("Failed to insert user " + username + " to MongoDB");
bson_destroy(query);
mongoc_cursor_destroy(cursor);
mongoc_collection_destroy(collection);
......@@ -343,6 +378,7 @@ void UserHandler::RegisterUserWithId(
throw se;
} else {
LOG(debug) << "User: " << username << " registered";
XTRACE("User " + username + " registered");
}
user_insert_span->Finish();
bson_destroy(new_doc);
......@@ -352,6 +388,8 @@ void UserHandler::RegisterUserWithId(
mongoc_client_pool_push(_mongodb_client_pool, mongodb_client);
span->Finish();
XTRACE("UserHandler::RegisterUserWithUserId complete");
DELETE_CURRENT_BAGGAGE();
}
void UserHandler::UploadUserWithUsername(
......@@ -359,6 +397,15 @@ void UserHandler::UploadUserWithUsername(
const std::string &username,
const std::map<std::string, std::string> & carrier) {
std::map<std::string, std::string>::const_iterator baggage_it = carrier.find("baggage");
if (baggage_it != carrier.end()) {
SET_CURRENT_BAGGAGE(Baggage::deserialize(baggage_it->second));
}
if (!XTrace::IsTracing()) {
XTrace::StartTrace("UserHandler");
}
XTRACE("UserHandler::UploadUserWithUsername", {{"RequestID", std::to_string(req_id)}});
TextMapReader reader(carrier);
std::map<std::string, std::string> writer_text_map;
TextMapWriter writer(writer_text_map);
......@@ -378,9 +425,11 @@ void UserHandler::UploadUserWithUsername(
ServiceException se;
se.errorCode = ErrorCode::SE_MEMCACHED_ERROR;
se.message = "Failed to pop a client from memcached pool";
XTRACE("Failed to pop a client from memcached pool");
throw se;
}
XTRACE("Memcached GetUserId start");
auto id_get_span = opentracing::Tracer::Global()->StartSpan(
"MmcGetUserId", { opentracing::ChildOf(&span->context()) });
char *user_id_mmc = memcached_get(
......@@ -404,18 +453,21 @@ void UserHandler::UploadUserWithUsername(
if (user_id_mmc) {
LOG(debug) << "Found password, salt and ID are cached in Memcached";
XTRACE("Found password, salt and ID are cached in Memcached");
user_id = std::stoul(user_id_mmc);
}
// If not cached in memcached
else {
LOG(debug) << "User_id not cached in Memcached";
XTRACE("User_id not cached in Memcached");
mongoc_client_t *mongodb_client = mongoc_client_pool_pop(
_mongodb_client_pool);
if (!mongodb_client) {
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = "Failed to pop a client from MongoDB pool";
XTRACE("Failed to pop a client from MongoDB pool");
free(user_id_mmc);
throw se;
}
......@@ -425,12 +477,14 @@ void UserHandler::UploadUserWithUsername(
ServiceException se;
se.errorCode = ErrorCode::SE_MONGODB_ERROR;
se.message = "Failed to create collection user from DB user";
XTRACE("Failed to create collection user from DB user");
free(user_id_mmc);
throw se;
}
bson_t *query = bson_new();
BSON_APPEND_UTF8(query, "username", username.c_str());
XTRACE("Mongo FindUser start");
auto find_span = opentracing::Tracer::Global()->StartSpan(
"MongoFindUser", { opentracing::ChildOf(&span->context()) });
mongoc_cursor_t *cursor = mongoc_collection_find_with_opts(
......@@ -438,6 +492,7 @@ void UserHandler::UploadUserWithUsername(
const bson_t *doc;
bool found = mongoc_cursor_next(cursor, &doc);
find_span->Finish();
XTRACE("Mongo FindUser finish");
if (!found) {
bson_error_t error;
......@@ -452,6 +507,7 @@ void UserHandler::UploadUserWithUsername(
throw se;
} else {
LOG(warning) << "User: " << username << " doesn't exist in MongoDB";
XTRACE("User: " + username + " doesn't exist in MongoDB");
mongoc_collection_destroy(collection);
mongoc_client_pool_push(_mongodb_client_pool, mongodb_client);
ServiceException se;
......@@ -463,11 +519,13 @@ void UserHandler::UploadUserWithUsername(
} else {
LOG(debug) << "User: " << username << " found in MongoDB";
bson_iter_t iter;
XTRACE("User: " + username + " found in MongoDB");
if (bson_iter_init_find(&iter, doc, "user_id")) {
user_id = bson_iter_value(&iter)->value.v_int64;
} else {
LOG(error) << "user_id attribute of user "
<< username <<" was not found in the User object";
XTRACE("user_id attribute of user " + username + " was not found in the User object");
bson_destroy(query);
mongoc_cursor_destroy(cursor);
mongoc_collection_destroy(collection);
......@@ -492,14 +550,17 @@ void UserHandler::UploadUserWithUsername(
ServiceException se;
se.errorCode = ErrorCode::SE_THRIFT_CONN_ERROR;
se.message = "Failed to connected to compose-review-service";
XTRACE("Failed to connect to compose-review-service");
throw se;
}
auto compose_client = compose_client_wrapper->GetClient();
try {
writer_text_map["baggage"] = BRANCH_CURRENT_BAGGAGE().str();
compose_client->UploadUserId(req_id, user_id, writer_text_map);
} catch (...) {
_compose_client_pool->Push(compose_client_wrapper);
LOG(error) << "Failed to upload movie_id to compose-review-service";
XTRACE("Failed to upload movie_id to compose-review-service");
throw;
}
_compose_client_pool->Push(compose_client_wrapper);
......@@ -511,11 +572,13 @@ void UserHandler::UploadUserWithUsername(
ServiceException se;
se.errorCode = ErrorCode::SE_MEMCACHED_ERROR;
se.message = "Failed to pop a client from memcached pool";
XTRACE("Failed to pop a client from memcached pool");
free(user_id_mmc);
throw se;
}
if (user_id && !user_id_mmc) {
XTRACE("Memcached SetUserId start");
auto id_set_span = opentracing::Tracer::Global()->StartSpan(
"MmcSetUserId", { opentracing::ChildOf(&span->context()) });
std::string user_id_str = std::to_string(user_id);
......@@ -534,12 +597,15 @@ void UserHandler::UploadUserWithUsername(
<< "Failed to set the user_id of user "
<< username << " to Memcached: "
<< memcached_strerror(memcached_client, memcached_rc);
XTRACE("Failed to set the user_id of user " + username + " to Memcached");
}
}
memcached_pool_push(_memcached_client_pool, memcached_client);
free(user_id_mmc);
span->Finish();
XTRACE("UserHandler::UploadUserWithUsername finish");
DELETE_CURRENT_BAGGAGE();
}
void UserHandler::UploadUserWithUserId(
......@@ -547,6 +613,15 @@ void UserHandler::UploadUserWithUserId(
int64_t user_id,
const std::map<std::string, std::string> &carrier) {
std::map<std::string, std::string>::const_iterator baggage_it = carrier.find("baggage");
if (baggage_it != carrier.end()) {
SET_CURRENT_BAGGAGE(Baggage::deserialize(baggage_it->second));
}
if (!XTrace::IsTracing()) {
XTrace::StartTrace("UserHandler");
}
XTRACE("UserHandler::UploadUserWithUserId", {{"RequestID", std::to_string(req_id)}});
TextMapReader reader(carrier);
std::map<std::string, std::string> writer_text_map;
TextMapWriter writer(writer_text_map);
......@@ -561,19 +636,24 @@ void UserHandler::UploadUserWithUserId(
ServiceException se;
se.errorCode = ErrorCode::SE_THRIFT_CONN_ERROR;
se.message = "Failed to connected to compose-review-service";
XTRACE("Failed to connect to compose-review-service");
throw se;
}
auto compose_client = compose_client_wrapper->GetClient();
try {
writer_text_map["baggage"] = BRANCH_CURRENT_BAGGAGE().str();
compose_client->UploadUserId(req_id, user_id, writer_text_map);
} catch (...) {
_compose_client_pool->Push(compose_client_wrapper);
LOG(error) << "Failed to upload movie_id to compose-review-service";
XTRACE("Failed to upload movie_id to compose-review-service");
throw;
}
_compose_client_pool->Push(compose_client_wrapper);
span->Finish();
XTRACE("UserHandler::UploadUserWithUserId complete");
DELETE_CURRENT_BAGGAGE();
}
......@@ -585,6 +665,15 @@ void UserHandler::Login(
const std::string &password,
const std::map<std::string, std::string> &carrier) {
std::map<std::string, std::string>::const_iterator baggage_it = carrier.find("baggage");
if (baggage_it != carrier.end()) {
SET_CURRENT_BAGGAGE(Baggage::deserialize(baggage_it->second));
}
if (!XTrace::IsTracing()) {
XTrace::StartTrace("UserHandler");
}
XTRACE("UserHandler::Login", {{"RequestID", std::to_string(req_id)}});
TextMapReader reader(carrier);
std::map<std::string, std::string> writer_text_map;
TextMapWriter writer(writer_text_map);
......@@ -606,9 +695,11 @@ void UserHandler::Login(
ServiceException se;
se.errorCode = ErrorCode::SE_MEMCACHED_ERROR;
se.message = "Failed to pop a client from memcached pool";
XTRACE("Failed to pop a client from memcached pool");
throw se;
}
XTRACE("Memcached GetPassword start");
auto pswd_get_span = opentracing::Tracer::Global()->StartSpan(
"MmcGetPassword", { opentracing::ChildOf(&span->context()) });
char *password_mmc = memcached_get(
......@@ -619,14 +710,17 @@ void UserHandler::Login(
&memcached_flags,
&memcached_rc);
pswd_get_span->Finish();
XTRACE("Memcached GetPassword finish");
if (!password_mmc && memcached_rc != MEMCACHED_NOTFOUND) {
ServiceException se;
se.errorCode = ErrorCode::SE_MEMCACHED_ERROR;
se.message = memcached_strerror(memcached_client, memcached_rc);
XTRACE(std::string(memcached_strerror(memcached_client, memcached_rc)));
memcached_pool_push(_memcached_client_pool, memcached_client);
throw se;
}
XTRACE("Memcached GetSalt start");
auto salt_get_span = opentracing::Tracer::Global()->StartSpan(
"MmcGetSalt", { opentracing::ChildOf(&span->context()) });
char *salt_mmc = memcached_get(
......@@ -637,15 +731,18 @@ void UserHandler::Login(
&memcached_flags,
&memcached_rc);
salt_get_span->Finish();
XTRACE("Memcached GetSalt finish");