Skip to content

Commit 5fbf7cb

Browse files
authored
fix(s2n-events): Fix warning when no nominal counters are defined (#2811)
1 parent 1d4aa38 commit 5fbf7cb

File tree

6 files changed

+14
-49
lines changed

6 files changed

+14
-49
lines changed

dc/s2n-quic-dc/src/event/generated/metrics/aggregate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,7 @@ impl<R: Registry> Subscriber<R> {
22402240
pub fn nominal_counters(
22412241
&self,
22422242
) -> impl Iterator<Item = (&'static Info, &[R::NominalCounter], &[info::Variant])> + '_ {
2243+
#[allow(unused_imports)]
22432244
use api::*;
22442245
self.nominal_counter_offsets
22452246
.iter()

quic/s2n-quic-core/src/event/generated/metrics/aggregate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,7 @@ impl<R: Registry> Subscriber<R> {
16801680
pub fn nominal_counters(
16811681
&self,
16821682
) -> impl Iterator<Item = (&'static Info, &[R::NominalCounter], &[info::Variant])> + '_ {
1683+
#[allow(unused_imports)]
16831684
use api::*;
16841685
self.nominal_counter_offsets
16851686
.iter()

tools/s2n-events/src/output/metrics/aggregate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ pub fn emit(output: &Output, files: &[File]) -> TokenStream {
470470
/// Returns all of the registered nominal counters
471471
#[inline]
472472
pub fn nominal_counters(&self) -> impl Iterator<Item = (&'static Info, &[R::NominalCounter], &[info::Variant])> + '_ {
473+
#[allow(unused_imports)]
473474
use api::*;
474475
#nominal_counters
475476
}

tools/s2n-events/tests/c_ffi_events/event/generated/metrics/aggregate.rs

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::event::{
1212
AsVariant, BoolRecorder, Info, Metric, NominalRecorder, Recorder, Registry, Units,
1313
},
1414
};
15-
static INFO: &[Info; 4usize] = &[
15+
static INFO: &[Info; 3usize] = &[
1616
info::Builder {
1717
id: 0usize,
1818
name: Str::new("byte_array_event\0"),
@@ -27,12 +27,6 @@ static INFO: &[Info; 4usize] = &[
2727
.build(),
2828
info::Builder {
2929
id: 2usize,
30-
name: Str::new("enum_event.value\0"),
31-
units: Units::None,
32-
}
33-
.build(),
34-
info::Builder {
35-
id: 3usize,
3630
name: Str::new("count_event\0"),
3731
units: Units::None,
3832
}
@@ -51,7 +45,7 @@ pub struct Subscriber<R: Registry> {
5145
#[allow(dead_code)]
5246
nominal_counters: Box<[R::NominalCounter]>,
5347
#[allow(dead_code)]
54-
nominal_counter_offsets: Box<[usize; 1usize]>,
48+
nominal_counter_offsets: Box<[usize; 0usize]>,
5549
#[allow(dead_code)]
5650
measures: Box<[R::Measure; 0usize]>,
5751
#[allow(dead_code)]
@@ -82,30 +76,19 @@ impl<R: Registry> Subscriber<R> {
8276
pub fn new(registry: R) -> Self {
8377
let mut counters = Vec::with_capacity(3usize);
8478
let mut bool_counters = Vec::with_capacity(0usize);
85-
let mut nominal_counters = Vec::with_capacity(1usize);
86-
let mut nominal_counter_offsets = Vec::with_capacity(1usize);
79+
let mut nominal_counters = Vec::with_capacity(0usize);
80+
let mut nominal_counter_offsets = Vec::with_capacity(0usize);
8781
let mut measures = Vec::with_capacity(0usize);
8882
let mut gauges = Vec::with_capacity(0usize);
8983
let mut timers = Vec::with_capacity(0usize);
9084
let mut nominal_timers = Vec::with_capacity(0usize);
9185
let mut nominal_timer_offsets = Vec::with_capacity(0usize);
9286
counters.push(registry.register_counter(&INFO[0usize]));
9387
counters.push(registry.register_counter(&INFO[1usize]));
94-
counters.push(registry.register_counter(&INFO[3usize]));
88+
counters.push(registry.register_counter(&INFO[2usize]));
9589
{
9690
#[allow(unused_imports)]
9791
use api::*;
98-
{
99-
let offset = nominal_counters.len();
100-
let mut count = 0;
101-
for variant in <TestEnum as AsVariant>::VARIANTS.iter() {
102-
nominal_counters
103-
.push(registry.register_nominal_counter(&INFO[2usize], variant));
104-
count += 1;
105-
}
106-
debug_assert_ne!(count, 0, "field type needs at least one variant");
107-
nominal_counter_offsets.push(offset);
108-
}
10992
}
11093
{
11194
#[allow(unused_imports)]
@@ -143,7 +126,7 @@ impl<R: Registry> Subscriber<R> {
143126
.map(|(idx, entry)| match idx {
144127
0usize => (&INFO[0usize], entry),
145128
1usize => (&INFO[1usize], entry),
146-
2usize => (&INFO[3usize], entry),
129+
2usize => (&INFO[2usize], entry),
147130
_ => unsafe { core::hint::unreachable_unchecked() },
148131
})
149132
}
@@ -171,19 +154,9 @@ impl<R: Registry> Subscriber<R> {
171154
pub fn nominal_counters(
172155
&self,
173156
) -> impl Iterator<Item = (&'static Info, &[R::NominalCounter], &[info::Variant])> + '_ {
157+
#[allow(unused_imports)]
174158
use api::*;
175-
self.nominal_counter_offsets
176-
.iter()
177-
.enumerate()
178-
.map(|(idx, entry)| match idx {
179-
0usize => {
180-
let offset = *entry;
181-
let variants = <TestEnum as AsVariant>::VARIANTS;
182-
let entries = &self.nominal_counters[offset..offset + variants.len()];
183-
(&INFO[2usize], entries, variants)
184-
}
185-
_ => unsafe { core::hint::unreachable_unchecked() },
186-
})
159+
core::iter::empty()
187160
}
188161
#[allow(dead_code)]
189162
#[inline(always)]
@@ -279,7 +252,6 @@ impl<R: Registry> event::Subscriber for Subscriber<R> {
279252
#[allow(unused_imports)]
280253
use api::*;
281254
self.count(1usize, 1usize, 1usize);
282-
self.count_nominal(2usize, 0usize, &event.value);
283255
let _ = context;
284256
let _ = meta;
285257
let _ = event;
@@ -288,7 +260,7 @@ impl<R: Registry> event::Subscriber for Subscriber<R> {
288260
fn on_count_event(&mut self, meta: &api::EndpointMeta, event: &api::CountEvent) {
289261
#[allow(unused_imports)]
290262
use api::*;
291-
self.count(3usize, 2usize, 1usize);
263+
self.count(2usize, 2usize, 1usize);
292264
let _ = event;
293265
let _ = meta;
294266
}

tools/s2n-events/tests/c_ffi_events/event/generated/metrics/probe.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod counter {
1919
match info.id {
2020
0usize => Self(byte_array_event),
2121
1usize => Self(enum_event),
22-
3usize => Self(count_event),
22+
2usize => Self(count_event),
2323
_ => unreachable!("invalid info: {info:?}"),
2424
}
2525
}
@@ -61,10 +61,7 @@ mod counter {
6161
pub struct Recorder(fn(u64, u64, &info::Str));
6262
impl Recorder {
6363
pub(crate) fn new(info: &'static Info, _variant: &'static info::Variant) -> Self {
64-
match info.id {
65-
2usize => Self(enum_event__value),
66-
_ => unreachable!("invalid info: {info:?}"),
67-
}
64+
unreachable!("invalid info: {info:?}")
6865
}
6966
}
7067
impl NominalRecorder for Recorder {
@@ -77,12 +74,6 @@ mod counter {
7774
(self.0)(value.as_u64(), variant.id as _, variant.name);
7875
}
7976
}
80-
define!(
81-
extern "probe" {
82-
# [link_name = c_ffi_events__event__counter__nominal__enum_event__value]
83-
fn enum_event__value(value: u64, variant: u64, variant_name: &info::Str);
84-
}
85-
);
8677
}
8778
}
8879
mod measure {

tools/s2n-events/tests/c_ffi_events/events/connection.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ enum TestEnum {
1313

1414
#[event("enum_event")]
1515
struct EnumEvent {
16-
#[nominal_counter("value")]
1716
value: TestEnum,
1817
}

0 commit comments

Comments
 (0)