Skip to content

Commit 2814714

Browse files
committed
QC-1289 Use consistently Bookkeeping facade in QC
The previously implemented token loading mechanism could not work because BookkeepingQualitySink was not using our Bookkeeping facade class, but the BkpClient directly. This commit makes BookkeepingQualitySink use it, thus take advantage of the token loading which was implemented there.
1 parent 27ea2a4 commit 2814714

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

Framework/include/QualityControl/Bookkeeping.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace o2::quality_control::core
2323
{
2424
class Activity;
2525

26+
// \brief A singleton class to handle the bookkeeping service interactions.
27+
//
28+
// All calls in QC code to Bookkeeping service should go through this class.
2629
class Bookkeeping
2730
{
2831
public:
@@ -39,6 +42,11 @@ class Bookkeeping
3942
void init(const std::string& url);
4043
void registerProcess(int runNumber, const std::string& name, const std::string& detector, bkp::DplProcessType type, const std::string& args);
4144

45+
// send QC flags to the bookkeeping service
46+
std::vector<int> sendFlagsForSynchronous(uint32_t runNumber, const std::string& detectorName, const std::vector<QcFlag>& qcFlags);
47+
std::vector<int> sendFlagsForDataPass(uint32_t runNumber, const std::string& passName, const std::string& detectorName, const std::vector<QcFlag>& qcFlags);
48+
std::vector<int> sendFlagsForSimulationPass(uint32_t runNumber, const std::string& productionName, const std::string& detectorName, const std::vector<QcFlag>& qcFlags);
49+
4250
private:
4351
Bookkeeping() = default;
4452

Framework/include/QualityControl/BookkeepingQualitySink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class BookkeepingQualitySink : public framework::Task
3939
// sendCallback is mainly used for testing without the necessity to do grpc calls
4040
BookkeepingQualitySink(const std::string& grpcUri, Provenance, SendCallback sendCallback = send);
4141

42+
void init(framework::InitContext&) override;
4243
void run(framework::ProcessingContext&) override;
4344

4445
void endOfStream(framework::EndOfStreamContext& context) override;

Framework/src/Bookkeeping.cxx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ using namespace o2::bkp::api;
2626
namespace o2::quality_control::core
2727
{
2828

29+
std::string readClientToken()
30+
{
31+
if (auto tokenEnv = std::getenv("QC_BKP_CLIENT_TOKEN"); tokenEnv != NULL && std::strlen(tokenEnv) > 0) {
32+
ILOG(Info, Ops) << "Using token from environment variable QC_BKP_CLIENT_TOKEN" << ENDM;
33+
return tokenEnv;
34+
}
35+
36+
ILOG(Debug, Devel) << "Could not find an env var QC_BKP_CLIENT_TOKEN, using BKP client without an authentication token" << ENDM;
37+
return "";
38+
}
39+
2940
void Bookkeeping::init(const std::string& url)
3041
{
3142
if (mInitialized) {
@@ -42,9 +53,11 @@ void Bookkeeping::init(const std::string& url)
4253
return;
4354
}
4455

56+
const auto token = readClientToken();
57+
4558
try {
46-
if (auto tokenEnv = std::getenv("QC_BKP_CLIENT_TOKEN"); tokenEnv != NULL) {
47-
mClient = BkpClientFactory::create(url, tokenEnv);
59+
if (!token.empty()) {
60+
mClient = BkpClientFactory::create(url, token);
4861
} else {
4962
mClient = BkpClientFactory::create(url);
5063
}
@@ -79,4 +92,29 @@ void Bookkeeping::registerProcess(int runNumber, const std::string& name, const
7992
}
8093
mClient->dplProcessExecution()->registerProcessExecution(runNumber, type, getHostName(), name, args, detector);
8194
}
95+
96+
std::vector<int> Bookkeeping::sendFlagsForSynchronous(uint32_t runNumber, const std::string& detectorName, const std::vector<QcFlag>& qcFlags)
97+
{
98+
if (!mInitialized) {
99+
return {};
100+
}
101+
return mClient->qcFlag()->createForSynchronous(runNumber, detectorName, qcFlags);
102+
}
103+
104+
std::vector<int> Bookkeeping::sendFlagsForDataPass(uint32_t runNumber, const std::string& passName, const std::string& detectorName, const std::vector<QcFlag>& qcFlags)
105+
{
106+
if (!mInitialized) {
107+
return {};
108+
}
109+
return mClient->qcFlag()->createForDataPass(runNumber, passName, detectorName, qcFlags);
110+
}
111+
112+
std::vector<int> Bookkeeping::sendFlagsForSimulationPass(uint32_t runNumber, const std::string& productionName, const std::string& detectorName, const std::vector<QcFlag>& qcFlags)
113+
{
114+
if (!mInitialized) {
115+
return {};
116+
}
117+
return mClient->qcFlag()->createForSimulationPass(runNumber, productionName, detectorName, qcFlags);
118+
}
119+
82120
} // namespace o2::quality_control::core

Framework/src/BookkeepingQualitySink.cxx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void BookkeepingQualitySink::customizeInfrastructure(std::vector<framework::Comp
4444

4545
void BookkeepingQualitySink::send(const std::string& grpcUri, const BookkeepingQualitySink::FlagsMap& flags, Provenance provenance)
4646
{
47-
auto bkpClient = o2::bkp::api::BkpClientFactory::create(grpcUri);
48-
auto& qcClient = bkpClient->qcFlag();
47+
auto& bkpClient = o2::quality_control::core::Bookkeeping::getInstance();
4948

5049
std::optional<int> runNumber;
5150
std::optional<std::string> passName;
@@ -98,20 +97,19 @@ void BookkeepingQualitySink::send(const std::string& grpcUri, const BookkeepingQ
9897
try {
9998
switch (provenance) {
10099
case Provenance::SyncQC:
101-
qcClient->createForSynchronous(runNumber.value(), detector, bkpQcFlags);
100+
bkpClient.sendFlagsForSynchronous(runNumber.value(), detector, bkpQcFlags);
102101
break;
103102
case Provenance::AsyncQC:
104-
qcClient->createForDataPass(runNumber.value(), passName.value(), detector, bkpQcFlags);
103+
bkpClient.sendFlagsForDataPass(runNumber.value(), passName.value(), detector, bkpQcFlags);
105104
break;
106105
case Provenance::MCQC:
107-
qcClient->createForSimulationPass(runNumber.value(), periodName.value(), detector, bkpQcFlags);
106+
bkpClient.sendFlagsForSimulationPass(runNumber.value(), periodName.value(), detector, bkpQcFlags);
108107
break;
109108
}
109+
ILOG(Info, Support) << "Sent " << bkpQcFlags.size() << " flags for detector '" << detector << "'" << ENDM;
110110
} catch (const std::runtime_error& err) {
111-
ILOG(Error, Support) << "Failed to send flags for detector: " << detector
112-
<< " with error: " << err.what() << ENDM;
111+
ILOG(Error, Support) << "Encountered errors while sending flags for detector '" << detector << "', details: " << err.what() << ENDM;
113112
}
114-
ILOG(Info, Support) << "Sent " << bkpQcFlags.size() << " flags for detector: " << detector << ENDM;
115113
}
116114
}
117115

@@ -130,6 +128,11 @@ auto collectionForQualityObject(const QualityObject& qualityObject) -> std::uniq
130128
qualityObject.getActivity().mProvenance);
131129
}
132130

131+
void BookkeepingQualitySink::init(framework::InitContext& context)
132+
{
133+
o2::quality_control::core::Bookkeeping::getInstance().init(mGrpcUri);
134+
}
135+
133136
void BookkeepingQualitySink::run(framework::ProcessingContext& context)
134137
{
135138
for (auto const& ref : framework::InputRecordWalker(context.inputs())) {

0 commit comments

Comments
 (0)