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

[feat] add port for client status #311

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Conversation

montaguelhz
Copy link
Contributor

@montaguelhz montaguelhz commented Sep 16, 2023

Get Client Status: [OK]

Id            Kind     Host         Container Id  Status      Port  Aux Info
--            ----     ----         ------------  ------      ----  --------
2ae7016a1160  curvebs  client-host  8b484fb2ed8a  Up 2 weeks  9002  {"user":"curve","volume":"/test2"}
15ea0603042d  curvebs  server-host  0af4ecea35b7  Up 2 weeks  9001  {"user":"curve","volume":"/test1"}

@montaguelhz
Copy link
Contributor Author

@Wine93 @caoxianfei1 PTAL~

t.AddStep(&step.ListContainers{
ShowAll: true,
Format: `"{{.Status}}"`,
Filter: fmt.Sprintf("id=%s", containerId),
Out: &status,
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step2Port{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe step2GetPort is more meaningful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@Wine93 Wine93 left a comment

Choose a reason for hiding this comment

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

LGTM!

@Cyber-SiKu
Copy link
Collaborator

Cyber-SiKu commented Oct 8, 2023

show ip:port is better?just look like:

Get Client Status: [OK]

Id            Kind     Host         Container Id  Status      Adrress                 Aux Info
--            ----     ----         ------------  ------                                                       ----  --------
2ae7016a1160  curvebs  client-host  8b484fb2ed8a  Up 2 weeks  xxx.xxx.xxx.xxx:9002  {"user":"curve","volume":"/test2"}
15ea0603042d  curvebs  server-host  0af4ecea35b7  Up 2 weeks  xxx.xxx.xxx.xxx:9001  {"user":"curve","volume":"/test1"}

@Wine93
Or --detail (-vv) to display more information

@montaguelhz
Copy link
Contributor Author

show ip:port is better?just look like:

Get Client Status: [OK]

Id            Kind     Host         Container Id  Status      Adrress                 Aux Info
--            ----     ----         ------------  ------                                                       ----  --------
2ae7016a1160  curvebs  client-host  8b484fb2ed8a  Up 2 weeks  xxx.xxx.xxx.xxx:9002  {"user":"curve","volume":"/test2"}
15ea0603042d  curvebs  server-host  0af4ecea35b7  Up 2 weeks  xxx.xxx.xxx.xxx:9001  {"user":"curve","volume":"/test1"}

@Wine93 Or --detail (-vv) to display more information

done

@caoxianfei1
Copy link
Contributor

@montaguelhz Have you passed the test

@montaguelhz
Copy link
Contributor Author

@montaguelhz Have you passed the test

The six ci tests are passed.

@caoxianfei1
Copy link
Contributor

@montaguelhz Have you passed the test

The six ci tests are passed.

I test it but address part is nil.

cmd := ctx.Module().DockerCli().TopContainer(s.containerId)
out, err := cmd.Execute(s.execOptions)
if err != nil {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return err?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx, I haven't tested the situation that top command goes wrong, but why it throw error

Copy link
Contributor

Choose a reason for hiding this comment

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

I don‘t know why commmand error, but
if err != nil {
return err
}
we should throw the error?

Comment on lines +118 to +122
if len(pid) == 0 {
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a error occur? handle it.

Comment on lines 133 to 137
if err != nil {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto.


// execute "ss" command in container
cli := ctx.Module().Shell().SocketStatistics("")
cli.AddOption("--no-header")
Copy link
Contributor

Choose a reason for hiding this comment

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

see #295

@montaguelhz
Copy link
Contributor Author

@caoxianfei1 The cause of the problem is that I executed ss in the terminal and it showed 0.0.0.0:9001, but in curveadm it showed *:9001, so I added this to the regular expression and error handling has been added too.

@montaguelhz
Copy link
Contributor Author

The result is
Id Kind Host Container Id Status Address Aux Info


2ae7016a1160 curvebs client-host 8b484fb2ed8a Up 2 months *:9002 {"user":"curve","volume":"/test2"}
15ea0603042d curvebs server-host 0af4ecea35b7 Up 2 months *:9001 {"user":"curve","volume":"/test1"}

@montaguelhz
Copy link
Contributor Author

@caoxianfei1 PTAL~

Comment on lines 154 to 163
func (s *step2GetAddress) extractAddress(line, pid string) string {

regex, err := regexp.Compile(`^.* ((\d+\.\d+\.\d+\.\d+)|\*:\d+).*pid=` + pid + ".*$")
if err == nil {
mu := regex.FindStringSubmatch(line)
if len(mu) > 1 {
return mu[1]
}
}
return ""
}
Copy link
Contributor

Choose a reason for hiding this comment

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

newer version ss command will answer RTNETLINK answers: Invalid argument. See the pr 5adc604

@caoxianfei1 caoxianfei1 merged commit 98d64d0 into opencurve:tombstone Dec 18, 2023
1 check passed
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.

4 participants