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

Fix self metrix when containerised #6620 #6641

Merged
merged 1 commit into from
Mar 27, 2018
Merged

Fix self metrix when containerised #6620 #6641

merged 1 commit into from
Mar 27, 2018

Conversation

ewgRa
Copy link
Contributor

@ewgRa ewgRa commented Mar 22, 2018

This is a fix for #6620.

Probably it is a little bit dirty solution, but on other hand there is big refactoring of gosigar and there is a big question about later upstream merging.

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@@ -59,6 +65,10 @@ type Stats struct {
envRegexps []match.Matcher // List of regular expressions used to whitelist env vars.
}

type LocalStats struct {

Choose a reason for hiding this comment

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

exported type LocalStats should have comment or be unexported

@@ -19,6 +19,12 @@ import (
sigar "github.com/elastic/gosigar"
)

var InitSigarProcd string

Choose a reason for hiding this comment

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

exported var InitSigarProcd should have comment or be unexported


func (procStats *LocalStats) preGetOne() {
curSigarProcd = sigar.Procd
sigar.Procd = InitSigarProcd
Copy link
Member

Choose a reason for hiding this comment

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

Solving it this way would probably require a locking mechanism in gosigar, as this value is global and there can be other goroutines using it at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this PR will be accepted in general, I think it can be done without big changes of gosigar.


import "os"

func GetSelfPid() (int, error) {

Choose a reason for hiding this comment

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

exported function GetSelfPid should have comment or be unexported

"strings"
)

func GetSelfPid() (int, error) {

Choose a reason for hiding this comment

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

exported function GetSelfPid should have comment or be unexported

"github.com/elastic/gosigar"
)

func GetSelfPid() (int, error) {

Choose a reason for hiding this comment

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

exported function GetSelfPid should have comment or be unexported


// GetSelfPid return self pid for current running process
func GetSelfPid() (int, error) {
contents, err := ioutil.ReadFile(gosigar.Procd + "/self/stat")
Copy link
Member

Choose a reason for hiding this comment

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

I was just thinking that it could be enough with os.Readlink(gosigar.Procd + "/self"), then no more parsing would be needed. Could you try? Thanks!


// GetSelfPid return self pid for current running process
func GetSelfPid() (int, error) {
contents, err := ioutil.ReadFile(gosigar.Procd + "/self/stat")
Copy link
Member

Choose a reason for hiding this comment

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

Btw, to join paths it'd be better to use path.Join.

@@ -0,0 +1,28 @@
package process
Copy link
Member

Choose a reason for hiding this comment

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

// +build linux

Copy link
Member

Choose a reason for hiding this comment

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

Oh, this won't be needed as the file has the _linux suffix.

@@ -0,0 +1,10 @@
// +build darwin freebsd windows
Copy link
Member

Choose a reason for hiding this comment

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

// +build !linux

@ewgRa
Copy link
Contributor Author

ewgRa commented Mar 25, 2018

@jsoriano thanks for review. Agree with everything and already made changes. ReadLink works. Check please.

Only requested "// +build linux" for _linux file make no sense, as you already mention.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

It mostly LGTM, please take a look to my comments about error messages. Could you also squash your commits before merging? Thanks!

state, err := beatProcessStats.GetOne(beatPID)
pid, err := process.GetSelfPid()
if err != nil {
return 0, fmt.Errorf("error retrieving process stats: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Rewrite to more specific message?

state, err := beatProcessStats.GetOne(beatPID)
pid, err := process.GetSelfPid()
if err != nil {
return 0.0, nil, fmt.Errorf("error retrieving process stats: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@jsoriano jsoriano requested a review from andrewkroh March 26, 2018 11:36
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM. Just a few nits.

import (
"os"
"strconv"

Copy link
Member

Choose a reason for hiding this comment

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

This newline could be dropped to group all stdlib imports together.

"github.com/elastic/gosigar"
)

// GetSelfPid return self pid for current running process
Copy link
Member

Choose a reason for hiding this comment

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

How about "GetSelfPid returns the PID for this process."

@jsoriano
Copy link
Member

jenkins, test this please

@ewgRa
Copy link
Contributor Author

ewgRa commented Mar 26, 2018

@jsoriano I squash it and change error to more specific, but a little bit surprised, since github allow to do that. Or just to simplify commit message?

@andrewkroh done group of stdlib imports and doc for function (but I did it without dot at the end, since docs everywhere without dots at the end).

Thanks for review, so small diff at the end, but so much effort.

@jsoriano
Copy link
Member

@ewgRa thanks for taking care of this!

Yes, I asked you to squash it to have a simpler message, and also a message that you chose as author of the changes :)

@jsoriano
Copy link
Member

Failing test doesn't seem related, merging this.

jsoriano added a commit to jsoriano/beats that referenced this pull request Sep 4, 2018
jsoriano added a commit that referenced this pull request Sep 5, 2018
jsoriano added a commit to jsoriano/beats that referenced this pull request Sep 5, 2018
jsoriano added a commit to jsoriano/beats that referenced this pull request Sep 5, 2018
jsoriano added a commit to jsoriano/beats that referenced this pull request Sep 5, 2018
jsoriano added a commit that referenced this pull request Sep 5, 2018
jsoriano added a commit that referenced this pull request Sep 5, 2018
jsoriano added a commit that referenced this pull request Sep 5, 2018
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
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.

6 participants