@@ -57,15 +57,12 @@ std::vector<IPNet> readNetworks(const std::string& networks, Address::Family fam
57
57
return ip_nets;
58
58
}
59
59
60
- void NetworkStatusNotifier::OnRecvControlMessage (const sensor::NetworkFlowsControlMessage* msg) {
61
- if (!msg) {
62
- return ;
63
- }
64
- if (msg->has_ip_networks ()) {
65
- ReceivePublicIPs (msg->public_ip_addresses ());
60
+ void NetworkStatusNotifier::OnRecvControlMessage (const sensor::NetworkFlowsControlMessage& msg) {
61
+ if (msg.has_ip_networks ()) {
62
+ ReceivePublicIPs (msg.public_ip_addresses ());
66
63
}
67
- if (msg-> has_ip_networks ()) {
68
- ReceiveIPNetworks (msg-> ip_networks ());
64
+ if (msg. has_ip_networks ()) {
65
+ ReceiveIPNetworks (msg. ip_networks ());
69
66
}
70
67
}
71
68
@@ -114,24 +111,10 @@ void NetworkStatusNotifier::Run() {
114
111
auto next_attempt = std::chrono::system_clock::now ();
115
112
116
113
while (thread_.PauseUntil (next_attempt)) {
117
- comm_->ResetClientContext ();
118
-
119
- if (!comm_->WaitForConnectionReady ([this ] { return thread_.should_stop (); })) {
120
- break ;
121
- }
122
-
123
- auto client_writer = comm_->PushNetworkConnectionInfoOpenStream ([this ](const sensor::NetworkFlowsControlMessage* msg) { OnRecvControlMessage (msg); });
124
-
125
- RunSingle (client_writer.get ());
114
+ RunSingle ();
126
115
if (thread_.should_stop ()) {
127
116
return ;
128
117
}
129
- auto status = client_writer->Finish (std::chrono::seconds (5 ));
130
- if (status.ok ()) {
131
- CLOG (ERROR) << " Error streaming network connection info: server hung up unexpectedly" ;
132
- } else {
133
- CLOG (ERROR) << " Error streaming network connection info: " << status.error_message ();
134
- }
135
118
next_attempt = std::chrono::system_clock::now () + std::chrono::seconds (10 );
136
119
}
137
120
@@ -140,12 +123,13 @@ void NetworkStatusNotifier::Run() {
140
123
141
124
void NetworkStatusNotifier::Start () {
142
125
thread_.Start ([this ] { Run (); });
126
+ receiver_.Start ();
143
127
CLOG (INFO) << " Started network status notifier." ;
144
128
}
145
129
146
130
void NetworkStatusNotifier::Stop () {
147
- comm_->TryCancel ();
148
131
thread_.Stop ();
132
+ receiver_.Stop ();
149
133
}
150
134
151
135
void NetworkStatusNotifier::WaitUntilWriterStarted (IDuplexClientWriter<sensor::NetworkConnectionInfoMessage>* writer, int wait_time_seconds) {
@@ -217,15 +201,13 @@ bool NetworkStatusNotifier::UpdateAllConnsAndEndpoints() {
217
201
return true ;
218
202
}
219
203
220
- void NetworkStatusNotifier::RunSingle (IDuplexClientWriter<sensor::NetworkConnectionInfoMessage>* writer) {
221
- WaitUntilWriterStarted (writer, 10 );
222
-
204
+ void NetworkStatusNotifier::RunSingle () {
223
205
ConnMap old_conn_state;
224
206
AdvertisedEndpointMap old_cep_state;
225
207
auto next_scrape = std::chrono::system_clock::now ();
226
208
int64_t time_at_last_scrape = NowMicros ();
227
209
228
- while (writer-> Sleep (next_scrape)) {
210
+ while (thread_. PauseUntil (next_scrape)) {
229
211
CLOG (DEBUG) << " Starting network status notification" ;
230
212
next_scrape = std::chrono::system_clock::now () + std::chrono::seconds (config_.ScrapeInterval ());
231
213
@@ -272,7 +254,7 @@ void NetworkStatusNotifier::RunSingle(IDuplexClientWriter<sensor::NetworkConnect
272
254
}
273
255
274
256
WITH_TIMER (CollectorStats::net_write_message) {
275
- if (!writer-> Write (*msg, next_scrape) ) {
257
+ if (output_-> SendMsg (*msg) != SignalHandler::PROCESSED ) {
276
258
CLOG (ERROR) << " Failed to write network connection info" ;
277
259
return ;
278
260
}
0 commit comments