Skip to content

Commit

Permalink
feat(kubernetes_logs source): Use resource_version of 0 to use cache (#…
Browse files Browse the repository at this point in the history
…9974)

* feat(kubernetes_logs source): Use resource_version of 0 to use cache

Signed-off-by: Spencer Gilbert <spencer.gilbert@datadoghq.com>

* Update reflector unit tests, use to_owned over to_string

Signed-off-by: Spencer Gilbert <spencer.gilbert@datadoghq.com>

* make fmt

Signed-off-by: Spencer Gilbert <spencer.gilbert@datadoghq.com>
  • Loading branch information
spencergilbert authored Nov 11, 2021
1 parent 1b91d6b commit 6cfb28d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
25 changes: 15 additions & 10 deletions src/kubernetes/reflector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ mod tests {
drop(reflector);
}

// Test the properties of the normal execution flow.
// Test the properties of the normal execution flow.
#[tokio::test]
async fn flow_test() {
trace_init();

let invocations = vec![
(
vec![],
None,
Some("0".to_owned()),
ExpInvRes::Stream(vec![
ExpStmRes::Item(WatchEvent::Added(make_pod("uid0", "10"))),
ExpStmRes::Item(WatchEvent::Added(make_pod("uid1", "15"))),
Expand Down Expand Up @@ -419,7 +419,7 @@ mod tests {
let invocations = vec![
(
vec![],
None,
Some("0".to_owned()),
ExpInvRes::Stream(vec![
ExpStmRes::Item(WatchEvent::Added(make_pod("uid0", "10"))),
ExpStmRes::Item(WatchEvent::Added(make_pod("uid1", "15"))),
Expand Down Expand Up @@ -460,7 +460,7 @@ mod tests {
let invocations = vec![
(
vec![],
None,
Some("0".to_owned()),
ExpInvRes::Stream(vec![
ExpStmRes::Item(WatchEvent::Added(make_pod("uid0", "10"))),
ExpStmRes::Item(WatchEvent::Added(make_pod("uid1", "15"))),
Expand Down Expand Up @@ -499,7 +499,7 @@ mod tests {
let invocations = vec![
(
vec![],
None,
Some("0".to_owned()),
ExpInvRes::Stream(vec![
ExpStmRes::Item(WatchEvent::Added(make_pod("uid0", "10"))),
ExpStmRes::Item(WatchEvent::Added(make_pod("uid1", "15"))),
Expand Down Expand Up @@ -543,7 +543,7 @@ mod tests {
let invocations = vec![
(
vec![],
None,
Some("0".to_owned()),
ExpInvRes::Stream(vec![
ExpStmRes::Item(WatchEvent::Added(make_pod("uid0", "10"))),
ExpStmRes::Item(WatchEvent::Added(make_pod("uid1", "15"))),
Expand Down Expand Up @@ -584,7 +584,7 @@ mod tests {
let invocations = vec![
(
vec![],
None,
Some("0".to_owned()),
ExpInvRes::Stream(vec![
ExpStmRes::Item(WatchEvent::Added(make_pod("uid0", "10"))),
ExpStmRes::Item(WatchEvent::Added(make_pod("uid1", "15"))),
Expand Down Expand Up @@ -681,7 +681,7 @@ mod tests {
field_selector: Some("fields".to_owned()),
label_selector: Some("labels".to_owned()),
pretty: None,
resource_version: None,
resource_version: Some("0".to_owned()),
timeout_seconds: Some(290),
}
);
Expand Down Expand Up @@ -1083,8 +1083,13 @@ mod tests {

// Prepare reflector.
let pause_between_requests = Duration::from_secs(60 * 60); // 1 hour
let mut reflector =
Reflector::new(watcher, state_writer, None, None, pause_between_requests);
let mut reflector = Reflector::new(
watcher,
state_writer,
None,
Some("0".to_owned()),
pause_between_requests,
);

// Run test logic.
let logic = tokio::spawn(async move {
Expand Down
4 changes: 2 additions & 2 deletions src/kubernetes/resource_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub struct State(Option<String>);

impl State {
/// Create a new resource version [`State`].
pub const fn new() -> Self {
Self(None)
pub fn new() -> Self {
Self(Some("0".to_owned()))
}

/// Update the resource version from a candidate obtained earlier.
Expand Down

0 comments on commit 6cfb28d

Please sign in to comment.