-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f979e1f
commit 55d83d4
Showing
10 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tools] | ||
rust = "1.74" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM rust:1.72.0 | ||
FROM rust:1.74.0 | ||
|
||
WORKDIR /code | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// Send a custom event as a title and a body | ||
/// NOTE: Try to minimise variation in tag values (avoid things like timestamps or ids). See note in lib docs! | ||
#[macro_export] | ||
macro_rules! event_with_options { | ||
($stat:path, $text:expr) => { | ||
$crate::Datadog::event_with_options($stat.as_ref(), $text, $crate::EMPTY_TAGS, None); | ||
}; | ||
($stat:expr, $text:expr) => { | ||
$crate::Datadog::event_with_options($stat, $text, $crate::EMPTY_TAGS, None); | ||
}; | ||
($stat:expr, $text:expr; $( $key:literal => $value:literal ), *) => { | ||
$crate::Datadog::event_with_options($stat, $text, &[$(::core::concat!($key, ":", $value)), *], None); | ||
}; | ||
($stat:path, $text:expr; $( $key:literal => $value:literal ), *) => { | ||
$crate::Datadog::event_with_options($stat.as_ref(), $text, &[$(::core::concat!($key, ":", $value)), *], None); | ||
}; | ||
($stat:expr, $text:expr; $( $key:expr => $value:expr ), *) => { | ||
$crate::Datadog::event_with_options($stat, $text, &[$(::std::format!("{}:{}", $key, $value).as_str()), *], None); | ||
}; | ||
($stat:path, $text:expr; $( $key:expr => $value:expr ), *) => { | ||
$crate::Datadog::event_with_options($stat.as_ref(), $text, &[$(::std::format!("{}:{}", $key, $value).as_str()), *], None); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use dogstatsd::EventAlertType; | ||
use dogstatsd::EventOptions; | ||
use dogstatsd::EventPriority; | ||
|
||
use crate::event_with_options; | ||
use crate::tests::mocks; | ||
use crate::tests::TestEvent; | ||
use crate::Datadog; | ||
use crate::TagTrackerConfiguration; | ||
use crate::EMPTY_TAGS; | ||
|
||
#[test] | ||
pub fn event_with_options_with_literal() { | ||
let mock = mocks::event_with_options_mock("test", "test_value", &[], None); | ||
Datadog::new(mock, TagTrackerConfiguration::new()).do_event_with_options("test", "test_value", EMPTY_TAGS, None); | ||
} | ||
|
||
#[test] | ||
pub fn event_with_options_with_type() { | ||
let mock = mocks::event_with_options_mock("test1_event", "test_value", &[], None); | ||
Datadog::new(mock, TagTrackerConfiguration::new()).do_event_with_options( | ||
TestEvent::Test1, | ||
"test_value", | ||
EMPTY_TAGS, | ||
None, | ||
); | ||
} | ||
|
||
#[test] | ||
pub fn event_with_options_with_literal_and_tags() { | ||
let mock = mocks::event_with_options_mock("test", "test_value", &["added:tag", "env:test"], None); | ||
Datadog::new(mock, TagTrackerConfiguration::new()).do_event_with_options( | ||
"test", | ||
"test_value", | ||
vec!["added:tag".to_string()], | ||
None, | ||
); | ||
} | ||
|
||
#[test] | ||
pub fn event_with_options_with_type_and_tags() { | ||
let mock = mocks::event_with_options_mock("test1_event", "test_value", &["added:tag", "env:test"], None); | ||
Datadog::new(mock, TagTrackerConfiguration::new()).do_event_with_options( | ||
TestEvent::Test1, | ||
"test_value", | ||
vec!["added:tag".to_string()], | ||
None, | ||
); | ||
} | ||
|
||
#[test] | ||
pub fn event_with_options_with_options() { | ||
let options = Some( | ||
EventOptions::new() | ||
.with_alert_type(EventAlertType::Info) | ||
.with_priority(EventPriority::Low) | ||
.with_aggregation_key("aggregation_key") | ||
.with_source_type_name("source_type_name") | ||
.with_hostname("hostname") | ||
.with_timestamp(12341234), | ||
); | ||
|
||
let mock = mocks::event_with_options_mock("test1_event", "test_value", &["added:tag", "env:test"], options); | ||
Datadog::new(mock, TagTrackerConfiguration::new()).do_event_with_options( | ||
TestEvent::Test1, | ||
"test_value", | ||
vec!["added:tag".to_string()], | ||
options, | ||
); | ||
} | ||
|
||
#[test] | ||
pub fn test_macro() { | ||
let tag = String::from("tag"); | ||
// no tags | ||
event_with_options!("test", "test_value"); | ||
// just literal tags | ||
event_with_options!("test", "test_value"; "literal" => 1); | ||
// just expression tags | ||
event_with_options!("test", "test_value"; "expression" => tag); | ||
// mixed tags | ||
event_with_options!("test", "test_value"; "literal" => 1, "expression" => tag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters