From 3202200ccb1bfc5cfee29b359df7c92fda1d3ed8 Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Thu, 1 Feb 2018 18:38:23 -0500 Subject: [PATCH] req/resp should be within config locks; rename for detected fingerprints changelog --- CHANGELOG.md | 2 ++ client/client.go | 18 +++++++++--------- client/driver/mock_driver.go | 1 - client/structs/structs.go | 4 ++++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f17f868b158a..3849a773707c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)] diff --git a/client/client.go b/client/client.go index 0d749ffe1084..17737d39fac1 100644 --- a/client/client.go +++ b/client/client.go @@ -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. @@ -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 { @@ -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 @@ -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) } @@ -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() @@ -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 { @@ -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 { @@ -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) @@ -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) } diff --git a/client/driver/mock_driver.go b/client/driver/mock_driver.go index 4c7085533b71..15cc56b5b415 100644 --- a/client/driver/mock_driver.go +++ b/client/driver/mock_driver.go @@ -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 diff --git a/client/structs/structs.go b/client/structs/structs.go index 9348acfb67f4..97887232de04 100644 --- a/client/structs/structs.go +++ b/client/structs/structs.go @@ -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