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

test: support running integration test with envoy bin #810

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

spacewander
Copy link
Member

No description provided.

@github-actions github-actions bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 28, 2024
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.72%. Comparing base (97a14ea) to head (6c22db2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #810      +/-   ##
==========================================
+ Coverage   85.68%   85.72%   +0.03%     
==========================================
  Files         141      141              
  Lines        8336     8336              
==========================================
+ Hits         7143     7146       +3     
+ Misses        937      934       -3     
  Partials      256      256              

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

@spacewander spacewander force-pushed the aci_run_intt branch 4 times, most recently from 228bae8 to b5be4c0 Compare November 28, 2024 03:21
@github-actions github-actions bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 28, 2024
@spacewander spacewander force-pushed the aci_run_intt branch 3 times, most recently from 0fc3dfd to 5d34462 Compare November 28, 2024 08:15
@github-actions github-actions bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 28, 2024
@spacewander spacewander marked this pull request as ready for review November 28, 2024 08:31
Comment on lines +161 to 164
portEnv, _ := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT"))
if portEnv != 0 {
port = portEnv
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer the following method, but yours is okay.

Suggested change
portEnv, _ := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT"))
if portEnv != 0 {
port = portEnv
}
if p, err := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")); err == nil && p != 0 {
port = p
}

Copy link
Member Author

Choose a reason for hiding this comment

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

No, thanks! My code style is more concise.

addr["port_value"] = b.dp.Port()

if isBinaryMode() {
for _, l := range root["static_resources"].(map[string]interface{})["listeners"].([]interface{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use staticResource defined above here?

Suggested change
for _, l := range root["static_resources"].(map[string]interface{})["listeners"].([]interface{}) {
for _, l := range staticResource["listeners"].([]interface{}) {

Comment on lines +192 to +193
httpFilters := hcm["http_filters"].([]interface{})
for _, hf := range httpFilters {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like httpFilters is only used once. I prefer to remove this middle variable. But reserving it is also good.

Suggested change
httpFilters := hcm["http_filters"].([]interface{})
for _, hf := range httpFilters {
for _, hf := range hcm["http_filters"].([]interface{}) {

Comment on lines +160 to +165

err = opt.Bootstrap.WriteTo(cfgFile)
cfgFile.Close()
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

cfgFile is used below. We can not close it here immediately.

Suggested change
err = opt.Bootstrap.WriteTo(cfgFile)
cfgFile.Close()
if err != nil {
return nil, err
}
defer cfgFile.Close()
if err = opt.Bootstrap.WriteTo(cfgFile); err != nil {
return nil, err
}

Copy link
Member Author

Choose a reason for hiding this comment

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

We only use cfgFile.Name() later

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, we must close the cfgFile immediately to ensure the written content is flushed.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, Thank you for your detailed explanation.

Comment on lines +201 to +206
image := "m.daocloud.io/docker.io/envoyproxy/envoy:contrib-v1.32.0"

specifiedImage := os.Getenv("PROXY_IMAGE")
if specifiedImage != "" {
image = specifiedImage
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
image := "m.daocloud.io/docker.io/envoyproxy/envoy:contrib-v1.32.0"
specifiedImage := os.Getenv("PROXY_IMAGE")
if specifiedImage != "" {
image = specifiedImage
}
image := "m.daocloud.io/docker.io/envoyproxy/envoy:contrib-v1.32.0"
if specifiedImage := os.Getenv("PROXY_IMAGE"); specifiedImage != "" {
image = specifiedImage
}

hostAddr + " " +
image

envoyCmd = "envoy -c /etc/envoy.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

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

the construct of envoyCmd is simple, what about moving it before cmdLine?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is too trivial to change.

Copy link
Member Author

Choose a reason for hiding this comment

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

The cmdLine doesn't depend on the envoyCmd. And envoyCmd is a new neighbor of the cmdLine. Add the new code after the old one is natural.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, it makes sense to me.

addEnvironemntVariables(cmd, opt.Envs)
}

out, err := cmd.CombinedOutput()
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like we can use following pattern here:

if out, err := cmd.CombinedOutput(); err != nil {
...
}

return nil, err
}
cmd.Stdout = stdout

Copy link
Contributor

Choose a reason for hiding this comment

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

the logic for stdout are same in two branches here. So I think we can move the logic of stdout out of the if-else here.

It will looks like:

if stdout, err := os.Create(filepath.Join(dir, "stdout")); err != nil {
     cmd.Stdout = stdout
}
if isBinaryMode() {
     cmd.Stderr = ....
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to keep the code in the if-else block so I can write comments for it, especially to make the comment match the one in the stderr.

Comment on lines +339 to +342
waitTimeEnv, _ := time.ParseDuration(os.Getenv("TEST_ENVOY_WAIT_BINARY_TO_START_TIME"))
if waitTimeEnv != 0 {
waitTime = waitTimeEnv
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
waitTimeEnv, _ := time.ParseDuration(os.Getenv("TEST_ENVOY_WAIT_BINARY_TO_START_TIME"))
if waitTimeEnv != 0 {
waitTime = waitTimeEnv
}
if waitTimeEnv, err := time.ParseDuration(os.Getenv("TEST_ENVOY_WAIT_BINARY_TO_START_TIME")); err != nil && waitTimeEnv != 0 {
waitTime = waitTimeEnv
}

dp.cmd.Process.Signal(syscall.SIGTERM)
} else {
cmd := exec.Command("docker", "stop", containerName)
err = cmd.Run()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we can check err here immediately, another branch will not return an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is too trivial to change. If we add the err next time, we have to move the err check out again.

@zll600
Copy link
Contributor

zll600 commented Nov 28, 2024

If my points have mistakes, feel free to correct me.

@spacewander spacewander merged commit 855823f into main Nov 29, 2024
20 checks passed
@spacewander spacewander deleted the aci_run_intt branch November 29, 2024 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants