Skip to content

Commit

Permalink
req/resp should be within config locks; rename for detected fingerprints
Browse files Browse the repository at this point in the history
changelog
  • Loading branch information
chelseakomlo committed Feb 2, 2018
1 parent 15cb768 commit 3202200
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ __BACKWARDS INCOMPATIBILITIES:__
IMPROVEMENTS:
* core: A set of features (Autopilot) has been added to allow for automatic operator-friendly management of Nomad servers. For more information about Autopilot, see the [Autopilot Guide](https://www.nomadproject.io/guides/cluster/autopilot.html). [[GH-3670](https://github.com/hashicorp/nomad/pull/3670)]
* client: Allow '.' in environment variable names [[GH-3760](https://github.com/hashicorp/nomad/issues/3760)]
* client: Refactor client fingerprint methods to a request/response format
[[GH-3781](https://github.com/hashicorp/nomad/issues/3781)]
* discovery: Allow `check_restart` to be specified in the `service` stanza.
[[GH-3718](https://github.com/hashicorp/nomad/issues/3718)]
* driver/docker; Support overriding image entrypoint [[GH-3788](https://github.com/hashicorp/nomad/issues/3788)]
Expand Down
18 changes: 9 additions & 9 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ func (c *Client) fingerprint() error {

c.logger.Printf("[DEBUG] client: built-in fingerprints: %v", fingerprint.BuiltinFingerprints())

var appliedFingerprints []string
var detectedFingerprints []string
var skippedFingerprints []string
for _, name := range fingerprint.BuiltinFingerprints() {
// Skip modules that are not in the whitelist if it is enabled.
Expand All @@ -951,9 +951,9 @@ func (c *Client) fingerprint() error {
return err
}

c.configLock.Lock()
request := &cstructs.FingerprintRequest{Config: c.config, Node: c.config.Node}
var response cstructs.FingerprintResponse
c.configLock.Lock()
err = f.Fingerprint(request, &response)
c.configLock.Unlock()
if err != nil {
Expand All @@ -962,7 +962,7 @@ func (c *Client) fingerprint() error {

// log the fingerprinters which have been applied
if response.Detected {
appliedFingerprints = append(appliedFingerprints, name)
detectedFingerprints = append(detectedFingerprints, name)
}

// add the diff found from each fingerprinter
Expand All @@ -977,7 +977,7 @@ func (c *Client) fingerprint() error {
}
}

c.logger.Printf("[DEBUG] client: applied fingerprints %v", appliedFingerprints)
c.logger.Printf("[DEBUG] client: detected fingerprints %v", detectedFingerprints)
if len(skippedFingerprints) != 0 {
c.logger.Printf("[DEBUG] client: fingerprint modules skipped due to white/blacklist: %v", skippedFingerprints)
}
Expand All @@ -990,9 +990,9 @@ func (c *Client) fingerprintPeriodic(name string, f fingerprint.Fingerprint, d t
for {
select {
case <-time.After(d):
c.configLock.Lock()
request := &cstructs.FingerprintRequest{Config: c.config, Node: c.config.Node}
var response cstructs.FingerprintResponse
c.configLock.Lock()
err := f.Fingerprint(request, &response)
c.configLock.Unlock()

Expand All @@ -1015,7 +1015,7 @@ func (c *Client) setupDrivers() error {
whitelistEnabled := len(whitelist) > 0
blacklist := c.config.ReadStringListToMap("driver.blacklist")

var availDrivers []string
var detectedDrivers []string
var skippedDrivers []string
driverCtx := driver.NewDriverContext("", "", c.config, c.config.Node, c.logger, nil)
for name := range driver.BuiltinDrivers {
Expand All @@ -1036,9 +1036,9 @@ func (c *Client) setupDrivers() error {
return err
}

c.configLock.Lock()
request := &cstructs.FingerprintRequest{Config: c.config, Node: c.config.Node}
var response cstructs.FingerprintResponse
c.configLock.Lock()
err = d.Fingerprint(request, &response)
c.configLock.Unlock()
if err != nil {
Expand All @@ -1047,7 +1047,7 @@ func (c *Client) setupDrivers() error {

// log the fingerprinters which have been applied
if response.Detected {
availDrivers = append(availDrivers, name)
detectedDrivers = append(detectedDrivers, name)
}

c.updateNodeFromFingerprint(&response)
Expand All @@ -1059,7 +1059,7 @@ func (c *Client) setupDrivers() error {

}

c.logger.Printf("[DEBUG] client: available drivers %v", availDrivers)
c.logger.Printf("[DEBUG] client: available drivers %v", detectedDrivers)
if len(skippedDrivers) > 0 {
c.logger.Printf("[DEBUG] client: drivers skipped due to white/blacklist: %v", skippedDrivers)
}
Expand Down
1 change: 0 additions & 1 deletion client/driver/mock_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
)

const (

// ShutdownPeriodicAfter is a config key that can be used during tests to
// "stop" a previously-functioning driver, allowing for testing of periodic
// drivers and fingerprinters
Expand Down
4 changes: 4 additions & 0 deletions client/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,15 @@ func (d *DriverNetwork) Hash() []byte {
return h.Sum(nil)
}

// FingerprintRequest is a request which a fingerprinter accepts to fingerprint
// the node
type FingerprintRequest struct {
Config *config.Config
Node *structs.Node
}

// FingerprintResponse is the response which a fingerprinter annotates with the
// results of the fingerprint method
type FingerprintResponse struct {
Attributes map[string]string
Links map[string]string
Expand Down

0 comments on commit 3202200

Please sign in to comment.