-
Notifications
You must be signed in to change notification settings - Fork 216
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(test): configuration changes and fixes needed to scale-test #1085
base: main
Are you sure you want to change the base?
Conversation
This PR will be closed in 7 days due to inactivity. |
9791c43
to
419dc4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like linter has some feedback though
419dc4d
to
c2ef8e9
Compare
bf79ef1
to
c57c17a
Compare
@@ -30,7 +34,7 @@ func (d *DeleteNamespace) Run() error { | |||
return fmt.Errorf("error creating Kubernetes client: %w", err) | |||
} | |||
|
|||
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second) | |||
ctx, cancel := context.WithTimeout(context.Background(), deleteNamespaceTimeoutSeconds*time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, just inline this. The const makes this less readable (mute the linter if it complains). Also, (even though we're not doing this) the best practice with Go durations is const deleteNamespaceTimeout = 1200 * time.Second
. Embedding a unit like Seconds
in the name is an antipattern.
ctx, cancel := context.WithTimeout(context.Background(), deleteNamespaceTimeoutSeconds*time.Second) | |
ctx, cancel := context.WithTimeout(context.Background(), 1200 * time.Second) |
numberOfSteps := 9 | ||
|
||
backoff := wait.Backoff{ | ||
Steps: 6, | ||
Steps: numberOfSteps, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here, the constant just obscures what's going on more than it helps.
Steps: 9
metav1.PatchOptions{}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("error patching pod: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I wrap errors, the word "error" is typically redundant (it's an error, so it will be logged as such). It's sufficient to just write what you were trying to do when the error occurred, as you've done:
return fmt.Errorf("error patching pod: %w", err) | |
return fmt.Errorf("patching pod: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree that "error" is redundant, but I prefer to write <what happened>
and think that that reads easier when scanning logs.
something like
return fmt.Errorf("error patching pod: %w", err) | |
return fmt.Errorf("failed to patch Pod: %w", err) |
Path: "/metadata/labels/uni-lab-" + fmt.Sprintf("%05d", *counter), | ||
Value: "val", | ||
}) | ||
(*counter)++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just return this? Or let the caller deal with JSON marshalling so they can just look at the len
?
@@ -48,11 +53,18 @@ func (c *CreateResources) Run() error { | |||
return fmt.Errorf("error creating Kubernetes client: %w", err) | |||
} | |||
|
|||
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeoutSeconds*time.Second) | |||
ctx, cancel := context.WithTimeout(context.Background(), timeoutCreateResourcesSeconds*time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find the other instance, but I also want to point out that value * time.Second
is dangerous math to do--you should eliminate it every chance you get. The value can easily overflow as you can see here if someone tries to give you a duration: https://go.dev/play/p/tZhE9KQPdju . time.Duration
is a first-class type and it should be passed around and used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1000000
please use time.Duration
for time instead of the primitive numerical types, and use it as soon as possible: at the interface of parsing config; in the func args; whenever you declare a time var or const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timraymond @rbtr This and other places that is following this kind of pattern (variable to store a single number) was requested by the linter, e.g.:
Error: test/e2e/framework/kubernetes/delete-namespace.go:48:13: Magic number: 9, in <assign> detected (mnd)
Steps: 9,
^
Should we disable this mnd linter?
g.stop = make(chan struct{}) | ||
g.wg.Add(1) | ||
|
||
go func() { | ||
|
||
t := time.NewTicker(5 * time.Minute) | ||
t := time.NewTicker(defaultInterval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaks a goroutine.
defer t.Stop()
Not a huge deal in tests, but it's a habit you should drill.
log.Fatalf("error getting and publishing number of restarts: %v", err) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no point in returning since log.Fatalf
will panic. That said, you should not panic :)
@@ -88,53 +125,61 @@ func (g *GetAndPublishMetrics) Prevalidate() error { | |||
if _, ok := g.AdditionalTelemetryProperty["retinaVersion"]; !ok { | |||
return fmt.Errorf("retinaVersion is required in AdditionalTelemetryProperty") | |||
} | |||
|
|||
if os.Getenv(common.OutputFilePathEnv) == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not crazy about ad-hoc os.Getenv
. The trouble is that it gets difficult to reason about "what is the entire configuration for this process" if you do it often enough. Is there some place where you can put this where it will get loaded in a config struct you can pass around?
permissions := 0o644 | ||
file, err := os.OpenFile(g.outputFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, fs.FileMode(permissions)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline permissions
@@ -12,6 +13,10 @@ import ( | |||
"k8s.io/client-go/tools/clientcmd" | |||
) | |||
|
|||
const ( | |||
timeoutToLabelAllPodsMinutes = 120 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, please use time.Duration
:
timeoutToLabelAllPodsMinutes = 120 | |
podLabelTimeout = 120 * time.Minute |
2a7c193
to
bb3a29f
Compare
Signed-off-by: Alex Castilio dos Santos <[email protected]>
bb3a29f
to
bcb2d2d
Compare
Description
Changes:
OUTPUT_FILEPATH
tocommon/common.go
podStatus
to metrics exportedRelated Issue
If this pull request is related to any issue, please mention it here. Additionally, make sure that the issue is assigned to you before submitting this pull request.
Checklist
git commit -S -s ...
). See this documentation on signing commits.Screenshots (if applicable) or Testing Completed
Please add any relevant screenshots or GIFs to showcase the changes made.
Additional Notes
Add any additional notes or context about the pull request here.
Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.