github.com/smithx10/nomad@v0.9.1-rc1/client/fingerprint/cgroup.go (about)

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