feat(config-migrate): couple to infra-agent agent type, simplify#1640
feat(config-migrate): couple to infra-agent agent type, simplify#1640DavSanchez merged 16 commits intomainfrom
Conversation
7ccec20 to
058494c
Compare
73af478 to
a82242b
Compare
|
E2E test for on-host migration scenario (part of nightly builds) is successful: https://github.com/newrelic/newrelic-agent-control/actions/runs/17630098266/job/50096362311 |
a3ae80a to
85ec477
Compare
sigilioso
left a comment
There was a problem hiding this comment.
The approach looks good! Find some comment below
| let file_reader = &self.file_reader; | ||
|
|
||
| // Retrieve the configuration for an existing infrastructure-agent installation. | ||
| let config_agent_key = String::from("config_agent"); |
There was a problem hiding this comment.
Could we use constants for the keys? I also wonder if we could have some sort of sanity check if the keys ever change in the Agent Type? Maybe a test involving the registry could be enough 🤔
| if let Some((key, value)) = map.next_entry::<String, Sequence>()? { | ||
| if map.next_key::<String>()?.is_some() { | ||
| Err(M::Error::custom( | ||
| "expected a single key-value pair in the map", |
There was a problem hiding this comment.
Shouldn't we support a single config file with multiple keys?
integrations:
- name: nri-docker
# ...
- name: nri-postgresql
# ...
discovery:
# ...
variables:
# ...I'm not completely sure if we were supporting it before (and I'm also not sure if the infra agent works well with such config), but the docs made me wonder.
There was a problem hiding this comment.
You might be right. My goal was the simplest thing possible that works in our current setup, but it might make sense to open up for a bit more. Looking into it!
There was a problem hiding this comment.
This highlighted the need of multiple files and now it is solved, right?
There was a problem hiding this comment.
This was tied to expecting a certain file structure for integrations and logging files and how to merge them into a single file, but now it's not needed yes!
Besides, I think it was better to have it accept generic YAML instead of defining structures for these file types, given it might change by the OHAI team and we might not notice (introducing new fields or something), so I removed the custom parse.
1686105 to
94e58ee
Compare
85ec477 to
79a2ea5
Compare
ec82968 to
d217e84
Compare
79a2ea5 to
36dce86
Compare
d217e84 to
5bbf894
Compare
36dce86 to
e6edf11
Compare
1db5aba to
0985366
Compare
ffc1b8f to
f251eb1
Compare
bece22b to
3c55a30
Compare
3ad1536 to
8383858
Compare
3c55a30 to
cf0b832
Compare
sigilioso
left a comment
There was a problem hiding this comment.
Thanks for taking care of this. Find some comments below.
| fn process_config_input(input: String) -> String { | ||
| // This regex matches {{VAR_NAME}} not already inside quotes | ||
| let re = Regex::new(r#"(?P<pre>[^'"]|^)\{\{([A-Za-z0-9_]+)\}\}(?P<post>[^'"]|$)"#).unwrap(); | ||
| re.replace_all(&input, "${pre}'{{${2}}}'${post}") | ||
| .to_string() | ||
| } |
There was a problem hiding this comment.
We are building the once for each function call, right? Could we build it only once? Maybe something similar to what we do here:
There was a problem hiding this comment.
Aah yes, makes total sense! I'll add it.
| /// This is a regex-based approach that may not cover all edge cases, but works for | ||
| /// the common scenarios we expect (small config strings). |
There was a problem hiding this comment.
Do you have any of those edge cases in mind? 🤔
I was thinking of values that are not supposed to be a string in the config, but I'm not sure there could be any.
I don't think we need to do it now but I think we should allocate some time to document the migration limitations.
There was a problem hiding this comment.
Not sure what would be cases that should work for the infra-agent but not in our migration. In all honesty I wrote the comment when I had another implementation (manual successive replacement of occurrences with String -> String functions) so it probably had flaws that the current implementation hasn't, so I'll reword the comments and start writing docs for the migration tool, if only in the top-level module.
There was a problem hiding this comment.
Probably these docs should have their own task (I don't think it is in the scope of this change)
| if !visited.insert(k) { | ||
| Err(ConversionError::DuplicateKeyFound(k.clone())) |
There was a problem hiding this comment.
I'm not sure if it is feasible but the error message could really help understanding where the problem is, right? It currently says duplicate key found in file and dir mappings: key", but I think it would be useful to say where the key is (unless I am not getting it right!).
By the way, do you think that adding a unit-test to check this error would be worth it?
There was a problem hiding this comment.
As for specifying where exactly the error occurs, this is something that might happen in the config (the stand-alone structure in defaults.rs) that before was controlled only by us (the configs define files_map and dirs_map and if these both define the same key it will modify the migration behavior) but you're right that now I accept an external config input. I'll try to be more verbose to help... or rewrite this config so this cannot even happen 😆
There was a problem hiding this comment.
Ok, I have removed the possibility of duplicate mapping keys altogether, so this shouldn't be an issue anymore, let me know your thoughts! d62334c
There was a problem hiding this comment.
As for specifying where exactly the error occurs, this is something that might happen in the config (the stand-alone structure in defaults.rs)
I wasn't getting it right! I thought it were keys in the config files (which doesn't make sense because we can have duplicates there! (integrations might be defined many times!) 🤦
There was a problem hiding this comment.
Anyway, I think the new changes simplify it quite a bit! 🚀
95ba5ce to
d62334c
Compare
7fa1adb to
b81090f
Compare
What this PR does / why we need it
Follow-up for #1610 and #1619, this adapts the code for the
config-migrateutility so it is coupled to our single use case (the newrelic-infra agent type) and performs its actions in the most straightforward way possible without rewriting the whole program.I have added scenario testing with filesystem access mocked so you can check how this works. Please see
converter.rs.Remaining tasks after all the currently opened PRs are merged:
INTEGRATING_AGENTS.mdas it's promoted to the official one.fileandmap[string]filevariable types and related structure (injected deps).Checklist
[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]
docsis aligned with the change.CONTRIBUTING.md.log level guidelines.