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

Ignore desiredCount of ECS when it's 0 or not set for AutoScaling #5030

Merged
merged 23 commits into from
Jul 18, 2024

Conversation

t-kikuc
Copy link
Member

@t-kikuc t-kikuc commented Jul 8, 2024

What this PR does / why we need it:

- Introduced a new config attribute ignoreDesiredCountOnUpdate, which ignores desiredCount when updating a service.

  • [edited] Ignore desiredCount on updating a service if it's 0 or not set.
  • The purpose is to avoid unintended scale-in when configuring Auto Scaling.

Which issue(s) this PR fixes:

Fixes #5027

Does this PR introduce a user-facing change?: Yes

  • How are users affected by this change: They can use a new config attribute. no
  • Is this breaking change: No
  • How to migrate (if breaking change): N/A

Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.

Project coverage is 22.46%. Comparing base (aff6609) to head (99060a0).
Report is 16 commits behind head on master.

Files Patch % Lines
pkg/app/piped/platformprovider/ecs/client.go 0.00% 17 Missing ⚠️
pkg/app/piped/executor/ecs/ecs.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5030      +/-   ##
==========================================
+ Coverage   22.42%   22.46%   +0.03%     
==========================================
  Files         522      522              
  Lines       56915    57056     +141     
==========================================
+ Hits        12766    12816      +50     
- Misses      43123    43213      +90     
- Partials     1026     1027       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 132 to 134
if !ignoreDesiredCount {
input.DesiredCount = aws.Int32(service.DesiredCount)
}
Copy link
Member

@khanhtc1202 khanhtc1202 Jul 8, 2024

Choose a reason for hiding this comment

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

@t-kikuc I think when users tend to ignore expressly setting the desiredCount value, they will leave it empty (or remove that line from the manifests); having this flag added can lead to some confusing configuration when users set the desiredCount value in service file but set this flag in the app configuration as true 🤔
For whatever cases, how about to change this logic as

	input := &ecs.UpdateServiceInput{
		Cluster:              service.ClusterArn,
		....
	}
	if service.DesiredCount != 0 {
		input.DesiredCount = aws.Int32(service.DesiredCount)
	}

Copy link
Member Author

Choose a reason for hiding this comment

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

@khanhtc1202
Thank you so much. Your code seems really simple and great, and I also think they will remove desiredCount.

