-
Notifications
You must be signed in to change notification settings - Fork 59
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
graph-builder: add plugin to parse openshift/cincinnati-graph-data #231
Changes from all commits
f8ac699
592f1af
ac2cef9
1ca63e0
e661734
09fcff9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,10 @@ use crate::plugins::BoxedPlugin; | |
use crate::plugins::{InternalIO, InternalPlugin, InternalPluginWrapper, PluginSettings}; | ||
use crate::ReleaseId; | ||
use async_trait::async_trait; | ||
use failure::Fallible; | ||
use failure::{Fallible, ResultExt}; | ||
use prometheus::Registry; | ||
|
||
static DEFAULT_KEY_FILTER: &str = "io.openshift.upgrades.graph"; | ||
pub static DEFAULT_KEY_FILTER: &str = "io.openshift.upgrades.graph"; | ||
pub static DEFAULT_REMOVE_ALL_EDGES_VALUE: &str = "*"; | ||
|
||
#[derive(Clone, Debug, Deserialize, SmartDefault)] | ||
|
@@ -19,6 +19,10 @@ pub struct EdgeAddRemovePlugin { | |
|
||
#[default(DEFAULT_REMOVE_ALL_EDGES_VALUE.to_string())] | ||
pub remove_all_edges_value: String, | ||
|
||
/// If true causes the removal of all processed metadata from the releases. | ||
#[default(false)] | ||
pub remove_consumed_metadata: bool, | ||
} | ||
|
||
#[async_trait] | ||
|
@@ -53,7 +57,8 @@ impl PluginSettings for EdgeAddRemovePlugin { | |
/// 2. next | ||
/// 2. *.remove | ||
/// 1. previous | ||
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. Seems both 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. I think the existing syntax can coexist with the additional one, so I don't see why we should remove the existing one. What makes you think we should? 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. I'd expect we use either 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. I don't see why it would be an error. They could be used in conjunction as well. Why do you want to restrict it? 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. Its not an error really, just feels that it might have undesirable consequences. Maybe I'm overreacting really as I can't come up with a potential issue on this one 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. If it helps, I don't see a potential issue in this part of the code either, and I've thought about it quite a bit 🙂 |
||
/// 2. next | ||
/// 2. previous_regex | ||
/// 3. next | ||
/// | ||
/// This ordering has implications on the result of semantical contradictions, so that the `*.remove` labels take precedence over `*.add`. | ||
/// | ||
|
@@ -94,11 +99,18 @@ impl EdgeAddRemovePlugin { | |
}; | ||
} | ||
|
||
let previous_remove_key = format!("{}.{}", self.key_prefix, "previous.remove"); | ||
graph | ||
.find_by_metadata_key(&format!("{}.{}", self.key_prefix, "previous.remove")) | ||
.find_by_metadata_key(&previous_remove_key) | ||
.into_iter() | ||
.try_for_each( | ||
|(to, to_version, from_csv): (ReleaseId, String, String)| -> Fallible<()> { | ||
if self.remove_consumed_metadata { | ||
graph | ||
.get_metadata_as_ref_mut(&to) | ||
.map(|metadata| metadata.remove(&previous_remove_key))?; | ||
} | ||
|
||
if from_csv.trim() == self.remove_all_edges_value { | ||
let parents: Vec<daggy::EdgeIndex> = graph | ||
.previous_releases(&to) | ||
|
@@ -114,7 +126,7 @@ impl EdgeAddRemovePlugin { | |
try_annotate_semver_build(&mut graph, from_version, &to)?; | ||
|
||
if let Some(from) = graph.find_by_version(&from_version) { | ||
info!("[{}]: removing previous {}", from_version, to_version,); | ||
info!("[{}]: removing previous {}", to_version, from_version); | ||
handle_remove_edge!(from, to) | ||
} else { | ||
warn!( | ||
|
@@ -127,11 +139,73 @@ impl EdgeAddRemovePlugin { | |
}, | ||
)?; | ||
|
||
// Remove edges instructed by "previous.remove_regex" | ||
let previous_remove_regex_key = format!("{}.{}", self.key_prefix, "previous.remove_regex"); | ||
graph | ||
.find_by_metadata_key(&previous_remove_regex_key) | ||
.into_iter() | ||
.try_for_each( | ||
|(to, to_version, from_regex_string): (ReleaseId, String, String)| -> Fallible<()> { | ||
if self.remove_consumed_metadata { | ||
graph | ||
.get_metadata_as_ref_mut(&to) | ||
.map(|metadata| metadata.remove(&previous_remove_regex_key))?; | ||
} | ||
|
||
let from_regex = regex::Regex::new(&from_regex_string) | ||
.context(format!("Parsing {} as Regex", &from_regex_string))?; | ||
|
||
if from_regex_string == ".*" { | ||
let parents: Vec<daggy::EdgeIndex> = graph | ||
.previous_releases(&to) | ||
.map(|(edge_index, _, _)| edge_index) | ||
.collect(); | ||
|
||
trace!( | ||
"removing parents by regex for '{}': {:?}", | ||
to_version, | ||
parents | ||
); | ||
return graph.remove_edges_by_index(&parents); | ||
}; | ||
|
||
let froms = graph.find_by_fn_mut(|release| { | ||
if from_regex.is_match(release.version()) { | ||
debug!( | ||
"Regex '{}' matches version '{}'", | ||
&from_regex, | ||
release.version(), | ||
); | ||
true | ||
} else { | ||
false | ||
} | ||
}); | ||
|
||
for (from, from_version) in froms { | ||
info!( | ||
"[{}]: removing previous {} by regex", | ||
to_version, from_version | ||
); | ||
handle_remove_edge!(from, to); | ||
} | ||
|
||
Ok(()) | ||
}, | ||
)?; | ||
|
||
let next_remove_key = format!("{}.{}", self.key_prefix, "next.remove"); | ||
graph | ||
.find_by_metadata_key(&format!("{}.{}", self.key_prefix, "next.remove")) | ||
.find_by_metadata_key(&next_remove_key) | ||
.into_iter() | ||
.try_for_each( | ||
|(from, from_version, to_csv): (ReleaseId, String, String)| -> Fallible<()> { | ||
if self.remove_consumed_metadata { | ||
graph | ||
.get_metadata_as_ref_mut(&from) | ||
.map(|metadata| metadata.remove(&next_remove_key))?; | ||
} | ||
|
||
for to_version in to_csv.split(',').map(str::trim) { | ||
let to_version = try_annotate_semver_build(&mut graph, to_version, &from)?; | ||
if let Some(to) = graph.find_by_version(&to_version) { | ||
|
@@ -167,10 +241,17 @@ impl EdgeAddRemovePlugin { | |
}; | ||
} | ||
|
||
let previous_add_key = format!("{}.{}", self.key_prefix, "previous.add"); | ||
graph | ||
.find_by_metadata_key(&format!("{}.{}", self.key_prefix, "previous.add")) | ||
.find_by_metadata_key(&previous_add_key) | ||
.into_iter() | ||
.try_for_each(|(to, to_version, from_csv)| -> Fallible<()> { | ||
if self.remove_consumed_metadata { | ||
graph | ||
.get_metadata_as_ref_mut(&to) | ||
.map(|metadata| metadata.remove(&previous_add_key))?; | ||
} | ||
|
||
for from_version in from_csv.split(',').map(str::trim) { | ||
let from_version_annotated = | ||
try_annotate_semver_build(&mut graph, from_version, &to)?; | ||
|
@@ -191,10 +272,17 @@ impl EdgeAddRemovePlugin { | |
Ok(()) | ||
})?; | ||
|
||
let next_add_key = format!("{}.{}", self.key_prefix, "next.add"); | ||
graph | ||
.find_by_metadata_key(&format!("{}.{}", self.key_prefix, "next.add")) | ||
.find_by_metadata_key(&next_add_key) | ||
.into_iter() | ||
.try_for_each(|(from, from_version, to_csv)| -> Fallible<()> { | ||
if self.remove_consumed_metadata { | ||
graph | ||
.get_metadata_as_ref_mut(&from) | ||
.map(|metadata| metadata.remove(&next_add_key))?; | ||
} | ||
|
||
for to_version in to_csv.split(',').map(str::trim) { | ||
let to_version_annotated = | ||
try_annotate_semver_build(&mut graph, to_version, &from)?; | ||
|
@@ -290,6 +378,8 @@ mod tests { | |
let plugin = Box::new(EdgeAddRemovePlugin { | ||
key_prefix, | ||
remove_all_edges_value: DEFAULT_REMOVE_ALL_EDGES_VALUE.to_string(), | ||
|
||
..Default::default() | ||
}); | ||
let future_processed_graph = plugin.run_internal(InternalIO { | ||
graph: input_graph.clone(), | ||
|
@@ -343,6 +433,8 @@ mod tests { | |
let plugin = Box::new(EdgeAddRemovePlugin { | ||
key_prefix, | ||
remove_all_edges_value: DEFAULT_REMOVE_ALL_EDGES_VALUE.to_string(), | ||
|
||
..Default::default() | ||
}); | ||
let future_processed_graph = plugin.run_internal(InternalIO { | ||
graph: input_graph, | ||
|
@@ -405,6 +497,8 @@ mod tests { | |
let plugin = Box::new(EdgeAddRemovePlugin { | ||
key_prefix, | ||
remove_all_edges_value: DEFAULT_REMOVE_ALL_EDGES_VALUE.to_string(), | ||
|
||
..Default::default() | ||
}); | ||
let future_processed_graph = plugin.run_internal(InternalIO { | ||
graph: input_graph, | ||
|
@@ -455,6 +549,8 @@ mod tests { | |
let plugin = Box::new(EdgeAddRemovePlugin { | ||
key_prefix, | ||
remove_all_edges_value: DEFAULT_REMOVE_ALL_EDGES_VALUE.to_string(), | ||
|
||
..Default::default() | ||
}); | ||
let future_processed_graph = plugin.run_internal(InternalIO { | ||
graph: input_graph, | ||
|
@@ -508,6 +604,8 @@ mod tests { | |
let plugin = Box::new(EdgeAddRemovePlugin { | ||
key_prefix, | ||
remove_all_edges_value: DEFAULT_REMOVE_ALL_EDGES_VALUE.to_string(), | ||
|
||
..Default::default() | ||
}); | ||
|
||
let future_processed_graph = plugin.run_internal(InternalIO { | ||
|
@@ -558,6 +656,8 @@ mod tests { | |
let plugin = Box::new(EdgeAddRemovePlugin { | ||
key_prefix: KEY_PREFIX.to_string(), | ||
remove_all_edges_value: DEFAULT_REMOVE_ALL_EDGES_VALUE.to_string(), | ||
|
||
..Default::default() | ||
}); | ||
let future_processed_graph = plugin.run_internal(InternalIO { | ||
graph: input_graph.clone(), | ||
|
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.
Do we need to make this tuneable? Can we just always do it?
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.
It can be helpful for debugging to leave them in, so see what annotations are on the release. Also for now it's still off by default, which is compatible with the existing deployments.
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.
Can this be used to force the plugin to discard previous processed metadata and start with fresh metadata scanning ?
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.
This controls whether the metadata which is used by this plugin is removed after processing or not. As an example, if there is a
previous.remove
with the value1.2.3
metadata on a release, this plugin will remove the edge, in the graph. Ifremove_consumed_metadata
istrue
in the plugin configuration, it will also remove the metadata entry with the keyprevious.remove
.