github.com/dkerwin/nomad@v0.3.3-0.20160525181927-74554135514b/client/fingerprint/cgroup.go (about) 1 package fingerprint 2 3 import ( 4 "log" 5 "time" 6 7 "github.com/hashicorp/nomad/nomad/structs" 8 ) 9 10 const ( 11 cgroupAvailable = "available" 12 cgroupUnavailable = "unavailable" 13 interval = 15 14 ) 15 16 type CGroupFingerprint struct { 17 logger *log.Logger 18 lastState string 19 mountPointDetector MountPointDetector 20 } 21 22 // An interface to isolate calls to the cgroup library 23 // This facilitates testing where we can implement 24 // fake mount points to test various code paths 25 type MountPointDetector interface { 26 MountPoint() (string, error) 27 } 28 29 // Implements the interface detector which calls the cgroups library directly 30 type DefaultMountPointDetector struct { 31 } 32 33 // Call out to the default cgroup library 34 func (b *DefaultMountPointDetector) MountPoint() (string, error) { 35 return FindCgroupMountpointDir() 36 } 37 38 // NewCGroupFingerprint returns a new cgroup fingerprinter 39 func NewCGroupFingerprint(logger *log.Logger) Fingerprint { 40 f := &CGroupFingerprint{ 41 logger: logger, 42 lastState: cgroupUnavailable, 43 mountPointDetector: &DefaultMountPointDetector{}, 44 } 45 return f 46 } 47 48 // clearCGroupAttributes clears any node attributes related to cgroups that might 49 // have been set in a previous fingerprint run. 50 func (f *CGroupFingerprint) clearCGroupAttributes(n *structs.Node) { 51 delete(n.Attributes, "unique.cgroup.mountpoint") 52 } 53 54 // Periodic determines the interval at which the periodic fingerprinter will run. 55 func (f *CGroupFingerprint) Periodic() (bool, time.Duration) { 56 return true, interval * time.Second 57 }