-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: clean up eventd and service check types #130
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
//! Event types | ||
mod priority; | ||
pub use self::priority::*; | ||
//! Events. | ||
|
||
mod alert; | ||
pub use self::alert::*; | ||
// TODO: Switch usages of `String` to `MetaString` since we should generally be able to intern these strings as they | ||
// originate in in the DogStatsD codec, where interning is already taking place. | ||
|
||
/// Alert type. | ||
#[derive(Clone, Copy, Debug)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this was previously only Generally, integral types (signed and unsigned integers, floats, booleans) and "unit" enums (the variants don't have any fields) can stand to be This is to say that if you compare the size of this enum to a reference to this enum, the reference to it is much larger: 8 bytes versus 1 byte. References are at least a machine word (so 8 bytes on 64-bit architectures) while the compiler ends up bitpacking this enum in a single byte. The same thing holds if we use an integer type like |
||
pub enum AlertType { | ||
/// Indicates an informational event. | ||
Info, | ||
|
||
/// Indicates an error event. | ||
Error, | ||
|
||
/// Indicates a warning event. | ||
Warning, | ||
|
||
/// Indicates a successful event. | ||
Success, | ||
} | ||
|
||
/// Event priority. | ||
#[derive(Clone, Copy, Debug)] | ||
pub enum Priority { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For both |
||
/// The event has normal priority. | ||
Normal, | ||
|
||
/// The event has low priority. | ||
Low, | ||
} | ||
|
||
/// EventD is an object that can be posted to the DataDog event stream. | ||
#[derive(Clone, Debug)] | ||
|
@@ -13,55 +37,57 @@ pub struct EventD { | |
timestamp: u64, | ||
host: String, | ||
aggregation_key: String, | ||
priority: EventPriority, | ||
priority: Priority, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've renamed |
||
source_type_name: String, | ||
alert_type: EventAlertType, | ||
alert_type: AlertType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, we've renamed |
||
tags: Vec<String>, | ||
} | ||
|
||
impl EventD { | ||
/// Gets a reference to the title. | ||
/// Gets the title of the event. | ||
pub fn title(&self) -> &str { | ||
&self.title | ||
} | ||
|
||
/// Gets a reference to the text. | ||
/// Gets the text of the event. | ||
pub fn text(&self) -> &str { | ||
&self.text | ||
} | ||
|
||
/// Gets a reference to the host. | ||
/// Gets the host where the event originated from. | ||
pub fn host(&self) -> &str { | ||
&self.host | ||
} | ||
|
||
/// Gets a reference to the aggregation key. | ||
/// Gets the aggregation key of the event. | ||
pub fn aggregation_key(&self) -> &str { | ||
&self.aggregation_key | ||
} | ||
|
||
/// Gets a reference to the priority. | ||
pub fn priority(&self) -> &EventPriority { | ||
&self.priority | ||
/// Gets the priority of the event. | ||
pub fn priority(&self) -> Priority { | ||
self.priority | ||
} | ||
|
||
/// Gets a reference to the source type name. | ||
/// Gets the source type name of the event. | ||
pub fn source_type_name(&self) -> &str { | ||
&self.source_type_name | ||
} | ||
|
||
/// Gets a reference to the alert type | ||
pub fn alert_type(&self) -> &EventAlertType { | ||
&self.alert_type | ||
/// Gets the alert type of the event. | ||
pub fn alert_type(&self) -> AlertType { | ||
self.alert_type | ||
} | ||
|
||
/// Gets a reference to the timestamp. | ||
pub fn timestamp(&self) -> &u64 { | ||
&self.timestamp | ||
/// Gets the timestamp of the event. | ||
/// | ||
/// This is a Unix timestamp, or the number of seconds since the Unix epoch. | ||
pub fn timestamp(&self) -> u64 { | ||
self.timestamp | ||
} | ||
|
||
/// Gets a reference to the tags. | ||
pub fn tags(&self) -> &Vec<String> { | ||
/// Gets the tags associated with the event. | ||
pub fn tags(&self) -> &[String] { | ||
&self.tags | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,68 @@ | ||
//! Service Check type | ||
mod status; | ||
pub use self::status::*; | ||
//! Service checks. | ||
|
||
/// ServiceCheck | ||
// TODO: Switch usages of `String` to `MetaString` since we should generally be able to intern these strings as they | ||
// originate in in the DogStatsD codec, where interning is already taking place. | ||
|
||
/// Service status. | ||
#[derive(Clone, Copy, Debug)] | ||
pub enum CheckStatus { | ||
/// The service is operating normally. | ||
Ok, | ||
|
||
/// The service is in a warning state. | ||
Warn, | ||
|
||
/// The service is in a critical state. | ||
Critical, | ||
|
||
/// The service is in an unknown state. | ||
Unknown, | ||
} | ||
|
||
/// A service check. | ||
/// | ||
/// Service checks represent the status of a service at a particular point in time. Checks are simplistic, with a basic | ||
/// message, status enum (OK vs warning vs critical, etc), timestamp, and tags. | ||
#[derive(Clone, Debug)] | ||
pub struct ServiceCheck { | ||
name: String, | ||
status: ServiceCheckStatus, | ||
status: CheckStatus, | ||
timestamp: u64, | ||
host: String, | ||
message: String, | ||
tags: Vec<String>, | ||
} | ||
|
||
impl ServiceCheck { | ||
/// Gets a reference to the service check name | ||
pub fn name(&self) -> &String { | ||
/// Gets the name of the check. | ||
pub fn name(&self) -> &str { | ||
&self.name | ||
} | ||
|
||
/// Gets a reference to the status | ||
pub fn status(&self) -> &ServiceCheckStatus { | ||
&self.status | ||
/// Gets the status of the check. | ||
pub fn status(&self) -> CheckStatus { | ||
self.status | ||
} | ||
|
||
/// Gets a reference to the timestamp | ||
/// Gets the timestamp of the check. | ||
/// | ||
/// This is a Unix timestamp, or the number of seconds since the Unix epoch. | ||
pub fn timestamp(&self) -> u64 { | ||
self.timestamp | ||
} | ||
|
||
/// Gets a reference to the host name | ||
pub fn host(&self) -> &String { | ||
/// Gets the host where the check originated from. | ||
pub fn host(&self) -> &str { | ||
&self.host | ||
} | ||
|
||
/// Gets a reference to the message | ||
pub fn message(&self) -> &String { | ||
/// Gets the message associated with the check. | ||
pub fn message(&self) -> &str { | ||
&self.message | ||
} | ||
|
||
/// Gets a reference to the tags | ||
pub fn tags(&self) -> &Vec<String> { | ||
/// Gets the tags associated with the check. | ||
pub fn tags(&self) -> &[String] { | ||
&self.tags | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we'll try to keep TODO comments close to the area where they're most relevant, but in this case, this is a thing we'd want to apply to multiple fields on the
EventD
struct, so we just shove it up here as a general TODO.