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

cache listeners on routing stage for later use #4599

Merged
merged 3 commits into from
Dec 14, 2023

Conversation

nnnkkk7
Copy link
Contributor

@nnnkkk7 nnnkkk7 commented Sep 10, 2023

What this PR does / why we need it:

  • Cache AWS LoadBalancers Listeners on routing stage

Which issue(s) this PR fixes:

Fixes #4474

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

@nnnkkk7 nnnkkk7 changed the title cache current listeners for later use cache listeners on routing stage for later use Sep 10, 2023
@codecov
Copy link

codecov bot commented Sep 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a64f250) 30.82% compared to head (4e86b6e) 30.85%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4599      +/-   ##
==========================================
+ Coverage   30.82%   30.85%   +0.02%     
==========================================
  Files         221      221              
  Lines       25947    25947              
==========================================
+ Hits         7999     8005       +6     
+ Misses      17297    17291       -6     
  Partials      651      651              

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

for i, v := range currListenerArns {
metadataListeners[fmt.Sprintf(currentListenersKey+"-%d", i)] = v
}
if err := in.MetadataStore.Shared().PutMulti(ctx, metadataListeners); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This only stores the listeners to metadata store, I think we have to add logic for query that data from store before fetch using API (client) at L419 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
I added it. get listeners from cache

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.

Thank you so much for your contribution! 🥇
It's totally OK! I just commented on one nit point!

Comment on lines 457 to 467
// Store created listeners to use later.
addedListeners := make([]string, 0, len(currListenerArns))
addedListeners = append(addedListeners, currListenerArns...)
metadata := strings.Join(addedListeners, ",")
if err := in.MetadataStore.Shared().Put(ctx, currentListenersKey, metadata); err != nil {
in.LogPersister.Errorf("Unable to store created listeners to metadata store: %v", err)
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

[nits]
Are these values of addedListeners the same as currListenerArns ?
If so, it might be better just to use currListenerArns to store as metadata 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@khanhtc1202
Copy link
Member

/review

Copy link

github-actions bot commented Nov 2, 2023

PR Analysis

Main theme

type: Enhancement
description: The PR introduces enhancements to the ecs.go file in the piped/executor/ecs package.

PR summary

type: string
description: The PR enhances the code in ecs.go to store and retrieve traffic routing configuration and active listener information in the metadata store.

Type of PR

Refactoring

PR Feedback:

General suggestions

type: string
description: |-
The code changes look good overall. However, there are a couple of suggestions for improvement:

  • Consider using more descriptive variable names instead of abbreviations to improve code readability.
  • Ensure proper error handling and return appropriate error messages instead of returning false.

Code feedback

type: array
uniqueItems: true
items:
relevant file:
type: string
description: "pkg/app/piped/executor/ecs/ecs.go"
suggestion:
type: string
description: |-
Instead of using abbreviations, use more descriptive variable names. This improves code readability.
For example, replace the following:

  ```diff
  const (
  -	trafficRoutePrimaryMetadataKey = "primary-percentage"
  -	trafficRouteCanaryMetadataKey  = "canary-percentage"
  -	canaryScaleMetadataKey         = "canary-scale"
  +	primaryPercentageMetadataKey = "primary-percentage"
  +	canaryPercentageMetadataKey  = "canary-percentage"
  +	canaryScaleMetadataKey       = "canary-scale"
  )
  ```
  
  Additionally, ensure proper error handling and return appropriate error messages instead of returning `false`. This helps in debugging and improves resiliency. For example:
  
  ```diff
  if err != nil {
      in.LogPersister.Errorf("Failed to get current active listeners: %v", err)
  +    return false, fmt.Errorf("failed to get current active listeners: %w", err)
  }
  ```

relevant line:
type: string
description: |-
+ trafficRoutePrimaryMetadataKey = "primary-percentage"
+ trafficRouteCanaryMetadataKey = "canary-percentage"
+ canaryScaleMetadataKey = "canary-scale"

  +	in.LogPersister.Errorf("Failed to get current active listeners: %v", err)
  +	return false
  
  +	primaryPercentageMetadataKey = "primary-percentage"
  +	canaryPercentageMetadataKey  = "canary-percentage"
  +	canaryScaleMetadataKey       = "canary-scale"
  
  +	return false, fmt.Errorf("failed to get current active listeners: %w", err)

Security concerns:

type: string
description: "no"

@nnnkkk7 nnnkkk7 force-pushed the add-cache-for-aws-lb-listeners branch from 2e77e94 to 87433db Compare November 19, 2023 03:55
@nnnkkk7 nnnkkk7 requested a review from ffjlabo November 19, 2023 03:57
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.

Thank you for your contribution 🚀

@ffjlabo ffjlabo force-pushed the add-cache-for-aws-lb-listeners branch 2 times, most recently from 3ef3dad to 366b0ba Compare November 24, 2023 06:07
Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
@ffjlabo ffjlabo force-pushed the add-cache-for-aws-lb-listeners branch from 366b0ba to 4e86b6e Compare November 27, 2023 10:04
@khanhtc1202
Copy link
Member

Let's me hold this PR until PR #4688 merged 🙏

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.

🚀 🚀 🚀

@khanhtc1202 khanhtc1202 merged commit b4003d7 into pipe-cd:master Dec 14, 2023
13 checks passed
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
* cache current listeners for later use

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

* get listeners from cache

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

* use currListenerArns instead of addedListeners

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

---------

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
* cache current listeners for later use

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

* get listeners from cache

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

* use currListenerArns instead of addedListeners

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

---------

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
* cache current listeners for later use

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

* get listeners from cache

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

* use currListenerArns instead of addedListeners

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

---------

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
Signed-off-by: sZma5a <masaaki.haribote@gmail.com>
@github-actions github-actions bot mentioned this pull request Feb 6, 2024
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Feb 12, 2024
* cache current listeners for later use

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

* get listeners from cache

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

* use currListenerArns instead of addedListeners

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

---------

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
Signed-off-by: 鈴木 優耀 <suzuki_masaaki@cyberagent.co.jp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache AWS LoadBalancers Listeners to reduce API call on routing stage
3 participants