Skip to content

Commit d3007d1

Browse files
authored
[OMON-733] Create bucket on SOR (#335)
1 parent d883244 commit d3007d1

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ endif()
3131

3232
# Define project
3333
project(Monitoring
34-
VERSION 3.17.5
34+
VERSION 3.17.6
3535
DESCRIPTION "O2 Monitoring library"
3636
LANGUAGES CXX
3737
)

examples/12-KafkaToInfluxDb.cxx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818

1919
using namespace o2::monitoring;
2020

21+
22+
std::string getCreateBucketBody(const std::string& orgId, const int run) {
23+
std::stringstream postPayload;
24+
postPayload << R"({
25+
"orgID": ")" + orgId + R"(",
26+
"name": ")" + std::to_string(run) + R"(",
27+
"retentionRules": [{
28+
"type": "expire",
29+
"everySeconds": 86400,
30+
"shardGroupDurationSeconds": 86400
31+
}]
32+
})";
33+
return postPayload.str();
34+
}
35+
2136
int main(int argc, char* argv[])
2237
{
2338
boost::program_options::options_description desc("Program options");
@@ -26,7 +41,10 @@ int main(int argc, char* argv[])
2641
("influxdb-url", boost::program_options::value<std::string>()->required(), "InfluxDB hostname")
2742
("influxdb-token", boost::program_options::value<std::string>()->required(), "InfluxDB token")
2843
("influxdb-org", boost::program_options::value<std::string>()->default_value("cern"), "InfluxDB organisation")
29-
("influxdb-bucket", boost::program_options::value<std::string>()->default_value("aliecs"), "InfluxDB bucket");
44+
("influxdb-bucket", boost::program_options::value<std::string>()->default_value("aliecs"), "InfluxDB bucket")
45+
("influxdb-dpl-url", boost::program_options::value<std::string>(), "InfluxDB DPL ID")
46+
("influxdb-dpl-orgid", boost::program_options::value<std::string>(), "InfluxDB DPL organization ID")
47+
("influxdb-dpl-token", boost::program_options::value<std::string>(), "InfluxDB DPL token");
3048
boost::program_options::variables_map vm;
3149
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
3250
boost::program_options::notify(vm);
@@ -41,6 +59,14 @@ int main(int argc, char* argv[])
4159
);
4260
httpTransport->addHeader("Authorization: Token " + vm["influxdb-token"].as<std::string>());
4361
auto influxdbBackend = std::make_unique<backends::InfluxDB>(std::move(httpTransport));
62+
63+
std::unique_ptr<transports::HTTP> influxBucketApi;
64+
if (vm.count("influxdb-dpl-orgid") && vm.count("influxdb-dpl-url") && vm.count("influxdb-dpl-token")) {
65+
MonLogger::Get() << "Creating bucket HTTP API for " << vm["influxdb-dpl-url"].as<std::string>() << MonLogger::End();
66+
influxBucketApi.reset(new transports::HTTP(vm["influxdb-dpl-url"].as<std::string>() + "/api/v2/buckets"));
67+
influxBucketApi->addHeader("Authorization: Token " + vm["influxdb-dpl-token"].as<std::string>());
68+
}
69+
4470
for (;;) {
4571
auto changes = kafkaConsumer->pull();
4672
if (!changes.empty()) {
@@ -50,15 +76,19 @@ int main(int argc, char* argv[])
5076
if (stateChange.envinfo().state().empty()) {
5177
continue;
5278
}
79+
int run = stateChange.envinfo().runnumber();
5380
auto metric = Metric{"run_times"};
5481
if (change.first.find("leave") != std::string::npos) {
5582
metric.addValue(stateChange.timestamp(), "eor");
5683
MonLogger::Get() << stateChange.envinfo().environmentid() << "/" << stateChange.envinfo().runnumber() << " " << change.first << " EOR: " << stateChange.timestamp() << MonLogger::End();
5784
} else {
5885
metric.addValue(stateChange.envinfo().runtype(), "type").addValue(stateChange.envinfo().enterstatetimestamp(), "sor");
5986
MonLogger::Get() << stateChange.envinfo().environmentid() << "/" << stateChange.envinfo().runnumber() << " " << change.first << " SOR: " <<stateChange.envinfo().enterstatetimestamp() << MonLogger::End();
87+
if (vm.count("influxdb-dpl-orgid") && run > 1) {
88+
MonLogger::Get() << "Request sent to create bucket " << stateChange.envinfo().runnumber() << " on " << vm["influxdb-dpl-url"].as<std::string>() << MonLogger::End();
89+
influxBucketApi->send(getCreateBucketBody(vm["influxdb-dpl-orgid"].as<std::string>(), stateChange.envinfo().runnumber()));
90+
}
6091
}
61-
int run = stateChange.envinfo().runnumber();
6292
if (run > 1) {
6393
influxdbBackend->sendWithRun(metric, stateChange.envinfo().environmentid(), std::to_string(run));
6494
}

0 commit comments

Comments
 (0)