Skip to content

Db/system both rebase#351

Merged
derekwbrown merged 39 commits intomasterfrom
db/system-both-rebase
Jul 12, 2017
Merged

Db/system both rebase#351
derekwbrown merged 39 commits intomasterfrom
db/system-both-rebase

Conversation

@derekwbrown
Copy link
Copy Markdown
Contributor

What does this PR do?

Implements the IO/disk check for windows. This version uses WMI, to match agent5. Have an eventual PR that uses PDH.

Moves platform specific code to conditionally compiled rather than runtime evaluation.

Note that this does NOT detect insertion of drives, at least as tested. Is same behavior as agent5.

(Tested using virtualbox, and using Disk Manager to mount & unmount drives).

truthbk and others added 30 commits May 24, 2017 14:54
@derekwbrown derekwbrown force-pushed the db/system-both-rebase branch 3 times, most recently from fe36c70 to c7b4989 Compare June 27, 2017 04:31
@derekwbrown derekwbrown force-pushed the db/system-both-rebase branch from c7b4989 to b58e66c Compare June 29, 2017 16:20
Copy link
Copy Markdown
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

This looks absolutely fine overall. Left a few comments/questions, small things that might make it a little more idiomatic or nitpicks. Also left a couple of notes to myself - as this PR is a bit of a joint effort..

Comment thread pkg/config/config.go Outdated
Datadog.SetDefault("check_runners", int64(4))
Datadog.SetDefault("forwarder_timeout", 20)
// Dogstatsd
Datadog.SetDefault("device_blacklist_re", "")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We decided device_blacklist_re was meant to be a check level (init_conf as I implemented it) configuration element. So we should remove it from here.

Comment thread rake/agent.rb
if !ENV["USE_SYSTEM_PY"]
env["PKG_CONFIG_LIBDIR"] = "#{PKG_CONFIG_LIBDIR}"
libdir = `PKG_CONFIG_LIBDIR="#{PKG_CONFIG_LIBDIR}" pkg-config --variable=libdir python-2.7`.strip
ENV["PKG_CONFIG_LIBDIR"] = "#{PKG_CONFIG_LIBDIR}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need to add PKG_CONFIG_LIBDIR to the global environment? I take it prepending the environment variable won't work on windows...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, it doesn't work on windows. This solution is definitely sub-optimal, and I'd be open to anything else, but the existing rakefile won't build on windows.

core.RegisterCheck("iowin", wmiioFactory)
}

func wmiioFactory() check.Check {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: should probably be wmiIoFactory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need two different factories? They both do the same thing:

func ioFactory() check.Check {
    c := &IOCheck{}
    return c
}

Similarly, I think we can probably have a single init block for the two implementations (and leave the initialization of hz in its own separate init block):

init() {
    core.RegisterCheck("io", ioFactory)
}

}

func init() {
core.RegisterCheck("iowin", wmiioFactory)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: the check can probably be called io - not sure we need to differentiate between platforms in the check name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. This is supposed to be "io". But, I have an associated problem on windows which is that when I call it "io", it fails to load, because the python loader fails loading the module "io"; this was supposed to be a temporary workaround. Will fix it.

return err
}

blacklistRe := config.Datadog.GetString("device_blacklist_re")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As mentioned in pkg/config we decided to not have this as a global configuration element, so you can probably remove this entire block. We already initialize the regexp expression in commonConfigure().


drivebuf := make([]byte, 256)

r, _, err := ProcGetLogicalDriveStringsW.Call(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

}
for _, v := range drivebuf {
// between 'A' & 'Z'
if v >= 65 && v <= 90 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any scenario on windows where the drive would not be a single letter? Network drives, for instance? Maybe something like this might be safer?

drives := bytes.Split(drivebuff, []byte{0})
	
for _, v := range drives {
        drive := string(v)

	// do whatever we need to do with the drive string. 
} 

tagbuff.WriteString("device:")
tagbuff.WriteString(drive)
tags := []string{tagbuff.String()}
if len(c.drivemap[d.Name].Name) != 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we just checking if the value was already in the drivemap? The more idiomatic way of doing this would be:

if prev, ok := m["route"]; ok {
     metrics, err := computeValue(prev, &d)
}

err := c.commonConfigure(data, initConfig)
return err
}
func (c *IOCheck) nixIO() error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note to self (and totally on me): We may be assuming way too many things about how this will work out on Darwin...

}

// Run executes the check
func (c *IOCheck) Run() error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although right now this it's probably unnecessary to have Run() just call nixIO(), it might actually come in handy in case we need to do different things for Darwin or other GOOS variants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My intent was, once we get to doing darwin, it should be split out at compile time (the way I did with windows), not at runtime. That's more a preference thing, though one we probably ought to standardize on one way or the other.

derekwbrown and others added 3 commits July 5, 2017 14:26
* adds upstart file to centos6

* adds upstart file to rpm

* changes conditional

* enables alternative python
Copy link
Copy Markdown
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

Logic looks good to me. There's a few things I commented on, but I'll let you decide if/when you want to address those.

Comment thread .gitlab-ci.yml

variables:
DOCKER_REGISTRY: gitlab.datad0g.com:4567
DOCKER_REGISTRY: 727006795293.dkr.ecr.us-east-1.amazonaws.com
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this be a problem once the repo goes public? Or is it only accessible from within a VPC or whatever?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I took this from master, to get it to pass ci: https://github.com/DataDog/datadog-agent/blob/master/.gitlab-ci.yml#L9. TBH, I'm not sure of the impact

# Linux
if linux?
if debian?
if debian? || redhat?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we don't do anything different for redhat vs debian we can maybe remove this if? Or are you accounting here for SuSE?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is also on master; I had to pull in this change to get CI to function
2a22841#diff-6510f031d77235eab2fc2392e0be89abR110


if debian?
mkdir "/etc/init/"
if debian? || redhat?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similarly, do we need this if condition, we're doing the same thing for both major distros... Is it because of SuSE?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ditto here (same change as above)

retstrings = append(retstrings, "")
continue
}
retstrings[rsindex] += string(rune(winput[i]))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unfortunately this is the most inefficient way to concatenate strings in go (by far)... This is going to get called pretty often, and although it's going to work on a short list, with short strings - it might be preferable to use a string buffer instead. I'll let you decide if you want to implement this differently.

byte buffer to do the original conversion, rather than appending a
character on to the string for each pass.
byte buffer to do the original conversion, rather than appending a
character on to the string for each pass.
@derekwbrown derekwbrown merged commit 8b10aa1 into master Jul 12, 2017
@masci masci deleted the db/system-both-rebase branch July 26, 2017 16:45
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.

3 participants