@@ -23,7 +23,7 @@ AsioEventProcessor::AsioEventProcessor(
23
23
Logger& logger)
24
24
: io_(boost::asio::make_strand(io)),
25
25
outbox_ (config.capacity()),
26
- summary_state_ (std::chrono::system_clock::now()),
26
+ summarizer_ (std::chrono::system_clock::now()),
27
27
flush_interval_(config.flush_interval()),
28
28
timer_(io_),
29
29
host_(endpoints.events_base_url()), // TODO: parse and use host
@@ -68,14 +68,14 @@ void AsioEventProcessor::AsyncSend(InputEvent input_event) {
68
68
if (!InboxIncrement ()) {
69
69
return ;
70
70
}
71
- boost::asio::post (io_, [this , e = std::move (input_event)]() mutable {
71
+ boost::asio::post (io_, [this , event = std::move (input_event)]() mutable {
72
72
InboxDecrement ();
73
- HandleSend (std::move (e ));
73
+ HandleSend (std::move (event ));
74
74
});
75
75
}
76
76
77
- void AsioEventProcessor::HandleSend (InputEvent e ) {
78
- std::vector<OutputEvent> output_events = Process (std::move (e ));
77
+ void AsioEventProcessor::HandleSend (InputEvent event ) {
78
+ std::vector<OutputEvent> output_events = Process (std::move (event ));
79
79
80
80
bool inserted = outbox_.PushDiscardingOverflow (std::move (output_events));
81
81
if (!inserted && !full_outbox_encountered_) {
@@ -93,7 +93,7 @@ void AsioEventProcessor::Flush(FlushTrigger flush_type) {
93
93
LD_LOG (logger_, LogLevel::kDebug )
94
94
<< " event-processor: nothing to flush" ;
95
95
}
96
- summary_state_ = Summarizer (std::chrono::system_clock::now ());
96
+ summarizer_ = Summarizer (std::chrono::system_clock::now ());
97
97
if (flush_type == FlushTrigger::Automatic) {
98
98
ScheduleFlush ();
99
99
}
@@ -132,14 +132,16 @@ AsioEventProcessor::MakeRequest() {
132
132
return std::nullopt;
133
133
}
134
134
135
- boost::json::value summary_event;
136
- if (!summary_state_.empty ()) {
137
- summary_event = boost::json::value_from (
138
- Summary{summary_state_, std::chrono::system_clock::now ()});
135
+ auto events = boost::json::value_from (outbox_.Consume ());
136
+
137
+ if (!summarizer_.Empty ()) {
138
+ events.as_array ().push_back (boost::json::value_from (
139
+ Summary{summarizer_, std::chrono::system_clock::now ()}));
139
140
}
140
141
141
142
LD_LOG (logger_, LogLevel::kDebug )
142
143
<< " event-processor: generating http request" ;
144
+
143
145
RequestType req;
144
146
145
147
req.set (http::field::host, host_);
@@ -150,11 +152,6 @@ AsioEventProcessor::MakeRequest() {
150
152
req.set (kPayloadIdHeader , boost::lexical_cast<std::string>(uuids_ ()));
151
153
req.target (host_ + path_);
152
154
153
- auto events = boost::json::value_from (outbox_.Consume ());
154
- if (!summary_event.is_null ()) {
155
- events.as_array ().push_back (summary_event);
156
- }
157
-
158
155
req.body () = boost::json::serialize (events);
159
156
req.prepare_payload ();
160
157
return req;
@@ -169,55 +166,57 @@ struct overloaded : Ts... {
169
166
template <class ... Ts>
170
167
overloaded (Ts...) -> overloaded<Ts...>;
171
168
172
- std::vector<OutputEvent> AsioEventProcessor::Process (InputEvent event ) {
169
+ std::vector<OutputEvent> AsioEventProcessor::Process (InputEvent input_event ) {
173
170
std::vector<OutputEvent> out;
174
171
std::visit (
175
- overloaded{
176
- [&](client::FeatureEventParams&& e) {
177
- summary_state_.update (e);
178
-
179
- if (!e.eval_result .track_events ()) {
180
- return ;
181
- }
182
- std::optional<Reason> reason;
183
-
184
- // TODO(cwaldren): should also add the reason if the variation
185
- // method was VariationDetail().
186
- if (e.eval_result .track_reason ()) {
187
- reason = e.eval_result .detail ().reason ();
188
- }
189
-
190
- client::FeatureEventBase b = {
191
- e.creation_date , std::move (e.key ), e.eval_result .version (),
192
- e.eval_result .detail ().variation_index (),
193
- e.eval_result .detail ().value (), reason,
194
- // TODO(cwaldren): change to actual default; figure out
195
- // where this should be plumbed through.
196
- Value::null ()};
197
-
198
- auto debug_until_date = e.eval_result .debug_events_until_date ();
199
- bool emit_debug_event =
200
- debug_until_date &&
201
- debug_until_date.value () > std::chrono::system_clock::now ();
202
-
203
- if (emit_debug_event) {
204
- out.emplace_back (
205
- client::DebugEvent{b, filter_.filter (e.context )});
206
- }
207
- // TODO(cwaldren): see about not copying the keys / having the
208
- // getter return a value.
209
- out.emplace_back (client::FeatureEvent{
210
- std::move (b), e.context .kinds_to_keys ()});
211
- },
212
- [&](client::IdentifyEventParams&& e) {
213
- // Contexts should already have been checked for
214
- // validity by this point.
215
- assert (e.context .valid ());
216
- out.emplace_back (client::IdentifyEvent{
217
- e.creation_date , filter_.filter (e.context )});
218
- },
219
- [&](TrackEventParams&& e) { out.emplace_back (std::move (e)); }},
220
- std::move (event));
172
+ overloaded{[&](client::FeatureEventParams&& event) {
173
+ summarizer_.Update (event);
174
+
175
+ if (!event.eval_result .track_events ()) {
176
+ return ;
177
+ }
178
+ std::optional<Reason> reason;
179
+
180
+ // TODO(cwaldren): should also add the reason if the
181
+ // variation method was VariationDetail().
182
+ if (event.eval_result .track_reason ()) {
183
+ reason = event.eval_result .detail ().reason ();
184
+ }
185
+
186
+ client::FeatureEventBase base = {
187
+ event.creation_date , std::move (event.key ),
188
+ event.eval_result .version (),
189
+ event.eval_result .detail ().variation_index (),
190
+ event.eval_result .detail ().value (), reason,
191
+ // TODO(cwaldren): change to actual default; figure
192
+ // out where this should be plumbed through.
193
+ Value::null ()};
194
+
195
+ auto debug_until_date =
196
+ event.eval_result .debug_events_until_date ();
197
+ bool emit_debug_event =
198
+ debug_until_date &&
199
+ debug_until_date.value () >
200
+ std::chrono::system_clock::now ();
201
+
202
+ if (emit_debug_event) {
203
+ out.emplace_back (client::DebugEvent{
204
+ base, filter_.filter (event.context )});
205
+ }
206
+ out.emplace_back (client::FeatureEvent{
207
+ std::move (base), event.context .kinds_to_keys ()});
208
+ },
209
+ [&](client::IdentifyEventParams&& event) {
210
+ // Contexts should already have been checked for
211
+ // validity by this point.
212
+ assert (event.context .valid ());
213
+ out.emplace_back (client::IdentifyEvent{
214
+ event.creation_date , filter_.filter (event.context )});
215
+ },
216
+ [&](TrackEventParams&& event) {
217
+ out.emplace_back (std::move (event));
218
+ }},
219
+ std::move (input_event));
221
220
222
221
return out;
223
222
}
0 commit comments