Skip to content

Commit 82c1d52

Browse files
committed
refactor: Final changes to add correlationID to the few remaining routes
still displaying unknown
1 parent 20ac548 commit 82c1d52

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

core/server/DatabaseAPI.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// Third party includes
1414
#include <boost/algorithm/string.hpp>
1515
#include <boost/tokenizer.hpp>
16+
#include <boost/uuid/uuid.hpp>
17+
#include <boost/uuid/uuid_generators.hpp>
18+
#include <boost/uuid/uuid_io.hpp>
1619
#include <google/protobuf/util/json_util.h>
1720
#include <nlohmann/json.hpp>
1821
#include <zmq.h>
@@ -392,6 +395,13 @@ void DatabaseAPI::userSetAccessToken(const std::string &a_acc_tok,
392395
const SDMS::AccessTokenType &token_type,
393396
const std::string &other_token_data,
394397
LogContext log_context) {
398+
// Ensure correlation ID exists
399+
if (log_context.correlation_id.empty() ||
400+
log_context.correlation_id == "unknown") {
401+
402+
boost::uuids::random_generator generator;
403+
log_context.correlation_id = boost::uuids::to_string(generator());
404+
}
395405
string result;
396406
std::vector<pair<string, string>> params = {
397407
{"access", a_acc_tok},
@@ -465,6 +475,14 @@ void DatabaseAPI::purgeTransferRecords(size_t age, LogContext log_context) {
465475
void DatabaseAPI::userCreate(const SDMS::UserCreateRequest &a_request,
466476
SDMS::UserDataReply &a_reply,
467477
LogContext log_context) {
478+
// Ensure correlation ID exists
479+
if (log_context.correlation_id.empty() ||
480+
log_context.correlation_id == "unknown") {
481+
482+
boost::uuids::random_generator generator;
483+
log_context.correlation_id = boost::uuids::to_string(generator());
484+
}
485+
468486
DL_DEBUG(log_context,
469487
"DataFed user create - uid: " << a_request.uid()
470488
<< ", name: " << a_request.name());
@@ -2147,6 +2165,14 @@ void DatabaseAPI::setGroupData(GroupDataReply &a_reply,
21472165
void DatabaseAPI::repoList(const SDMS::RepoListRequest &a_request,
21482166
SDMS::RepoDataReply &a_reply,
21492167
LogContext log_context) {
2168+
// Ensure correlation ID exists
2169+
if (log_context.correlation_id.empty() ||
2170+
log_context.correlation_id == "unknown") {
2171+
2172+
boost::uuids::random_generator generator;
2173+
log_context.correlation_id = boost::uuids::to_string(generator());
2174+
}
2175+
21502176
Value result;
21512177

21522178
DL_DEBUG(log_context, "Calling repoList.");
@@ -2174,6 +2200,14 @@ void DatabaseAPI::repoList(std::vector<RepoData> &a_repos,
21742200

21752201
void DatabaseAPI::repoView(std::vector<RepoData> &a_repos,
21762202
LogContext log_context) {
2203+
// Ensure correlation ID exists
2204+
if (log_context.correlation_id.empty() ||
2205+
log_context.correlation_id == "unknown") {
2206+
2207+
boost::uuids::random_generator generator;
2208+
log_context.correlation_id = boost::uuids::to_string(generator());
2209+
}
2210+
21772211
const std::vector<RepoData> copy = a_repos;
21782212
a_repos.clear();
21792213
for (const RepoData &r : copy) {
@@ -3132,6 +3166,13 @@ void DatabaseAPI::taskRun(const std::string &a_task_id,
31323166
libjson::Value &a_task_reply, LogContext log_context,
31333167
int *a_step, std::string *a_err_msg) {
31343168
vector<pair<string, string>> params;
3169+
// Ensure correlation ID exists
3170+
if (log_context.correlation_id.empty() ||
3171+
log_context.correlation_id == "unknown") {
3172+
3173+
boost::uuids::random_generator generator;
3174+
log_context.correlation_id = boost::uuids::to_string(generator());
3175+
}
31353176
params.push_back({"task_id", a_task_id});
31363177
DL_DEBUG(log_context,
31373178
"Calling taskRun from DatabaseAPI task id: " << a_task_id);
@@ -3157,7 +3198,7 @@ void DatabaseAPI::taskAbort(const std::string &a_task_id,
31573198
}
31583199

31593200
void DatabaseAPI::taskInitDataGet(const SDMS::DataGetRequest &a_request,
3160-
SDMS::DataGetReply &a_reply,
3201+
SDMS::DataGetReply &a_reply,
31613202
libjson::Value &a_result,
31623203
LogContext log_context) {
31633204
nlohmann::json payload;
@@ -3803,6 +3844,14 @@ void DatabaseAPI::metricsUpdateMsgCounts(
38033844
const std::map<std::string, std::map<uint16_t, uint32_t>> &a_metrics,
38043845
LogContext log_context) {
38053846

3847+
// Ensure correlation ID exists
3848+
if (log_context.correlation_id.empty() ||
3849+
log_context.correlation_id == "unknown") {
3850+
3851+
boost::uuids::random_generator generator;
3852+
log_context.correlation_id = boost::uuids::to_string(generator());
3853+
}
3854+
38063855
std::string body = newJsonMetricParse(a_timestamp, a_total, a_metrics);
38073856

38083857
libjson::Value result;

0 commit comments

Comments
 (0)