1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
// mod bytes_received;
// mod bytes_sent;
// pub mod cached_event;
// pub mod component_events_dropped;
// mod events_received;
// mod events_sent;
// mod optional_tag;
// mod prelude;
// pub mod service;
// use std::ops::{Add, AddAssign};
pub use *;
// pub use metrics::SharedString;
// pub use bytes_received::BytesReceived;
// pub use bytes_sent::BytesSent;
// #[allow(clippy::module_name_repetitions)]
// pub use cached_event::{RegisterTaggedInternalEvent, RegisteredEventCache};
// pub use component_events_dropped::{ComponentEventsDropped, INTENTIONAL, UNINTENTIONAL};
// pub use events_received::EventsReceived;
// pub use events_sent::{EventsSent, TaggedEventsSent, DEFAULT_OUTPUT};
// pub use optional_tag::OptionalTag;
// pub use prelude::{error_stage, error_type};
// pub use service::{CallError, PollReadyError};
// use crate::json_size::JsonSize;
/// Represents an internal event that can be emitted by the adaptive concurrency system.
///
/// This trait is used for instrumentation and monitoring of the AIMD algorithm's behavior.
/// Implementations should emit events that can be collected for metrics, logging, or tracing.
///
/// # Example
/// ```rust
/// use rate_limiter_aimd::adaptive_concurrency::internal_event::InternalEvent;
///
/// struct MyEvent;
///
/// impl InternalEvent for MyEvent {
/// fn emit(self) {
/// // Record the event in your metrics system
/// println!("Internal event occurred");
/// }
///
/// fn name(&self) -> Option<&'static str> {
/// Some("my_event")
/// }
/// }
/// ```
/// Trait for types that can register internal events.
///
/// This provides a way to register events while potentially maintaining
/// context or configuration needed for event emission.
// Sets the name of an event if it doesn't have one
// #[cfg(any(test, feature = "test"))]
// pub fn emit(event: impl InternalEvent) {
// if let Some(name) = event.name() {
// super::event_test_util::record_internal_event(name);
// }
// event.emit();
// }
// #[cfg(any(test, feature = "test"))]
// pub fn register<E: RegisterInternalEvent>(event: E) -> E::Handle {
// if let Some(name) = event.name() {
// super::event_test_util::record_internal_event(name);
// }
// event.register()
// }
// #[cfg(not(any(test, feature = "test")))]
pub type Registered<T> = Handle;
// Wrapper types used to hold data emitted by registered events
;
;
// /// Holds the tuple `(count_of_events, estimated_json_size_of_events)`.
// #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
// pub struct CountByteSize(pub usize, pub JsonSize);
// impl AddAssign for CountByteSize {
// fn add_assign(&mut self, rhs: Self) {
// self.0 += rhs.0;
// self.1 += rhs.1;
// }
// }
// impl Add<CountByteSize> for CountByteSize {
// type Output = CountByteSize;
// fn add(self, rhs: CountByteSize) -> Self::Output {
// CountByteSize(self.0 + rhs.0, self.1 + rhs.1)
// }
// }
// Wrapper types used to hold parameters for registering events
// pub struct Output(pub Option<SharedString>);
// pub struct Protocol(pub SharedString);
// impl Protocol {
// pub const HTTP: Protocol = Protocol(SharedString::const_str("http"));
// pub const HTTPS: Protocol = Protocol(SharedString::const_str("https"));
// pub const NONE: Protocol = Protocol(SharedString::const_str("none"));
// pub const TCP: Protocol = Protocol(SharedString::const_str("tcp"));
// pub const UDP: Protocol = Protocol(SharedString::const_str("udp"));
// pub const UNIX: Protocol = Protocol(SharedString::const_str("unix"));
// pub const INTERNAL: Protocol = Protocol(SharedString::const_str("internal"));
// pub const STATIC: Protocol = Protocol(SharedString::const_str("static"));
// }
// impl From<&'static str> for Protocol {
// fn from(s: &'static str) -> Self {
// Self(SharedString::const_str(s))
// }
// }
// impl From<Protocol> for SharedString {
// fn from(value: Protocol) -> Self {
// value.0
// }
// }
/// Macro to take care of some of the repetitive boilerplate in implementing a registered event. See
/// the other events in this module for examples of how to use this.
///
/// ## Usage
///
/// ```ignore
/// registered_event!(
/// Event {
/// event_field: &'static str,
/// } => {
/// handle_field: Counter = counter!("name", "tag" => self.event_field),
/// }
/// fn emit(&self, data: DataType) {
/// self.handle_field.increment(data.0);
/// }
/// );
///
/// let handle = register!(Event { event_field: "message" });
///
/// handle.emit(DataType(123));
/// ```
///
/// In this example, the first set of fields describes the data required to register the event. This
/// is what would be used by the `register!` macro. For example, `register!(Event { event_field:
/// "something" })`. The second set of fields describes the data required to store the registered
/// handle, namely the `Counter`s and `Gauge`s that record the handle from `metrics` as well as any
/// associated data for emitting traces or debug messages, followed by an initialization assignment
/// value. The `emit` function is the code required to update the metrics and generate any log
/// messages.
$?
}
};
}
// #[cfg(feature = "test")]
// #[macro_export]
// macro_rules! register {
// ($event:expr) => {
// vector_lib::internal_event::register(vector_lib::internal_event::DefaultName {
// event: $event,
// name: stringify!($event),
// })
// };
// }
// #[cfg(not(feature = "test"))]