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

Fix AWS ECS Discovery #2706

Merged
merged 2 commits into from
Aug 15, 2024
Merged

Conversation

Arkatufus
Copy link
Contributor

AWS ECS tag matching logic is wrong, it assumes that all of the tags have to match exactly

Changes

  • Change the tag matching logic to match what Scala Akka is doing
  • Make sure that the Diff() logic follows Scala list[T].diff() behavior exactly

Copy link
Contributor Author

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-review

CancellationToken token)
{
var taskArns = await ListTaskArns(ecsClient, cluster, serviceName, token);
var tasks = await DescribeTasks(ecsClient, cluster, taskArns, token);
// only return tasks with the exact same tags as the filter
var tasksWithTags = tasks.Where(task => task.Tags.IsSame(tags, TagComparer)).ToList();
var tasksWithTags = tasks.Where(task => task.Tags.Select(t => new AwsTag(t.Key, t.Value)).Diff(tags).Count == 0).ToList();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix, it was a porting error from Scala.

When this is ported, it is assumed that Scala list[T].diff() works by returning a distinct set of items from both the left and right list, so it is assumed that the line tags.diff(ecsTags).isEmpty literally means tags items have to match ecsTags.

Turns out list[T].diff() returns items from the left that does not have a match on the right, all it does is a linear walk on the right list and for every item in the right list removes the first matching item on the left.

So the actual correct port for the code tags.diff(ecsTags).isEmpty is actually "Is tags a subset of ecsTags"

@Aaronontheweb Aaronontheweb merged commit 6579315 into akkadotnet:dev Aug 15, 2024
3 checks passed
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.

2 participants