github.com/anuvu/nomad@v0.8.7-atom1/client/fingerprint/cgroup.go (about)

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