Skip to content

Commit a9683c7

Browse files
committed
[ereporter] data loss as a first class citizen
1 parent a6dd46d commit a9683c7

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

ereporter/api/src/lib.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,41 @@ pub struct SeqPathParam {
4646
pub seq: Generation,
4747
}
4848

49-
/// An error report.
49+
/// An entry in the ereport batch returned by a reporter.
5050
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
51-
pub struct Ereport {
51+
pub struct Entry {
5252
/// UUID of the entity that generated this ereport.
5353
pub reporter_id: Uuid,
5454
/// The ereport's sequence number, unique with regards to ereports generated
5555
/// by the entity with the `reporter_id`.
5656
pub seq: Generation,
57+
58+
pub value: EntryKind,
59+
}
60+
61+
/// Kinds of entry in a batch.
62+
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
63+
pub enum EntryKind {
64+
/// An ereport.
65+
Ereport(Ereport),
66+
/// Ereports may have been lost.
67+
DataLoss {
68+
/// The number of ereports that were discarded, if it is known.
69+
///
70+
/// If ereports are dropped because a buffer has reached its capacity,
71+
/// the reporter is strongly encouraged to attempt to count the number
72+
/// of ereports lost. In other cases, such as a reporter crashing and
73+
/// restarting, the reporter may not be capable of determining the
74+
/// number of ereports that were lost, or even *if* data loss actually
75+
/// occurred. Therefore, a `None` here indicates *possible* data loss,
76+
/// while a `Some(u32)` indicates *known* data loss.
77+
dropped: Option<u32>,
78+
},
79+
}
80+
81+
/// An error report.
82+
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
83+
pub struct Ereport {
5784
/// A string indicating the kind of ereport.
5885
///
5986
/// This may be used by diagnosis engines as an indication of what `facts`

ereporter/src/buffer.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ pub(crate) enum ServerReq {
1717
List {
1818
start_seq: Option<Generation>,
1919
limit: usize,
20-
tx: oneshot::Sender<Vec<ereporter_api::Ereport>>,
20+
tx: oneshot::Sender<Vec<ereporter_api::Entry>>,
2121
},
2222
}
2323

2424
pub(crate) struct Buffer {
2525
pub(crate) seq: Generation,
26-
pub(crate) buf: VecDeque<ereporter_api::Ereport>,
26+
pub(crate) buf: VecDeque<ereporter_api::Entry>,
2727
pub(crate) log: slog::Logger,
2828
pub(crate) id: Uuid,
2929
pub(crate) ereports: mpsc::Receiver<EreportData>,
@@ -111,12 +111,14 @@ impl Buffer {
111111
fn push_ereport(&mut self, ereport: EreportData) {
112112
let EreportData { facts, class, time_created } = ereport;
113113
let seq = self.seq;
114-
self.buf.push_back(ereporter_api::Ereport {
115-
facts,
116-
class,
117-
time_created,
118-
reporter_id: self.id,
114+
self.buf.push_back(ereporter_api::Entry {
119115
seq,
116+
reporter_id: self.id,
117+
value: ereporter_api::EntryKind::Ereport(ereporter_api::Ereport {
118+
facts,
119+
class,
120+
time_created,
121+
}),
120122
});
121123
self.seq = self.seq.next();
122124
slog::trace!(

openapi/ereporter.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,6 @@
105105
"type": "string"
106106
}
107107
},
108-
"reporter_id": {
109-
"description": "UUID of the entity that generated this ereport.",
110-
"type": "string",
111-
"format": "uuid"
112-
},
113-
"seq": {
114-
"description": "The ereport's sequence number, unique with regards to ereports generated by the entity with the `reporter_id`.",
115-
"allOf": [
116-
{
117-
"$ref": "#/components/schemas/Generation"
118-
}
119-
]
120-
},
121108
"time_created": {
122109
"description": "The UTC timestamp when this ereport was observed, as determined by the reporter.",
123110
"type": "string",
@@ -127,8 +114,6 @@
127114
"required": [
128115
"class",
129116
"facts",
130-
"reporter_id",
131-
"seq",
132117
"time_created"
133118
]
134119
},

0 commit comments

Comments
 (0)