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

Get the client source docker socket path dynamically #219

Merged
merged 0 commits into from
Aug 12, 2022

Conversation

Vr00mm
Copy link

@Vr00mm Vr00mm commented Apr 27, 2022

Hello,

Here is a fix proposal.

Cause you are using "client" as variable name, you had to ovewrite the docker client lib as dockerapi.
Cause dockerapi.NewClientWithOpts return client.Client object, we cant use method and field on this object.

The simpliest way I found to get the object field value is to use "unsafe" to catch the unreferenced field in a "reflect" object of the client.Client

The communication look working with the socket now.

Fix #218
Signed-off-by: Remi Ziolkowski remi.ziolkowski-ext@pole-emploi.fr

Copy link
Owner

@alexei-led alexei-led 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 contributing the PR

  • please keep format intact (run make lint)
  • avoid using reflection; prefer explicit parameter

@@ -11,6 +11,8 @@ import (
"strings"
"time"

"unsafe"
Copy link
Owner

Choose a reason for hiding this comment

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

Please format code with goimports and run make lint to check if it properly formatted

@@ -652,6 +654,11 @@ func (client dockerClient) tcContainerCommand(ctx context.Context, target *Conta
return nil
}


func GetUnexportedField(field reflect.Value) string {
Copy link
Owner

Choose a reason for hiding this comment

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

Please, do not use reflection to expose the internal field.
Consider doing this explicitly.

  • Add a new host-socket parameter to the stress command (NewStressCLICommand)
  • Default to /var/run/docker.sock
  • Pass it to the stressContainerCommand function

@@ -652,6 +654,11 @@ func (client dockerClient) tcContainerCommand(ctx context.Context, target *Conta
return nil
}


func GetUnexportedField(field reflect.Value) string {
Copy link
Owner

Choose a reason for hiding this comment

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

Please, do not use reflection to expose the internal field.
Consider doing this explicitly.

  • Add a new host-socket parameter to the stress command (NewStressCLICommand)
  • Default to /var/run/docker.sock
  • Pass it to the stressContainerCommand function

Copy link
Author

@Vr00mm Vr00mm Aug 24, 2022

Choose a reason for hiding this comment

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

Hello @alexei-led, it seem adding new parameter break this function:

func getNamesOrPattern(c *cli.Context) ([]string, string) {

How can I deal with ?

Copy link
Author

Choose a reason for hiding this comment

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

I added the parameter:

# ./pumba stress --help

NAME:
   pumba stress - stress test a specified containers

USAGE:
   pumba stress [command options] containers (name, list of names, or RE2 regex if prefixed with "re2:")

DESCRIPTION:
   stress test target container(s)

OPTIONS:
   --duration value, -d value  stress duration: must be shorter than recurrent interval; use with optional unit suffix: 'ms/s/m/h'
   --stress-image value        Docker image with stress-ng tool, cgroup-bin and docker packages, and dockhack script (default: "alexeiled/stress-ng:latest-ubuntu")
   --pull-image                pull stress-image form Docker registry
   --stressors value           stress-ng stressors; see https://kernel.ubuntu.com/~cking/stress-ng/ (default: "--cpu 4 --timeout 60s")
   --host-socket value         daemon socket to connect to (default: "/var/run/docker.sock") [$DOCKER_HOST]

If I use the parameter, I get this output:

# ./pumba --log-level debug --label test=chaos stress --duration 60s --stress-image chaos/pumba:0.2.0 --stressors "--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s" --host-socket /var/run/docker.sock

DEBU[0000] using names                                   names="[/var/run/docker.sock --cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
DEBU[0000] stress testing all matching containers       
DEBU[0000] listing matching containers                   duration=1m0s labels="[test=chaos]" limit=0 names="[/var/run/docker.sock --cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]" pattern= random=false stressors="[--host-socket]"
DEBU[0000] listing containers                           
DEBU[0000] found container                               id=2618ac158889440c4b0764c55cb5ffb69dd650f1aa870ea99bc2fb5b95652b1e name=/keen_heyrovsky
WARN[0000] no containers to stress test

If I remove the flag, its seem work:

# ./pumba --log-level debug --label test=chaos stress --duration 60s --stress-image chaos/pumba:0.2.0 --stressors "--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s"

DEBU[0000] stress testing all matching containers       
DEBU[0000] listing matching containers                   duration=1m0s labels="[test=chaos]" limit=0 names="[]" pattern= random=false stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
DEBU[0000] listing containers                           
DEBU[0000] found container                               id=2618ac158889440c4b0764c55cb5ffb69dd650f1aa870ea99bc2fb5b95652b1e name=/keen_heyrovsky
DEBU[0000] stress testing container for duration         container=2618ac158889440c4b0764c55cb5ffb69dd650f1aa870ea99bc2fb5b95652b1e duration=1m0s pull image=true stress-ng image="chaos/pumba:0.2.0" stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
INFO[0000] stress testing container                      dryrun=false duration=1m0s id=2618ac158889440c4b0764c55cb5ffb69dd650f1aa870ea99bc2fb5b95652b1e image="chaos/pumba:0.2.0" name=/keen_heyrovsky pull=true stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
DEBU[0000] executing stress-ng command                   image="chaos/pumba:0.2.0" pull=true stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]" target=2618ac158889440c4b0764c55cb5ffb69dd650f1aa870ea99bc2fb5b95652b1e
DEBU[0000] pulling stress-ng image                       image="chaos/pumba:0.2.0"
DEBU[0000] &{Pulling from chaos/pumba   {0 0}}          
DEBU[0000] &{Digest: sha256:6b0150ed9a2a75539b6dd8cdd48d65e32fd124eb257919ef5f9bf3d0a820a59a   {0 0}} 
DEBU[0000] &{Status: Image is up to date for chaos/pumba:0.2.0   {0 0}} 
DEBU[0000] creating stress-ng container                  image="chaos/pumba:0.2.0"
DEBU[0000] stress-ng container created, starting it      id=f5d9e6c5cd67e2da457c52cce901ecf821517409507e95ec62f4678026708ce2

Copy link
Author

Choose a reason for hiding this comment

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

Well, switch parameter order seem make it work...

No --host-socket parameter -> bind source path does not exist: /var/run/docker.sock

# ./pumba \
    --host unix:///var/run/docker-test.sock \
    --log-level debug \
    --label test=chaos \ 
 stress \
     --duration 60s \
     --stress-image chaos/pumba:0.2.0 \
     --stressors "--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s"

DEBU[0000] stress testing all matching containers       
DEBU[0000] listing matching containers                   duration=1m0s labels="[test=chaos]" limit=0 names="[]" pattern= random=false stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
DEBU[0000] listing containers                           
DEBU[0000] found container                               id=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d name=/determined_moore
DEBU[0000] stress testing container for duration         container=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d duration=1m0s pull image=true stress-ng image="chaos/pumba:0.2.0" stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
INFO[0000] stress testing container                      dryrun=false duration=1m0s id=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d image="chaos/pumba:0.2.0" name=/determined_moore pull=true stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
DEBU[0000] executing stress-ng command                   image="chaos/pumba:0.2.0" pull=true stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]" target=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d
DEBU[0000] pulling stress-ng image                       image="chaos/pumba:0.2.0"
DEBU[0000] &{Pulling from chaos/pumba   {0 0}}          
DEBU[0000] &{Digest: sha256:6b0150ed9a2a75539b6dd8cdd48d65e32fd124eb257919ef5f9bf3d0a820a59a   {0 0}} 
DEBU[0000] &{Status: Image is up to date for chaos/pumba:0.2.0   {0 0}} 
DEBU[0000] creating stress-ng container                  image="chaos/pumba:0.2.0"
FATA[0000] error running stress command: error running chaos command: one or more stress test failed: stress test failed: failed to create stress-ng container: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /var/run/docker.sock 

Using --host-socket as last parameter -> no containers to stress test

# ./pumba \
    --host unix:///var/run/docker-test.sock \
    --log-level debug \
    --label test=chaos \ 
 stress \
     --duration 60s \
     --stress-image chaos/pumba:0.2.0 \
     --stressors "--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s" \
     --host-socket /var/run/docker-test.sock
     
DEBU[0000] using names                                   names="[/var/run/docker.sock --cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
DEBU[0000] stress testing all matching containers       
DEBU[0000] listing matching containers                   duration=1m0s labels="[test=chaos]" limit=0 names="[/var/run/docker.sock --cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]" pattern= random=false stressors="[--host-socket]"
DEBU[0000] listing containers                           
DEBU[0000] found container                               id=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d name=/determined_moore
WARN[0000] no containers to stress test 

Using --host-socket as third parameter -> it work
(I dont have dockhack installed on my computer)

# ./pumba \
    --host unix:///var/run/docker-test.sock \
    --log-level debug \
    --label test=chaos \ 
 stress \
     --duration 60s \
     --stress-image chaos/pumba:0.2.0 \
     --host-socket /var/run/docker-test.sock \
     --stressors "--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s"
     
DEBU[0000] stress testing all matching containers       
DEBU[0000] listing matching containers                   duration=1m0s labels="[test=chaos]" limit=0 names="[]" pattern= random=false stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
DEBU[0000] listing containers                           
DEBU[0000] found container                               id=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d name=/determined_moore
DEBU[0000] stress testing container for duration         container=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d duration=1m0s pull image=true stress-ng image="chaos/pumba:0.2.0" stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
INFO[0000] stress testing container                      dryrun=false duration=1m0s id=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d image="chaos/pumba:0.2.0" name=/determined_moore pull=true stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]"
DEBU[0000] executing stress-ng command                   image="chaos/pumba:0.2.0" pull=true stressors="[--cpu 1 --vm 1 --vm-bytes 500M --timeout 30s]" target=fdefca0776411b2561cb33a27d9d4088270a75cb085682328102f2decb86c35d
DEBU[0000] pulling stress-ng image                       image="chaos/pumba:0.2.0"
DEBU[0000] &{Pulling from chaos/pumba   {0 0}}          
DEBU[0000] &{Digest: sha256:6b0150ed9a2a75539b6dd8cdd48d65e32fd124eb257919ef5f9bf3d0a820a59a   {0 0}} 
DEBU[0000] &{Status: Image is up to date for chaos/pumba:0.2.0   {0 0}} 
DEBU[0000] creating stress-ng container                  image="chaos/pumba:0.2.0"
DEBU[0000] stress-ng container created, starting it      id=f5454b4d71e4082520814e66d364315bba60066d81036df1c6f0e66afe4153bd
FATA[0000] error running stress command: error running chaos command: one or more stress test failed: stress test failed: failed to start stress-ng container: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "dockhack": executable file not found in $PATH: unknown 

This is kinda dirty...

@@ -674,7 +681,7 @@ func (client dockerClient) stressContainerCommand(ctx context.Context, targetID
// docker socket mount
dockerSocket := mount.Mount{
Type: mount.TypeBind,
Source: "/var/run/docker.sock",
Source: GetUnexportedField(reflect.ValueOf(client.containerAPI).Elem().FieldByName("addr")),
Copy link
Owner

Choose a reason for hiding this comment

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

no reflection, please

@@ -674,7 +681,7 @@ func (client dockerClient) stressContainerCommand(ctx context.Context, targetID
// docker socket mount
dockerSocket := mount.Mount{
Type: mount.TypeBind,
Source: "/var/run/docker.sock",
Source: GetUnexportedField(reflect.ValueOf(client.containerAPI).Elem().FieldByName("addr")),
Copy link
Owner

Choose a reason for hiding this comment

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

no reflection, please

@Vr00mm Vr00mm merged commit cd6983d into alexei-led:master Aug 12, 2022
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.

IO-Stress: bind source path does not exist
2 participants