However, there are two patterns we should consider.

  1. Even if a user truly wants to scale-in tasks to 0 by desiredCount: 0, desiredCount won't be 0.
    • e.g. When a user wants to keep the service but it does not need to serve.
  2. DriftDetection will be inevitable because a piped cannot judge whether to ignore desiredCount.
    • case-a.
      1. current desiredCount= 5
      2. ->Scale up to 10 by AutoScaling
      3. -> DriftDetection will reconcile to 5.
    • case-b.
      1. current desiredCount= 5
      2. -> new desiredCount= 0
      3. -> DriftDetection will try to reconcile to 0 every time (but it won't actually be 0).

That's why I think the new config attribute is required.

Copy link
Member

Choose a reason for hiding this comment

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

@t-kikuc Across the Kubernetes QuickSync configuration of pipecd, I think currently we don't support prune resource (tasks) for ECS application, which mean we can forget about the behavior when users set desiredCount to zero to remove the tasks (ref: https://pipecd.dev/docs-v0.48.x/user-guide/configuration-reference/#kubernetesquicksync).

Copy link
Member

Choose a reason for hiding this comment

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

Of course, I understand the need to support the prune resource on deployment, but I think it should be a separate change, not this PR. Also, in such cases, we can just add a new interface (not update this UpdateService) but call the new function like PruneService. Then, in the implementation, we set the desiredCount to zero.
My point is, we should not change the interface whenever we need a change that is not actually worth; creating a new one is a better choice 😄 (If follow the OOP principles - if you're a former java dev, you know what I mean 😉 )

Copy link
Member Author

Choose a reason for hiding this comment

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

@khanhtc1202

we don't support prune resource

To be precise, this is not pruning, it's scaling-in.
Of course, I know the principle and won't use UpdateService() for pruning.

You mean scaling-in to 0 tasks is not necessary?

DriftDetection

I found a simpler way based on your code.

Let's ignore the drift If

  • diff is only desiredCount
  • desiredCount in new commit = 0

Then we can support both of two patterns:

  • reconciling to desiredCount(>0) in the new commit
  • skipping reconciling when desiredCount is 0 or not defined

In case I mentioned, a user should remove desiredCount from the serviceDef.

case-b.
current desiredCount= 5
-> new desiredCount= 0
-> DriftDetection will try to reconcile to 0 every time (but it won't actually be 0).

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@t-kikuc Thanks for making it clear; I forgot about the recreating case 😢
Then, how about

Copy link
Member Author

Choose a reason for hiding this comment

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

@khanhtc1202
Thanks,

Let's ignore "scaling-in to 0 tasks is not necessary" cases for simplicity.
It is not a common case for production-ready services.

If needed, let's support prune feature like K8sApp.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you 🙏

@t-kikuc t-kikuc changed the title Add a config attribute to ignore desiredCount on updating a service Ignore desiredCount of ECS when it's 0 or not set for AutoScaling Jul 11, 2024
@t-kikuc t-kikuc marked this pull request as ready for review July 11, 2024 09:38
khanhtc1202
khanhtc1202 previously approved these changes Jul 11, 2024
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you 🪨

Comment on lines +519 to 521
- As long as `desiredCount` is 0 or not set, `desiredCount` of your service will NOT be updated in deployments.
- If `desiredCount` is 0 or not set for a new service, the service's `desiredCount` will be 0.
- `capacityProviderStrategy` is not supported.
Copy link
Member

Choose a reason for hiding this comment

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

[Ask] When enabling ECS autoscaling, what should users do? In my understanding, they set desiredCount to 0 after setting up autoscaling. Is it right?

Copy link
Contributor

@Warashi Warashi Jul 12, 2024

Choose a reason for hiding this comment

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

Just to sure. I have the same question.

Users can follow the below steps to create an autoscaled service. Is this correct?

  1. create a service with the desiredCount as 0 or not specified. if it is not specified, the desiredCount is treated as 0.
  2. configure autoscaling, and autoscaling policy or something like this updates desiredCount.
  3. when updating a service, piped ignores the desiredCount. So the count of tasks is not touched.

Copy link
Contributor

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

LGTM

@t-kikuc t-kikuc requested a review from khanhtc1202 July 16, 2024 07:52
@t-kikuc t-kikuc enabled auto-merge (squash) July 18, 2024 03:14
Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

LGTM 🆗

@t-kikuc t-kikuc merged commit 012eb25 into master Jul 18, 2024
17 of 18 checks passed
@t-kikuc t-kikuc deleted the ecs-ignore-desired-count branch July 18, 2024 04:00
@github-actions github-actions bot mentioned this pull request Jul 18, 2024
t-kikuc added a commit that referenced this pull request Jul 18, 2024
…5030)

* add a flag: ignoreDesiredCountOnUpdate

Signed-off-by: t-kikuc <[email protected]>

* ignore desiredCount on updateService if needed

Signed-off-by: t-kikuc <[email protected]>

* Add a flag ignoreDesiredCountOnUpdate into each func

Signed-off-by: t-kikuc <[email protected]>

* Format func params and comment

Signed-off-by: t-kikuc <[email protected]>

* add docs

Signed-off-by: t-kikuc <[email protected]>

* fix tests: add a missing attribute

Signed-off-by: t-kikuc <[email protected]>

* recover desiredCount in CreateService (mistake)

Signed-off-by: t-kikuc <[email protected]>

* add mentioning driftdetection

Signed-off-by: t-kikuc <[email protected]>

* Revert changes of adding ignoreDesiredCountOnUpdate

This reverts commit a0f3459.

Signed-off-by: t-kikuc <[email protected]>

* Revert commits of adding ignoreDesiredCount"

This reverts commit 7d65824.

Signed-off-by: t-kikuc <[email protected]>

* Revert "add docs"

This reverts commit dcd7dc9.

Signed-off-by: t-kikuc <[email protected]>

* Revert "Format func params and comment"

This reverts commit 5103158.

Signed-off-by: t-kikuc <[email protected]>

* Revert "Add a flag ignoreDesiredCountOnUpdate into each func"

This reverts commit d17a9b7.

Signed-off-by: t-kikuc <[email protected]>

* Revert "ignore desiredCount on updateService if needed"

This reverts commit cf3efbf.

Signed-off-by: t-kikuc <[email protected]>

* Revert "add a flag: ignoreDesiredCountOnUpdate"

This reverts commit 6b2af75.

Signed-off-by: t-kikuc <[email protected]>

* ignore updating desiredCount if it's 0 or not defined

Signed-off-by: t-kikuc <[email protected]>

* Use pruning when 'recreate' is on

Signed-off-by: t-kikuc <[email protected]>

* add docs

Signed-off-by: t-kikuc <[email protected]>

* refine docs

Signed-off-by: t-kikuc <[email protected]>

* Clarify procedure of configuring

Signed-off-by: t-kikuc <[email protected]>

---------

Signed-off-by: t-kikuc <[email protected]>
t-kikuc added a commit that referenced this pull request Jul 18, 2024
…5030)

* add a flag: ignoreDesiredCountOnUpdate

Signed-off-by: t-kikuc <[email protected]>

* ignore desiredCount on updateService if needed

Signed-off-by: t-kikuc <[email protected]>

* Add a flag ignoreDesiredCountOnUpdate into each func

Signed-off-by: t-kikuc <[email protected]>

* Format func params and comment

Signed-off-by: t-kikuc <[email protected]>

* add docs

Signed-off-by: t-kikuc <[email protected]>

* fix tests: add a missing attribute

Signed-off-by: t-kikuc <[email protected]>

* recover desiredCount in CreateService (mistake)

Signed-off-by: t-kikuc <[email protected]>

* add mentioning driftdetection

Signed-off-by: t-kikuc <[email protected]>

* Revert changes of adding ignoreDesiredCountOnUpdate

This reverts commit a0f3459.

Signed-off-by: t-kikuc <[email protected]>

* Revert commits of adding ignoreDesiredCount"

This reverts commit 7d65824.

Signed-off-by: t-kikuc <[email protected]>

* Revert "add docs"

This reverts commit dcd7dc9.

Signed-off-by: t-kikuc <[email protected]>

* Revert "Format func params and comment"

This reverts commit 5103158.

Signed-off-by: t-kikuc <[email protected]>

* Revert "Add a flag ignoreDesiredCountOnUpdate into each func"

This reverts commit d17a9b7.

Signed-off-by: t-kikuc <[email protected]>

* Revert "ignore desiredCount on updateService if needed"

This reverts commit cf3efbf.

Signed-off-by: t-kikuc <[email protected]>

* Revert "add a flag: ignoreDesiredCountOnUpdate"

This reverts commit 6b2af75.

Signed-off-by: t-kikuc <[email protected]>

* ignore updating desiredCount if it's 0 or not defined

Signed-off-by: t-kikuc <[email protected]>

* Use pruning when 'recreate' is on

Signed-off-by: t-kikuc <[email protected]>

* add docs

Signed-off-by: t-kikuc <[email protected]>

* refine docs

Signed-off-by: t-kikuc <[email protected]>

* Clarify procedure of configuring

Signed-off-by: t-kikuc <[email protected]>

---------

Signed-off-by: t-kikuc <[email protected]>
t-kikuc added a commit that referenced this pull request Jul 18, 2024
* fix: upgrade @loadable/component from 5.14.1 to 5.16.4 (#5000)

Snyk has created this PR to upgrade @loadable/component from 5.14.1 to 5.16.4.

See this package in yarn:
@loadable/component

See this project in Snyk:
https://app.snyk.io/org/pipecd/project/f41c5767-b506-4f59-beb9-ef662258eb9a?utm_source=github&utm_medium=referral&page=upgrade-pr

Signed-off-by: khanhtc1202 <[email protected]>
Co-authored-by: snyk-bot <[email protected]>
Signed-off-by: t-kikuc <[email protected]>

* fix: upgrade @reduxjs/toolkit from 1.8.5 to 1.9.7 (#4999)

Snyk has created this PR to upgrade @reduxjs/toolkit from 1.8.5 to 1.9.7.

See this package in yarn:
@reduxjs/toolkit

See this project in Snyk:
https://app.snyk.io/org/pipecd/project/f41c5767-b506-4f59-beb9-ef662258eb9a?utm_source=github&utm_medium=referral&page=upgrade-pr

Co-authored-by: snyk-bot <[email protected]>
Signed-off-by: t-kikuc <[email protected]>

* fix: upgrade react-router-dom from 5.2.0 to 5.3.4 (#5001)

Snyk has created this PR to upgrade react-router-dom from 5.2.0 to 5.3.4.

See this package in yarn:
react-router-dom

See this project in Snyk:
https://app.snyk.io/org/pipecd/project/f41c5767-b506-4f59-beb9-ef662258eb9a?utm_source=github&utm_medium=referral&page=upgrade-pr

Signed-off-by: t-kikuc <[email protected]>
Co-authored-by: snyk-bot <[email protected]>
Co-authored-by: Tetsuya Kikuchi <[email protected]>
Signed-off-by: t-kikuc <[email protected]>

* fix: upgrade grpc-web from 1.0.7 to 1.5.0 (#4984)

Snyk has created this PR to upgrade grpc-web from 1.0.7 to 1.5.0.

See this package in yarn:
grpc-web

See this project in Snyk:
https://app.snyk.io/org/pipecd/project/f41c5767-b506-4f59-beb9-ef662258eb9a?utm_source=github&utm_medium=referral&page=upgrade-pr

Co-authored-by: snyk-bot <[email protected]>
Signed-off-by: t-kikuc <[email protected]>

* [Snyk] Security upgrade alpine from 3.17 to 3.20 (#5014)

* fix: docs/Dockerfile to reduce vulnerabilities

The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-ALPINE317-OPENSSL-7413590
- https://snyk.io/vuln/SNYK-ALPINE317-OPENSSL-7413590
- https://snyk.io/vuln/SNYK-ALPINE317-OPENSSL-7413591
- https://snyk.io/vuln/SNYK-ALPINE317-OPENSSL-7413591

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Bump alpine

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Co-authored-by: snyk-bot <[email protected]>
Co-authored-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: t-kikuc <[email protected]>

* Upgrade google-cloud-sdk (#5042)

* Use x86_64 version of google-cloud-sdk

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Upgrade google-cloud-sdk

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: t-kikuc <[email protected]>

* feat: add support mention slack groups for NotificationReceiverSlack and NotificationMention (#4903)

* feat: add support mentione groups for NotifactionReceiverSlack and slackGroups for NotificationMention

Signed-off-by: hungran <[email protected]>

* remove change in docs v0.47.x

Signed-off-by: hungran <[email protected]>

* update docs

Signed-off-by: hungran <[email protected]>

* update logic for having getGroupsAsString()

Signed-off-by: hungran <[email protected]>

* using <!subteam^ID> for group mentioning

Signed-off-by: hungran <[email protected]>

* typo

Signed-off-by: hungran <[email protected]>

* call both getAccountsAsString and getGroupsAsString

Signed-off-by: hungran <[email protected]>

* revert change pkg/model/notificationevent.pb.go

Signed-off-by: hungran <[email protected]>

* use same format for group <!subteam^ID>

Signed-off-by: hungran <[email protected]>

* same method to format slack group

Signed-off-by: hungran <[email protected]>

* following slack api, !subteam^ is a literal string that should not change

Signed-off-by: hungran <[email protected]>

* feat: add slackUsers field and mark slack as deprecated field

Signed-off-by: hungran <[email protected]>

* revert pkg/model/notificationevent.pb.go

Signed-off-by: hungran <[email protected]>

* update doc Using the groupID or teamID in the documents makes it easier for users to use this feature.

Signed-off-by: hungran <[email protected]>

* add code gen

Signed-off-by: hungran <[email protected]>

* adjust mention users and slack logic

Signed-off-by: hungran <[email protected]>

* unify the process to get users and groups in the same method

Signed-off-by: hungran <[email protected]>

---------

Signed-off-by: hungran <[email protected]>
Signed-off-by: t-kikuc <[email protected]>

* Ignore `desiredCount` of ECS when it's 0 or not set for AutoScaling (#5030)

* add a flag: ignoreDesiredCountOnUpdate

Signed-off-by: t-kikuc <[email protected]>

* ignore desiredCount on updateService if needed

Signed-off-by: t-kikuc <[email protected]>

* Add a flag ignoreDesiredCountOnUpdate into each func

Signed-off-by: t-kikuc <[email protected]>

* Format func params and comment

Signed-off-by: t-kikuc <[email protected]>

* add docs

Signed-off-by: t-kikuc <[email protected]>

* fix tests: add a missing attribute

Signed-off-by: t-kikuc <[email protected]>

* recover desiredCount in CreateService (mistake)

Signed-off-by: t-kikuc <[email protected]>

* add mentioning driftdetection

Signed-off-by: t-kikuc <[email protected]>

* Revert changes of adding ignoreDesiredCountOnUpdate

This reverts commit a0f3459.

Signed-off-by: t-kikuc <[email protected]>

* Revert commits of adding ignoreDesiredCount"

This reverts commit 7d65824.

Signed-off-by: t-kikuc <[email protected]>

* Revert "add docs"

This reverts commit dcd7dc9.

Signed-off-by: t-kikuc <[email protected]>

* Revert "Format func params and comment"

This reverts commit 5103158.

Signed-off-by: t-kikuc <[email protected]>

* Revert "Add a flag ignoreDesiredCountOnUpdate into each func"

This reverts commit d17a9b7.

Signed-off-by: t-kikuc <[email protected]>

* Revert "ignore desiredCount on updateService if needed"

This reverts commit cf3efbf.

Signed-off-by: t-kikuc <[email protected]>

* Revert "add a flag: ignoreDesiredCountOnUpdate"

This reverts commit 6b2af75.

Signed-off-by: t-kikuc <[email protected]>

* ignore updating desiredCount if it's 0 or not defined

Signed-off-by: t-kikuc <[email protected]>

* Use pruning when 'recreate' is on

Signed-off-by: t-kikuc <[email protected]>

* add docs

Signed-off-by: t-kikuc <[email protected]>

* refine docs

Signed-off-by: t-kikuc <[email protected]>

* Clarify procedure of configuring

Signed-off-by: t-kikuc <[email protected]>

---------

Signed-off-by: t-kikuc <[email protected]>

---------

Signed-off-by: khanhtc1202 <[email protected]>
Signed-off-by: t-kikuc <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: hungran <[email protected]>
Co-authored-by: Khanh Tran <[email protected]>
Co-authored-by: snyk-bot <[email protected]>
Co-authored-by: Chris Aniszczyk <[email protected]>
Co-authored-by: Shinnosuke Sawada-Dazai <[email protected]>
Co-authored-by: Henry Vu <[email protected]>
@github-actions github-actions bot mentioned this pull request Jul 18, 2024
This was referenced Jul 29, 2024
This was referenced Aug 13, 2024
@github-actions github-actions bot mentioned this pull request Aug 26, 2024
This was referenced Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/go kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ECS]When using application autoscaling, the desired count must be adjusted each time.
4 participants