Skip to content

Commit

Permalink
Fix sampling policy related APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sophie-cluml committed Nov 7, 2024
1 parent 455758d commit d6d8f35
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- Modified `applyNode` GraphQL API logic to prevent notifying agents that are
operating with local configuration.

### Fixed

- Added missing `node` field in `samplingPolicy` and `samplingPolicyList`
GraphQL API responses in the `SamplingPolicy` object.

## [0.23.0] - 2024-10-23

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ num-traits = "0.2"
reqwest = { version = "0.12", default-features = false, features = [
"rustls-tls-native-roots",
] }
review-database = { git = "https://github.com/petabi/review-database.git", tag = "0.31.0" }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "aaab9e7" }
roxy = { git = "https://github.com/aicers/roxy.git", tag = "0.3.0" }
rustls = { version = "0.23", default-features = false, features = [
"ring",
Expand Down
35 changes: 32 additions & 3 deletions src/graphql/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ impl SamplingPolicy {
self.inner.dst_ip.as_ref().map(ToString::to_string)
}

async fn node(&self) -> Option<String> {
self.inner.node.as_ref().map(ToString::to_string)
}

async fn column(&self) -> Option<StringNumber<u32>> {
self.inner.column.map(StringNumber)
}
Expand Down Expand Up @@ -436,6 +440,9 @@ impl SamplingPolicyMutation {

#[cfg(test)]
mod tests {
use assert_json_diff::assert_json_eq;
use serde_json::json;

use crate::graphql::TestSchema;

#[tokio::test]
Expand All @@ -458,6 +465,7 @@ mod tests {
interval: FIFTEEN_MINUTES,
period: ONE_DAY,
offset: 0,
node: "collector",
immutable: false
)
}
Expand All @@ -478,6 +486,7 @@ mod tests {
interval: FIFTEEN_MINUTES,
period: ONE_DAY,
offset: 0,
node: "collector",
immutable: false
},
new:{
Expand All @@ -486,6 +495,7 @@ mod tests {
interval: FIFTEEN_MINUTES,
period: ONE_DAY,
offset: 0,
node: "manager",
immutable: true
}
)
Expand All @@ -502,15 +512,34 @@ mod tests {
samplingPolicyList(first: 10) {
nodes {
name
kind
interval
period
offset
node
immutable
}
}
}
"#,
)
.await;
assert_eq!(
res.data.to_string(),
r#"{samplingPolicyList: {nodes: [{name: "Policy 2"}]}}"#

assert_json_eq!(
res.data.into_json().unwrap(),
json!({
"samplingPolicyList": {
"nodes": [{
"name": "Policy 2",
"kind": "CONN",
"interval": "FIFTEEN_MINUTES",
"period": "ONE_DAY",
"offset": 0,
"node": "manager",
"immutable": true
}]
}
})
);

let res = schema
Expand Down

0 comments on commit d6d8f35

Please sign in to comment.