Skip to content

Commit 4a64f85

Browse files
committed
Create a dedicated output namespace
1 parent fcac496 commit 4a64f85

14 files changed

+59
-53
lines changed

collector/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
file(GLOB COLLECTOR_LIB_SRC_FILES
22
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
33
${CMAKE_CURRENT_SOURCE_DIR}/system-inspector/*.cpp
4+
${CMAKE_CURRENT_SOURCE_DIR}/output/*.cpp
45
)
56

67
add_library(collector_lib ${DRIVER_HEADERS} ${COLLECTOR_LIB_SRC_FILES})

collector/lib/CollectorConfig.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ class CollectorConfig {
193193
}
194194

195195
protected:
196-
FRIEND_TEST(SensorClientFormatterTest, NoProcessArguments);
197-
198196
int scrape_interval_;
199197
CollectionMethod collection_method_;
200198
bool turn_off_scrape_;

collector/lib/CollectorService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
#include "CivetWrapper.h"
77
#include "CollectorConfig.h"
8-
#include "CollectorOutput.h"
98
#include "CollectorStatsExporter.h"
109
#include "ConfigLoader.h"
1110
#include "Control.h"
1211
#include "NetworkStatusInspector.h"
1312
#include "NetworkStatusNotifier.h"
13+
#include "output/Output.h"
1414
#include "system-inspector/Service.h"
1515

1616
namespace collector {
@@ -33,7 +33,7 @@ class CollectorService {
3333
bool WaitForGRPCServer();
3434

3535
CollectorConfig& config_;
36-
CollectorOutput output_;
36+
output::Output output_;
3737
system_inspector::Service system_inspector_;
3838

3939
std::atomic<ControlValue>* control_;

collector/lib/ProcessSignalHandler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "CollectorConfig.h"
66
#include "ProcessSignalFormatter.h"
77
#include "RateLimit.h"
8-
#include "SensorClientFormatter.h"
98
#include "SignalHandler.h"
9+
#include "output/SensorClientFormatter.h"
1010
#include "system-inspector/Service.h"
1111

1212
// forward declarations
@@ -20,7 +20,7 @@ class ProcessSignalHandler : public SignalHandler {
2020
public:
2121
ProcessSignalHandler(
2222
sinsp* inspector,
23-
CollectorOutput* client,
23+
output::Output* client,
2424
system_inspector::Stats* stats,
2525
const CollectorConfig& config)
2626
: client_(client),
@@ -48,9 +48,9 @@ class ProcessSignalHandler : public SignalHandler {
4848
Result HandleSensorSignal(sinsp_evt* evt);
4949
Result HandleExistingProcessSensor(sinsp_threadinfo* tinfo);
5050

51-
CollectorOutput* client_;
51+
output::Output* client_;
5252
ProcessSignalFormatter signal_formatter_;
53-
SensorClientFormatter sensor_formatter_;
53+
output::SensorClientFormatter sensor_formatter_;
5454
system_inspector::Stats* stats_;
5555
RateLimitCache rate_limiter_;
5656
};

collector/lib/CollectorOutput.cpp renamed to collector/lib/output/Output.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#include "CollectorOutput.h"
1+
#include "Output.h"
22

33
#include "GRPCUtil.h"
44
#include "HostInfo.h"
55

6-
namespace collector {
6+
namespace collector::output {
77

8-
CollectorOutput::CollectorOutput(const CollectorConfig& config)
8+
Output::Output(const CollectorConfig& config)
99
: use_sensor_client_(!config.UseLegacyServices()) {
1010
if (config.grpc_channel != nullptr) {
1111
channel_ = config.grpc_channel;
@@ -32,13 +32,13 @@ CollectorOutput::CollectorOutput(const CollectorConfig& config)
3232
thread_.Start([this] { EstablishGrpcStream(); });
3333
}
3434

35-
void CollectorOutput::HandleOutputError() {
35+
void Output::HandleOutputError() {
3636
CLOG(ERROR) << "GRPC stream interrupted";
3737
stream_active_.store(false, std::memory_order_release);
3838
stream_interrupted_.notify_one();
3939
}
4040

41-
SignalHandler::Result CollectorOutput::SensorOutput(const sensor::ProcessSignal& msg) {
41+
SignalHandler::Result Output::SensorOutput(const sensor::ProcessSignal& msg) {
4242
for (auto& client : sensor_clients_) {
4343
auto res = client->SendMsg(msg);
4444
switch (res) {
@@ -58,7 +58,7 @@ SignalHandler::Result CollectorOutput::SensorOutput(const sensor::ProcessSignal&
5858
return SignalHandler::PROCESSED;
5959
}
6060

61-
SignalHandler::Result CollectorOutput::SignalOutput(const sensor::SignalStreamMessage& msg) {
61+
SignalHandler::Result Output::SignalOutput(const sensor::SignalStreamMessage& msg) {
6262
for (auto& client : signal_clients_) {
6363
auto res = client->PushSignals(msg);
6464
switch (res) {
@@ -78,7 +78,7 @@ SignalHandler::Result CollectorOutput::SignalOutput(const sensor::SignalStreamMe
7878
return SignalHandler::PROCESSED;
7979
}
8080

81-
SignalHandler::Result CollectorOutput::SendMsg(const MessageType& msg) {
81+
SignalHandler::Result Output::SendMsg(const MessageType& msg) {
8282
auto visitor = [this](auto&& m) {
8383
using T = std::decay_t<decltype(m)>;
8484
if constexpr (std::is_same_v<T, sensor::ProcessSignal>) {
@@ -94,13 +94,13 @@ SignalHandler::Result CollectorOutput::SendMsg(const MessageType& msg) {
9494
return std::visit(visitor, msg);
9595
}
9696

97-
void CollectorOutput::EstablishGrpcStream() {
97+
void Output::EstablishGrpcStream() {
9898
while (EstablishGrpcStreamSingle()) {
9999
}
100100
CLOG(INFO) << "Service client terminating.";
101101
}
102102

103-
bool CollectorOutput::EstablishGrpcStreamSingle() {
103+
bool Output::EstablishGrpcStreamSingle() {
104104
std::mutex mtx;
105105
std::unique_lock<std::mutex> lock(mtx);
106106
stream_interrupted_.wait(lock, [this]() { return !stream_active_.load(std::memory_order_acquire) || thread_.should_stop(); });
@@ -135,4 +135,4 @@ bool CollectorOutput::EstablishGrpcStreamSingle() {
135135
}
136136
return true;
137137
}
138-
} // namespace collector
138+
} // namespace collector::output

collector/lib/CollectorOutput.h renamed to collector/lib/output/Output.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@
1010
#include "SignalServiceClient.h"
1111
#include "StoppableThread.h"
1212

13-
namespace collector {
13+
namespace collector::output {
1414

1515
using MessageType = std::variant<sensor::ProcessSignal, sensor::SignalStreamMessage>;
1616

17-
class CollectorOutput {
17+
class Output {
1818
public:
19-
CollectorOutput(const CollectorOutput&) = delete;
20-
CollectorOutput(CollectorOutput&&) = delete;
21-
CollectorOutput& operator=(const CollectorOutput&) = delete;
22-
CollectorOutput& operator=(CollectorOutput&&) = delete;
19+
Output(const Output&) = delete;
20+
Output(Output&&) = delete;
21+
Output& operator=(const Output&) = delete;
22+
Output& operator=(Output&&) = delete;
2323

24-
CollectorOutput(const CollectorConfig& config);
24+
Output(const CollectorConfig& config);
2525

26-
~CollectorOutput() {
26+
~Output() {
2727
stream_interrupted_.notify_one();
2828
if (thread_.running()) {
2929
thread_.Stop();
3030
}
3131
}
3232

3333
// Constructor for tests
34-
CollectorOutput(std::unique_ptr<ISensorClient>&& sensor_client,
35-
std::unique_ptr<ISignalServiceClient>&& signal_client) {
34+
Output(std::unique_ptr<ISensorClient>&& sensor_client,
35+
std::unique_ptr<ISignalServiceClient>&& signal_client) {
3636
sensor_clients_.emplace_back(std::move(sensor_client));
3737
signal_clients_.emplace_back(std::move(signal_client));
3838
}
@@ -75,4 +75,4 @@ class CollectorOutput {
7575
std::shared_ptr<grpc::Channel> channel_;
7676
};
7777

78-
} // namespace collector
78+
} // namespace collector::output

collector/lib/SensorClient.cpp renamed to collector/lib/output/SensorClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "Logging.h"
44

5-
namespace collector {
5+
namespace collector::output {
66
bool SensorClient::Recreate() {
77
context_ = std::make_unique<grpc::ClientContext>();
88
writer_ = DuplexClient::CreateWithReadsIgnored(&sensor::CollectorService::Stub::AsyncPushProcesses, channel_, context_.get());
@@ -44,4 +44,4 @@ SignalHandler::Result SensorClient::SendMsg(const sensor::ProcessSignal& msg) {
4444

4545
return SignalHandler::PROCESSED;
4646
}
47-
} // namespace collector
47+
} // namespace collector::output

collector/lib/SensorClient.h renamed to collector/lib/output/SensorClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "DuplexGRPC.h"
1010
#include "SignalHandler.h"
1111

12-
namespace collector {
12+
namespace collector::output {
1313

1414
class ISensorClient {
1515
public:
@@ -82,4 +82,4 @@ class SensorClientStdout : public ISensorClient {
8282
}
8383
};
8484

85-
} // namespace collector
85+
} // namespace collector::output

collector/lib/SensorClientFormatter.cpp renamed to collector/lib/output/SensorClientFormatter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "Utility.h"
1414
#include "system-inspector/EventExtractor.h"
1515

16-
namespace collector {
16+
namespace collector::output {
1717

1818
using SignalStreamMessage = sensor::SignalStreamMessage;
1919
using Signal = SensorClientFormatter::Signal;
@@ -331,4 +331,4 @@ std::vector<LineageInfo> SensorClientFormatter::GetProcessLineage(sinsp_threadin
331331
return lineage;
332332
}
333333

334-
} // namespace collector
334+
} // namespace collector::output

collector/lib/SensorClientFormatter.h renamed to collector/lib/output/SensorClientFormatter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace collector::system_inspector {
1919
class EventExtractor;
2020
}
2121

22-
namespace collector {
22+
namespace collector::output {
2323

2424
class SensorClientFormatter : public ProtoSignalFormatter<sensor::ProcessSignal> {
2525
public:
@@ -108,4 +108,4 @@ class SensorClientFormatter : public ProtoSignalFormatter<sensor::ProcessSignal>
108108
const CollectorConfig& config_;
109109
};
110110

111-
} // namespace collector
111+
} // namespace collector::output

0 commit comments

Comments
 (0)