Skip to content
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

Model transformer: model reconciliation for agent upgrades #3878

Merged
merged 4 commits into from Sep 7, 2023

Conversation

Realmonia
Copy link
Contributor

@Realmonia Realmonia commented Aug 29, 2023

Summary

This adds the functionality of model transformer to agent, which detects model incompatibility between the running agent version and the data we persists in boltDB.

Note 1: the transformation functions and models introduced in this PR is example/template change and will never be executed!
Note 2: this is only for agent upgrades. Support for agent downgrades is not in scope.

A version check (using version.Version in "running" agent and agent-version in boltDB metadata bucket) is performed before we load boltDB data to agent state. If a version difference is detected, the loaded json will go through a series of transformation functions, apply those applicable transformation functions, then reach a state that it is compatible with current running agent version then loaded into agent state.

Here, "applicable" transformation functions means that the model is older than the version we introduce a new model (and as a result, anew transformation function). We check the model version against transformation function's threshold version, if it is older (smaller version number), it will go through the transformation function.

Implementation details

  • transformer in ecs-agent module
    • transformer stores transformation functions registered by agent (during data client initialization), and expose method to actually execute transformation functions in a loop (through a slice of function closure).
  • model and transtf in agent module
    • model contains different models we introduced that are mutually incompatible. transtf contains corresponding transformation functions we introduced with models.

I also included a template task transformation function which will never get executed now.

Testing

New tests cover the changes: Yes

New unit tests are added. Manual testing done: manually verified following:

  • Transformation function executed if a model compatibility is detected and there is a version upgrade
  • Transformation function skipped if no model compatibility is detected and there is a version upgrade
  • Transformation function skipped if there is no version upgrade

Log from manual testing

BoltDB stored agent version is 1.75.0

sudo systemctl restart ecs

level=info time=2023-08-30T00:12:52Z msg="Starting Amazon ECS Agent" version="1.75.2" commit="UNKNOWN"
level=info time=2023-08-30T00:12:52Z msg="Registered transformation function with threshold 1.99.0."
level=info time=2023-08-30T00:12:52Z msg="Agent version associated with task model in boltdb 1.75.0 is below threshold 1.99.0. Transformation needed."
level=info time=2023-08-30T00:12:52Z msg="Executing transformation function with threshold 1.99.0."
level=info time=2023-08-30T00:12:52Z msg="Transform associated with version 1.99.0 finished."

transformation functions registered and executed, since 1.75.0 < 1.75.2 and a breaking change introduced.

sudo systemctl restart ecs

level=info time=2023-08-30T00:24:23Z msg="Starting Amazon ECS Agent" version="1.75.2" commit="UNKNOWN"
level=info time=2023-08-30T00:24:23Z msg="Registered transformation function with threshold 1.99.0."

transformation functions registered but not executed, since it's 1.75.2 = 1.75.2, and models have been updated since last load.

Description for the changelog

Model transformer: model reconciliation for agent upgrades

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Realmonia Realmonia force-pushed the modelUpdateSupport branch 9 times, most recently from 7392af8 to a33b844 Compare August 31, 2023 00:58
@Realmonia Realmonia force-pushed the modelUpdateSupport branch 2 times, most recently from 0145053 to 219a63b Compare August 31, 2023 20:21
@Realmonia Realmonia marked this pull request as ready for review August 31, 2023 20:28
@Realmonia Realmonia requested a review from a team as a code owner August 31, 2023 20:28
ecs-agent/modeltransformer/transformer.go Outdated Show resolved Hide resolved
ecs-agent/modeltransformer/transformer.go Outdated Show resolved Hide resolved
ecs-agent/modeltransformer/transformer.go Outdated Show resolved Hide resolved
ecs-agent/modeltransformer/transformer.go Outdated Show resolved Hide resolved
danehlim
danehlim previously approved these changes Sep 1, 2023
@chienhanlin
Copy link
Contributor

Thanks a lot for contributing this transformation logic to unblock our future & ongoing works!
In addition to the comments left on each line, I still have some questions/comments listed as follows

  1. Can we update the PR template here to ask contributors to update the transformation files/functions if any breaking change is introduced by their PR?
  2. Have we tested it on windows, AL2 ARM, AL2023 ARM and ECS Anywhere?
  3. Have we validated it with TestUpdateContainerAgent on platforms that support update-container-agent locally?
  4. Could we add and highlight "downgrade Agent version is not supported" in the summary section?
  5. As downgraded is not supported, should we create an announcement or an issue to notify customers?
    Thanks!

@Realmonia
Copy link
Contributor Author

Thanks a lot for contributing this transformation logic to unblock our future & ongoing works! In addition to the comments left on each line, I still have some questions/comments listed as follows

  1. Can we update the PR template here to ask contributors to update the transformation files/functions if any breaking change is introduced by their PR?
  2. Have we tested it on windows, AL2 ARM, AL2023 ARM and ECS Anywhere?
  3. Have we validated it with TestUpdateContainerAgent on platforms that support update-container-agent locally?
  4. Could we add and highlight "downgrade Agent version is not supported" in the summary section?
  5. As downgraded is not supported, should we create an announcement or an issue to notify customers?
    Thanks!

Thanks for the input. I think one thing I am not making clear in the description is the transformation functions and models introduced here are just placeholder and will always be skipped with current implementation. Therefore I didn't do 2/3/5. I will do 1 but maybe after this one is pushed, and will do 4!

@Realmonia Realmonia merged commit d985fb1 into aws:dev Sep 7, 2023
40 checks passed
@Realmonia Realmonia deleted the modelUpdateSupport branch September 7, 2023 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants