mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 19:05:42 +03:00
client uses passed logger and fix fingerprinters
This commit is contained in:
committed by
Michael Schurter
parent
e9f3f2cfee
commit
9a2c2a4f68
@@ -229,7 +229,7 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulServic
|
||||
}
|
||||
|
||||
// Create the logger
|
||||
logger := cfg.Logger.Named("client")
|
||||
logger := cfg.Logger.ResetNamed("client")
|
||||
|
||||
// Create the client
|
||||
c := &Client{
|
||||
@@ -1922,17 +1922,10 @@ func (c *Client) addAlloc(alloc *structs.Allocation, migrateToken string) error
|
||||
// Copy the config since the node can be swapped out as it is being updated.
|
||||
// The long term fix is to pass in the config and node separately and then
|
||||
// we don't have to do a copy.
|
||||
//XXX FIXME create a root logger
|
||||
logger := hclog.New(&hclog.LoggerOptions{
|
||||
Name: "nomad",
|
||||
Level: hclog.LevelFromString(c.configCopy.LogLevel),
|
||||
TimeFormat: time.RFC3339,
|
||||
})
|
||||
|
||||
c.configLock.RLock()
|
||||
arConf := &allocrunnerv2.Config{
|
||||
Alloc: alloc,
|
||||
Logger: logger,
|
||||
Logger: c.logger,
|
||||
ClientConfig: c.config,
|
||||
StateDB: c.stateDB,
|
||||
Consul: c.consulService,
|
||||
|
||||
@@ -650,7 +650,7 @@ func TestClient_Init(t *testing.T) {
|
||||
config: &config.Config{
|
||||
AllocDir: allocDir,
|
||||
},
|
||||
logger: testlog.Logger(t),
|
||||
logger: testlog.HCLogger(t),
|
||||
}
|
||||
if err := client.init(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"log"
|
||||
"runtime"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
)
|
||||
|
||||
// ArchFingerprint is used to fingerprint the architecture
|
||||
type ArchFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewArchFingerprint is used to create an OS fingerprint
|
||||
func NewArchFingerprint(logger *log.Logger) Fingerprint {
|
||||
f := &ArchFingerprint{logger: logger}
|
||||
func NewArchFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &ArchFingerprint{logger: logger.Named("arch")}
|
||||
return f
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestArchFingerprint(t *testing.T) {
|
||||
f := NewArchFingerprint(testlog.Logger(t))
|
||||
f := NewArchFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ const (
|
||||
)
|
||||
|
||||
type CGroupFingerprint struct {
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
lastState string
|
||||
mountPointDetector MountPointDetector
|
||||
}
|
||||
@@ -35,9 +35,9 @@ func (b *DefaultMountPointDetector) MountPoint() (string, error) {
|
||||
}
|
||||
|
||||
// NewCGroupFingerprint returns a new cgroup fingerprinter
|
||||
func NewCGroupFingerprint(logger *log.Logger) Fingerprint {
|
||||
func NewCGroupFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &CGroupFingerprint{
|
||||
logger: logger,
|
||||
logger: logger.Named("cgroup"),
|
||||
lastState: cgroupUnavailable,
|
||||
mountPointDetector: &DefaultMountPointDetector{},
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (f *CGroupFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
f.clearCGroupAttributes(resp)
|
||||
|
||||
if f.lastState == cgroupAvailable {
|
||||
f.logger.Printf("[INFO] fingerprint.cgroups: cgroups are unavailable")
|
||||
f.logger.Info("cgroups are unavailable")
|
||||
}
|
||||
f.lastState = cgroupUnavailable
|
||||
return nil
|
||||
@@ -54,7 +54,7 @@ func (f *CGroupFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
resp.Detected = true
|
||||
|
||||
if f.lastState == cgroupUnavailable {
|
||||
f.logger.Printf("[INFO] fingerprint.cgroups: cgroups are available")
|
||||
f.logger.Info("cgroups are available")
|
||||
}
|
||||
f.lastState = cgroupAvailable
|
||||
return nil
|
||||
|
||||
@@ -2,12 +2,11 @@ package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
consul "github.com/hashicorp/consul/api"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
)
|
||||
|
||||
@@ -18,14 +17,14 @@ const (
|
||||
|
||||
// ConsulFingerprint is used to fingerprint for Consul
|
||||
type ConsulFingerprint struct {
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
client *consul.Client
|
||||
lastState string
|
||||
}
|
||||
|
||||
// NewConsulFingerprint is used to create a Consul fingerprint
|
||||
func NewConsulFingerprint(logger *log.Logger) Fingerprint {
|
||||
return &ConsulFingerprint{logger: logger, lastState: consulUnavailable}
|
||||
func NewConsulFingerprint(logger log.Logger) Fingerprint {
|
||||
return &ConsulFingerprint{logger: logger.Named("consul"), lastState: consulUnavailable}
|
||||
}
|
||||
|
||||
func (f *ConsulFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cstructs.FingerprintResponse) error {
|
||||
@@ -52,7 +51,7 @@ func (f *ConsulFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
// Print a message indicating that the Consul Agent is not available
|
||||
// anymore
|
||||
if f.lastState == consulAvailable {
|
||||
f.logger.Printf("[INFO] fingerprint.consul: consul agent is unavailable")
|
||||
f.logger.Info("consul agent is unavailable")
|
||||
}
|
||||
f.lastState = consulUnavailable
|
||||
return nil
|
||||
@@ -61,27 +60,27 @@ func (f *ConsulFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
if s, ok := info["Config"]["Server"].(bool); ok {
|
||||
resp.AddAttribute("consul.server", strconv.FormatBool(s))
|
||||
} else {
|
||||
f.logger.Printf("[WARN] fingerprint.consul: unable to fingerprint consul.server")
|
||||
f.logger.Warn("unable to fingerprint consul.server")
|
||||
}
|
||||
if v, ok := info["Config"]["Version"].(string); ok {
|
||||
resp.AddAttribute("consul.version", v)
|
||||
} else {
|
||||
f.logger.Printf("[WARN] fingerprint.consul: unable to fingerprint consul.version")
|
||||
f.logger.Warn("unable to fingerprint consul.version")
|
||||
}
|
||||
if r, ok := info["Config"]["Revision"].(string); ok {
|
||||
resp.AddAttribute("consul.revision", r)
|
||||
} else {
|
||||
f.logger.Printf("[WARN] fingerprint.consul: unable to fingerprint consul.revision")
|
||||
f.logger.Warn("unable to fingerprint consul.revision")
|
||||
}
|
||||
if n, ok := info["Config"]["NodeName"].(string); ok {
|
||||
resp.AddAttribute("unique.consul.name", n)
|
||||
} else {
|
||||
f.logger.Printf("[WARN] fingerprint.consul: unable to fingerprint unique.consul.name")
|
||||
f.logger.Warn("unable to fingerprint unique.consul.name")
|
||||
}
|
||||
if d, ok := info["Config"]["Datacenter"].(string); ok {
|
||||
resp.AddAttribute("consul.datacenter", d)
|
||||
} else {
|
||||
f.logger.Printf("[WARN] fingerprint.consul: unable to fingerprint consul.datacenter")
|
||||
f.logger.Warn("unable to fingerprint consul.datacenter")
|
||||
}
|
||||
|
||||
if dc, ok := resp.Attributes["consul.datacenter"]; ok {
|
||||
@@ -89,13 +88,13 @@ func (f *ConsulFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
resp.AddLink("consul", fmt.Sprintf("%s.%s", dc, name))
|
||||
}
|
||||
} else {
|
||||
f.logger.Printf("[WARN] fingerprint.consul: malformed Consul response prevented linking")
|
||||
f.logger.Warn("malformed Consul response prevented linking")
|
||||
}
|
||||
|
||||
// If the Consul Agent was previously unavailable print a message to
|
||||
// indicate the Agent is available now
|
||||
if f.lastState == consulUnavailable {
|
||||
f.logger.Printf("[INFO] fingerprint.consul: consul agent is available")
|
||||
f.logger.Info("consul agent is available")
|
||||
}
|
||||
f.lastState = consulAvailable
|
||||
resp.Detected = true
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func TestConsulFingerprint(t *testing.T) {
|
||||
fp := NewConsulFingerprint(testlog.Logger(t))
|
||||
fp := NewConsulFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -171,7 +171,7 @@ const mockConsulResponse = `
|
||||
// See https://github.com/hashicorp/nomad/issues/3326
|
||||
func TestConsulFingerprint_UnexpectedResponse(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
fp := NewConsulFingerprint(testlog.Logger(t))
|
||||
fp := NewConsulFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/helper/stats"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
// CPUFingerprint is used to fingerprint the CPU
|
||||
type CPUFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewCPUFingerprint is used to create a CPU fingerprint
|
||||
func NewCPUFingerprint(logger *log.Logger) Fingerprint {
|
||||
f := &CPUFingerprint{logger: logger}
|
||||
func NewCPUFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &CPUFingerprint{logger: logger.Named("cpu")}
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func (f *CPUFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cst
|
||||
}
|
||||
|
||||
if err := stats.Init(); err != nil {
|
||||
f.logger.Printf("[WARN] fingerprint.cpu: %v", err)
|
||||
f.logger.Warn("failed initializing stats collector", "error", err)
|
||||
}
|
||||
|
||||
if cfg.CpuCompute != 0 {
|
||||
@@ -51,17 +51,17 @@ func (f *CPUFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cst
|
||||
|
||||
if mhz := stats.CPUMHzPerCore(); mhz > 0 {
|
||||
resp.AddAttribute("cpu.frequency", fmt.Sprintf("%.0f", mhz))
|
||||
f.logger.Printf("[DEBUG] fingerprint.cpu: frequency: %.0f MHz", mhz)
|
||||
f.logger.Debug("detected cpu frequency", "MHz", log.Fmt("%.0f", mhz))
|
||||
}
|
||||
|
||||
if numCores := stats.CPUNumCores(); numCores > 0 {
|
||||
resp.AddAttribute("cpu.numcores", fmt.Sprintf("%d", numCores))
|
||||
f.logger.Printf("[DEBUG] fingerprint.cpu: core count: %d", numCores)
|
||||
f.logger.Debug("detected core count", "cores", numCores)
|
||||
}
|
||||
|
||||
tt := int(stats.TotalTicksAvailable())
|
||||
if cfg.CpuCompute > 0 {
|
||||
f.logger.Printf("[DEBUG] fingerprint.cpu: Using specified cpu compute %d", cfg.CpuCompute)
|
||||
f.logger.Debug("using user specified cpu compute", "cpu_compute", cfg.CpuCompute)
|
||||
tt = cfg.CpuCompute
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCPUFingerprint(t *testing.T) {
|
||||
f := NewCPUFingerprint(testlog.Logger(t))
|
||||
f := NewCPUFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func TestCPUFingerprint(t *testing.T) {
|
||||
// TestCPUFingerprint_OverrideCompute asserts that setting cpu_total_compute in
|
||||
// the client config overrides the detected CPU freq (if any).
|
||||
func TestCPUFingerprint_OverrideCompute(t *testing.T) {
|
||||
f := NewCPUFingerprint(testlog.Logger(t))
|
||||
f := NewCPUFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package fingerprint
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -11,8 +10,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-cleanhttp"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
|
||||
"github.com/hashicorp/go-cleanhttp"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
@@ -51,13 +52,13 @@ var ec2InstanceSpeedMap = map[*regexp.Regexp]int{
|
||||
type EnvAWSFingerprint struct {
|
||||
StaticFingerprinter
|
||||
timeout time.Duration
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewEnvAWSFingerprint is used to create a fingerprint from AWS metadata
|
||||
func NewEnvAWSFingerprint(logger *log.Logger) Fingerprint {
|
||||
func NewEnvAWSFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &EnvAWSFingerprint{
|
||||
logger: logger,
|
||||
logger: logger.Named("env_aws"),
|
||||
timeout: AwsMetadataTimeout,
|
||||
}
|
||||
return f
|
||||
@@ -107,7 +108,7 @@ func (f *EnvAWSFingerprint) Fingerprint(request *cstructs.FingerprintRequest, re
|
||||
for k, unique := range keys {
|
||||
res, err := client.Get(metadataURL + k)
|
||||
if res.StatusCode != http.StatusOK {
|
||||
f.logger.Printf("[DEBUG]: fingerprint.env_aws: Could not read value for attribute %q", k)
|
||||
f.logger.Debug("could not read attribute value", "attribute", k)
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
@@ -122,7 +123,7 @@ func (f *EnvAWSFingerprint) Fingerprint(request *cstructs.FingerprintRequest, re
|
||||
resp, err := ioutil.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
f.logger.Printf("[ERR]: fingerprint.env_aws: Error reading response body for AWS %s", k)
|
||||
f.logger.Error("error reading response body for AWS attribute", "attribute", k, "error", err)
|
||||
}
|
||||
|
||||
// assume we want blank entries
|
||||
@@ -194,7 +195,7 @@ func (f *EnvAWSFingerprint) isAWS() bool {
|
||||
// Query the metadata url for the ami-id, to verify we're on AWS
|
||||
resp, err := client.Get(metadataURL + "ami-id")
|
||||
if err != nil {
|
||||
f.logger.Printf("[DEBUG] fingerprint.env_aws: Error querying AWS Metadata URL, skipping")
|
||||
f.logger.Debug("error querying AWS Metadata URL, skipping")
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
@@ -206,7 +207,7 @@ func (f *EnvAWSFingerprint) isAWS() bool {
|
||||
|
||||
instanceID, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
f.logger.Printf("[DEBUG] fingerprint.env_aws: Error reading AWS Instance ID, skipping")
|
||||
f.logger.Debug("error reading AWS Instance ID, skipping")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -235,14 +236,14 @@ func (f *EnvAWSFingerprint) linkSpeed() int {
|
||||
|
||||
res, err := client.Get(metadataURL + "instance-type")
|
||||
if err != nil {
|
||||
f.logger.Printf("[ERR]: fingerprint.env_aws: Error reading instance-type: %v", err)
|
||||
f.logger.Error("error reading instance-type", "error", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
f.logger.Printf("[ERR]: fingerprint.env_aws: Error reading response body for instance-type: %v", err)
|
||||
f.logger.Error("error reading response body for instance-type", "error", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
func TestEnvAWSFingerprint_nonAws(t *testing.T) {
|
||||
os.Setenv("AWS_ENV_URL", "http://127.0.0.1/latest/meta-data/")
|
||||
f := NewEnvAWSFingerprint(testlog.Logger(t))
|
||||
f := NewEnvAWSFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func TestEnvAWSFingerprint_nonAws(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnvAWSFingerprint_aws(t *testing.T) {
|
||||
f := NewEnvAWSFingerprint(testlog.Logger(t))
|
||||
f := NewEnvAWSFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func TestNetworkFingerprint_AWS(t *testing.T) {
|
||||
defer ts.Close()
|
||||
os.Setenv("AWS_ENV_URL", ts.URL+"/latest/meta-data/")
|
||||
|
||||
f := NewEnvAWSFingerprint(testlog.Logger(t))
|
||||
f := NewEnvAWSFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func TestNetworkFingerprint_AWS_network(t *testing.T) {
|
||||
defer ts.Close()
|
||||
os.Setenv("AWS_ENV_URL", ts.URL+"/latest/meta-data/")
|
||||
|
||||
f := NewEnvAWSFingerprint(testlog.Logger(t))
|
||||
f := NewEnvAWSFingerprint(testlog.HCLogger(t))
|
||||
{
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
@@ -298,7 +298,7 @@ func TestNetworkFingerprint_AWS_network(t *testing.T) {
|
||||
|
||||
func TestNetworkFingerprint_notAWS(t *testing.T) {
|
||||
os.Setenv("AWS_ENV_URL", "http://127.0.0.1/latest/meta-data/")
|
||||
f := NewEnvAWSFingerprint(testlog.Logger(t))
|
||||
f := NewEnvAWSFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -13,8 +12,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-cleanhttp"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
|
||||
"github.com/hashicorp/go-cleanhttp"
|
||||
"github.com/hashicorp/nomad/helper/useragent"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
@@ -56,12 +57,12 @@ func lastToken(s string) string {
|
||||
type EnvGCEFingerprint struct {
|
||||
StaticFingerprinter
|
||||
client *http.Client
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
metadataURL string
|
||||
}
|
||||
|
||||
// NewEnvGCEFingerprint is used to create a fingerprint from GCE metadata
|
||||
func NewEnvGCEFingerprint(logger *log.Logger) Fingerprint {
|
||||
func NewEnvGCEFingerprint(logger log.Logger) Fingerprint {
|
||||
// Read the internal metadata URL from the environment, allowing test files to
|
||||
// provide their own
|
||||
metadataURL := os.Getenv("GCE_ENV_URL")
|
||||
@@ -77,7 +78,7 @@ func NewEnvGCEFingerprint(logger *log.Logger) Fingerprint {
|
||||
|
||||
return &EnvGCEFingerprint{
|
||||
client: client,
|
||||
logger: logger,
|
||||
logger: logger.Named("env_gce"),
|
||||
metadataURL: metadataURL,
|
||||
}
|
||||
}
|
||||
@@ -103,15 +104,18 @@ func (f *EnvGCEFingerprint) Get(attribute string, recursive bool) (string, error
|
||||
}
|
||||
|
||||
res, err := f.client.Do(req)
|
||||
if err != nil || res.StatusCode != http.StatusOK {
|
||||
f.logger.Printf("[DEBUG] fingerprint.env_gce: Could not read value for attribute %q", attribute)
|
||||
if err != nil {
|
||||
f.logger.Debug("could not read value for attribute", "attribute", attribute, "error", err)
|
||||
return "", err
|
||||
} else if res.StatusCode != http.StatusOK {
|
||||
f.logger.Debug("could not read value for attribute", "attribute", attribute, "resp_code", res.StatusCode)
|
||||
return "", err
|
||||
}
|
||||
|
||||
resp, err := ioutil.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
f.logger.Printf("[ERR] fingerprint.env_gce: Error reading response body for GCE %s", attribute)
|
||||
f.logger.Error("error reading response body for GCE attribute", "attribute", attribute, "error", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -122,11 +126,11 @@ func (f *EnvGCEFingerprint) Get(attribute string, recursive bool) (string, error
|
||||
return string(resp), nil
|
||||
}
|
||||
|
||||
func checkError(err error, logger *log.Logger, desc string) error {
|
||||
func checkError(err error, logger log.Logger, desc string) error {
|
||||
// If it's a URL error, assume we're not actually in an GCE environment.
|
||||
// To the outer layers, this isn't an error so return nil.
|
||||
if _, ok := err.(*url.Error); ok {
|
||||
logger.Printf("[DEBUG] fingerprint.env_gce: Error querying GCE " + desc + ", skipping")
|
||||
logger.Debug("error querying GCE attribute; skipping", "attribute", desc)
|
||||
return nil
|
||||
}
|
||||
// Otherwise pass the error through.
|
||||
@@ -191,12 +195,12 @@ func (f *EnvGCEFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
// Get internal and external IPs (if they exist)
|
||||
value, err := f.Get("network-interfaces/", true)
|
||||
if err != nil {
|
||||
f.logger.Printf("[WARN] fingerprint.env_gce: Error retrieving network interface information: %s", err)
|
||||
f.logger.Warn("error retrieving network interface information", "error", err)
|
||||
} else {
|
||||
|
||||
var interfaces []GCEMetadataNetworkInterface
|
||||
if err := json.Unmarshal([]byte(value), &interfaces); err != nil {
|
||||
f.logger.Printf("[WARN] fingerprint.env_gce: Error decoding network interface information: %s", err.Error())
|
||||
f.logger.Warn("error decoding network interface information", "error", err)
|
||||
}
|
||||
|
||||
for _, intf := range interfaces {
|
||||
@@ -216,7 +220,7 @@ func (f *EnvGCEFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
return checkError(err, f.logger, "tags")
|
||||
}
|
||||
if err := json.Unmarshal([]byte(value), &tagList); err != nil {
|
||||
f.logger.Printf("[WARN] fingerprint.env_gce: Error decoding instance tags: %s", err.Error())
|
||||
f.logger.Warn("error decoding instance tags", "error", err)
|
||||
}
|
||||
for _, tag := range tagList {
|
||||
attr := "platform.gce.tag."
|
||||
@@ -240,7 +244,7 @@ func (f *EnvGCEFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
return checkError(err, f.logger, "attributes/")
|
||||
}
|
||||
if err := json.Unmarshal([]byte(value), &attrDict); err != nil {
|
||||
f.logger.Printf("[WARN] fingerprint.env_gce: Error decoding instance attributes: %s", err.Error())
|
||||
f.logger.Warn("error decoding instance attributes", "error", err)
|
||||
}
|
||||
for k, v := range attrDict {
|
||||
attr := "platform.gce.attr."
|
||||
@@ -276,7 +280,7 @@ func (f *EnvGCEFingerprint) isGCE() bool {
|
||||
if err != nil {
|
||||
if re, ok := err.(ReqError); !ok || re.StatusCode != 404 {
|
||||
// If it wasn't a 404 error, print an error message.
|
||||
f.logger.Printf("[DEBUG] fingerprint.env_gce: Error querying GCE Metadata URL, skipping")
|
||||
f.logger.Debug("error querying GCE Metadata URL, skipping")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
func TestGCEFingerprint_nonGCE(t *testing.T) {
|
||||
os.Setenv("GCE_ENV_URL", "http://127.0.0.1/computeMetadata/v1/instance/")
|
||||
f := NewEnvGCEFingerprint(testlog.Logger(t))
|
||||
f := NewEnvGCEFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func testFingerprint_GCE(t *testing.T, withExternalIp bool) {
|
||||
}))
|
||||
defer ts.Close()
|
||||
os.Setenv("GCE_ENV_URL", ts.URL+"/computeMetadata/v1/instance/")
|
||||
f := NewEnvGCEFingerprint(testlog.Logger(t))
|
||||
f := NewEnvGCEFingerprint(testlog.HCLogger(t))
|
||||
|
||||
request := &cstructs.FingerprintRequest{Config: &config.Config{}, Node: node}
|
||||
var response cstructs.FingerprintResponse
|
||||
|
||||
@@ -2,10 +2,10 @@ package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
)
|
||||
|
||||
@@ -67,7 +67,7 @@ func BuiltinFingerprints() []string {
|
||||
|
||||
// NewFingerprint is used to instantiate and return a new fingerprint
|
||||
// given the name and a logger
|
||||
func NewFingerprint(name string, logger *log.Logger) (Fingerprint, error) {
|
||||
func NewFingerprint(name string, logger log.Logger) (Fingerprint, error) {
|
||||
// Lookup the factory function
|
||||
factory, ok := hostFingerprinters[name]
|
||||
if !ok {
|
||||
@@ -83,7 +83,7 @@ func NewFingerprint(name string, logger *log.Logger) (Fingerprint, error) {
|
||||
}
|
||||
|
||||
// Factory is used to instantiate a new Fingerprint
|
||||
type Factory func(*log.Logger) Fingerprint
|
||||
type Factory func(log.Logger) Fingerprint
|
||||
|
||||
// HealthCheck is used for doing periodic health checks. On a given time
|
||||
// interfal, a health check will be called by the fingerprint manager of the
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"log"
|
||||
"runtime"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
)
|
||||
@@ -11,19 +11,19 @@ import (
|
||||
// HostFingerprint is used to fingerprint the host
|
||||
type HostFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewHostFingerprint is used to create a Host fingerprint
|
||||
func NewHostFingerprint(logger *log.Logger) Fingerprint {
|
||||
f := &HostFingerprint{logger: logger}
|
||||
func NewHostFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &HostFingerprint{logger: logger.Named("host")}
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *HostFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cstructs.FingerprintResponse) error {
|
||||
hostInfo, err := host.Info()
|
||||
if err != nil {
|
||||
f.logger.Println("[WARN] Error retrieving host information: ", err)
|
||||
f.logger.Warn("error retrieving host information", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestHostFingerprint(t *testing.T) {
|
||||
f := NewHostFingerprint(testlog.Logger(t))
|
||||
f := NewHostFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
@@ -14,13 +14,13 @@ const bytesInMB = 1024 * 1024
|
||||
// MemoryFingerprint is used to fingerprint the available memory on the node
|
||||
type MemoryFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewMemoryFingerprint is used to create a Memory fingerprint
|
||||
func NewMemoryFingerprint(logger *log.Logger) Fingerprint {
|
||||
func NewMemoryFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &MemoryFingerprint{
|
||||
logger: logger,
|
||||
logger: logger.Named("memory"),
|
||||
}
|
||||
return f
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func (f *MemoryFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *
|
||||
} else {
|
||||
memInfo, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
f.logger.Printf("[WARN] Error reading memory information: %s", err)
|
||||
f.logger.Warn("error reading memory information", "error", err)
|
||||
return err
|
||||
}
|
||||
if memInfo.Total > 0 {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMemoryFingerprint(t *testing.T) {
|
||||
f := NewMemoryFingerprint(testlog.Logger(t))
|
||||
f := NewMemoryFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func TestMemoryFingerprint(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMemoryFingerprint_Override(t *testing.T) {
|
||||
f := NewMemoryFingerprint(testlog.Logger(t))
|
||||
f := NewMemoryFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
sockaddr "github.com/hashicorp/go-sockaddr"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
@@ -25,7 +25,7 @@ const (
|
||||
// NetworkFingerprint is used to fingerprint the Network capabilities of a node
|
||||
type NetworkFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
interfaceDetector NetworkInterfaceDetector
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ func (b *DefaultNetworkInterfaceDetector) Addrs(intf *net.Interface) ([]net.Addr
|
||||
|
||||
// NewNetworkFingerprint returns a new NetworkFingerprinter with the given
|
||||
// logger
|
||||
func NewNetworkFingerprint(logger *log.Logger) Fingerprint {
|
||||
f := &NetworkFingerprint{logger: logger, interfaceDetector: &DefaultNetworkInterfaceDetector{}}
|
||||
func NewNetworkFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &NetworkFingerprint{logger: logger.Named("network"), interfaceDetector: &DefaultNetworkInterfaceDetector{}}
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -79,13 +79,13 @@ func (f *NetworkFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp
|
||||
throughput := f.linkSpeed(intf.Name)
|
||||
if cfg.NetworkSpeed != 0 {
|
||||
mbits = cfg.NetworkSpeed
|
||||
f.logger.Printf("[DEBUG] fingerprint.network: setting link speed to user configured speed: %d", mbits)
|
||||
f.logger.Debug("setting link speed to user configured speed", "mbits", mbits)
|
||||
} else if throughput != 0 {
|
||||
mbits = throughput
|
||||
f.logger.Printf("[DEBUG] fingerprint.network: link speed for %v set to %v", intf.Name, mbits)
|
||||
f.logger.Debug("link speed detected", "interface", intf.Name, "mbits", mbits)
|
||||
} else {
|
||||
mbits = defaultNetworkSpeed
|
||||
f.logger.Printf("[DEBUG] fingerprint.network: link speed could not be detected and no speed specified by user. Defaulting to %d", defaultNetworkSpeed)
|
||||
f.logger.Debug("link speed could not be detected and no speed specified by user, falling back to default speed", "mbits", defaultNetworkSpeed)
|
||||
}
|
||||
|
||||
// Create the network resources from the interface
|
||||
@@ -105,7 +105,7 @@ func (f *NetworkFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp
|
||||
}
|
||||
|
||||
for _, nwResource := range nwResources {
|
||||
f.logger.Printf("[DEBUG] fingerprint.network: Detected interface %v with IP: %v", intf.Name, nwResource.IP)
|
||||
f.logger.Debug("detected interface IP", "interface", intf.Name, "IP", nwResource.IP)
|
||||
}
|
||||
|
||||
// Deprecated, setting the first IP as unique IP for the node
|
||||
@@ -163,7 +163,7 @@ func (f *NetworkFingerprint) createNetworkResources(throughput int, intf *net.In
|
||||
|
||||
if len(nwResources) == 0 && len(linkLocals) != 0 {
|
||||
if disallowLinkLocal {
|
||||
f.logger.Printf("[DEBUG] fingerprint.network: ignoring detected link-local address on interface %v", intf.Name)
|
||||
f.logger.Debug("ignoring detected link-local address on interface", "interface", intf.Name)
|
||||
return nwResources, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ func TestNetworkFingerprint_basic(t *testing.T) {
|
||||
t.Skipf("Environment variable %+q not empty, skipping test", skipOnlineTestsEnvVar)
|
||||
}
|
||||
|
||||
f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &DefaultNetworkInterfaceDetector{}}
|
||||
f := &NetworkFingerprint{logger: testlog.HCLogger(t), interfaceDetector: &DefaultNetworkInterfaceDetector{}}
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func TestNetworkFingerprint_basic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkFingerprint_default_device_absent(t *testing.T) {
|
||||
f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorOnlyLo{}}
|
||||
f := &NetworkFingerprint{logger: testlog.HCLogger(t), interfaceDetector: &NetworkInterfaceDetectorOnlyLo{}}
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -259,7 +259,7 @@ func TestNetworkFingerprint_default_device_absent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkFingerPrint_default_device(t *testing.T) {
|
||||
f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorOnlyLo{}}
|
||||
f := &NetworkFingerprint{logger: testlog.HCLogger(t), interfaceDetector: &NetworkInterfaceDetectorOnlyLo{}}
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -310,7 +310,7 @@ func TestNetworkFingerPrint_default_device(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkFingerPrint_LinkLocal_Allowed(t *testing.T) {
|
||||
f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}}
|
||||
f := &NetworkFingerprint{logger: testlog.HCLogger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}}
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -357,7 +357,7 @@ func TestNetworkFingerPrint_LinkLocal_Allowed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkFingerPrint_LinkLocal_Allowed_MixedIntf(t *testing.T) {
|
||||
f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}}
|
||||
f := &NetworkFingerprint{logger: testlog.HCLogger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}}
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
@@ -411,7 +411,7 @@ func TestNetworkFingerPrint_LinkLocal_Allowed_MixedIntf(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkFingerPrint_LinkLocal_Disallowed(t *testing.T) {
|
||||
f := &NetworkFingerprint{logger: testlog.Logger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}}
|
||||
f := &NetworkFingerprint{logger: testlog.HCLogger(t), interfaceDetector: &NetworkInterfaceDetectorMultipleInterfaces{}}
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
)
|
||||
|
||||
// NomadFingerprint is used to fingerprint the Nomad version
|
||||
type NomadFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewNomadFingerprint is used to create a Nomad fingerprint
|
||||
func NewNomadFingerprint(logger *log.Logger) Fingerprint {
|
||||
f := &NomadFingerprint{logger: logger}
|
||||
func NewNomadFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &NomadFingerprint{logger: logger.Named("nomad")}
|
||||
return f
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNomadFingerprint(t *testing.T) {
|
||||
f := NewNomadFingerprint(testlog.Logger(t))
|
||||
f := NewNomadFingerprint(testlog.HCLogger(t))
|
||||
|
||||
v := "foo"
|
||||
r := "123"
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/consul-template/signals"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
)
|
||||
|
||||
// SignalFingerprint is used to fingerprint the available signals
|
||||
type SignalFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewSignalFingerprint is used to create a Signal fingerprint
|
||||
func NewSignalFingerprint(logger *log.Logger) Fingerprint {
|
||||
f := &SignalFingerprint{logger: logger}
|
||||
func NewSignalFingerprint(logger log.Logger) Fingerprint {
|
||||
f := &SignalFingerprint{logger: logger.Named("signals")}
|
||||
return f
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSignalFingerprint(t *testing.T) {
|
||||
fp := NewSignalFingerprint(testlog.Logger(t))
|
||||
fp := NewSignalFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
@@ -16,11 +16,11 @@ const bytesPerMegabyte = 1024 * 1024
|
||||
// applications that the Nomad agent will run on this machine.
|
||||
type StorageFingerprint struct {
|
||||
StaticFingerprinter
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func NewStorageFingerprint(logger *log.Logger) Fingerprint {
|
||||
fp := &StorageFingerprint{logger: logger}
|
||||
func NewStorageFingerprint(logger log.Logger) Fingerprint {
|
||||
fp := &StorageFingerprint{logger: logger.Named("storage")}
|
||||
return fp
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func TestStorageFingerprint(t *testing.T) {
|
||||
fp := NewStorageFingerprint(testlog.Logger(t))
|
||||
fp := NewStorageFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
vapi "github.com/hashicorp/vault/api"
|
||||
)
|
||||
@@ -18,14 +18,14 @@ const (
|
||||
|
||||
// VaultFingerprint is used to fingerprint for Vault
|
||||
type VaultFingerprint struct {
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
client *vapi.Client
|
||||
lastState string
|
||||
}
|
||||
|
||||
// NewVaultFingerprint is used to create a Vault fingerprint
|
||||
func NewVaultFingerprint(logger *log.Logger) Fingerprint {
|
||||
return &VaultFingerprint{logger: logger, lastState: vaultUnavailable}
|
||||
func NewVaultFingerprint(logger log.Logger) Fingerprint {
|
||||
return &VaultFingerprint{logger: logger.Named("vault"), lastState: vaultUnavailable}
|
||||
}
|
||||
|
||||
func (f *VaultFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *cstructs.FingerprintResponse) error {
|
||||
@@ -55,7 +55,7 @@ func (f *VaultFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *c
|
||||
f.clearVaultAttributes(resp)
|
||||
// Print a message indicating that Vault is not available anymore
|
||||
if f.lastState == vaultAvailable {
|
||||
f.logger.Printf("[INFO] fingerprint.vault: Vault is unavailable")
|
||||
f.logger.Info("Vault is unavailable")
|
||||
}
|
||||
f.lastState = vaultUnavailable
|
||||
return nil
|
||||
@@ -71,7 +71,7 @@ func (f *VaultFingerprint) Fingerprint(req *cstructs.FingerprintRequest, resp *c
|
||||
// If Vault was previously unavailable print a message to indicate the Agent
|
||||
// is available now
|
||||
if f.lastState == vaultUnavailable {
|
||||
f.logger.Printf("[INFO] fingerprint.vault: Vault is available")
|
||||
f.logger.Info("Vault is available")
|
||||
}
|
||||
f.lastState = vaultAvailable
|
||||
resp.Detected = true
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestVaultFingerprint(t *testing.T) {
|
||||
tv := testutil.NewTestVault(t)
|
||||
defer tv.Stop()
|
||||
|
||||
fp := NewVaultFingerprint(testlog.Logger(t))
|
||||
fp := NewVaultFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/client/driver"
|
||||
"github.com/hashicorp/nomad/client/fingerprint"
|
||||
@@ -30,7 +28,7 @@ type FingerprintManager struct {
|
||||
// updateNodeFromDriver is a callback to the client to update the state of a
|
||||
// specific driver for the node
|
||||
updateNodeFromDriver func(string, *structs.DriverInfo, *structs.DriverInfo) *structs.Node
|
||||
logger hclog.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// NewFingerprintManager is a constructor that creates and returns an instance
|
||||
@@ -40,16 +38,15 @@ func NewFingerprintManager(getConfig func() *config.Config,
|
||||
shutdownCh chan struct{},
|
||||
updateNodeAttributes func(*cstructs.FingerprintResponse) *structs.Node,
|
||||
updateNodeFromDriver func(string, *structs.DriverInfo, *structs.DriverInfo) *structs.Node,
|
||||
logger hclog.Logger) *FingerprintManager {
|
||||
logger log.Logger) *FingerprintManager {
|
||||
|
||||
logger = logger.Named("fingerprint_mgr")
|
||||
return &FingerprintManager{
|
||||
getConfig: getConfig,
|
||||
updateNodeAttributes: updateNodeAttributes,
|
||||
updateNodeFromDriver: updateNodeFromDriver,
|
||||
node: node,
|
||||
shutdownCh: shutdownCh,
|
||||
logger: logger,
|
||||
logger: logger.Named("fingerprint_mgr"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,13 +141,10 @@ func (fp *FingerprintManager) Run() error {
|
||||
// setupFingerprints is used to fingerprint the node to see if these attributes are
|
||||
// supported
|
||||
func (fm *FingerprintManager) setupFingerprinters(fingerprints []string) error {
|
||||
//FIXME Update fingerprinters to hclog
|
||||
tempLogger := log.New(os.Stdout, "", log.LstdFlags|log.Lmicroseconds)
|
||||
|
||||
var appliedFingerprints []string
|
||||
|
||||
for _, name := range fingerprints {
|
||||
f, err := fingerprint.NewFingerprint(name, tempLogger)
|
||||
f, err := fingerprint.NewFingerprint(name, fm.logger)
|
||||
|
||||
if err != nil {
|
||||
fm.logger.Error("error fingerprinting", "error", err, "fingerprinter", name)
|
||||
@@ -180,11 +174,9 @@ func (fm *FingerprintManager) setupFingerprinters(fingerprints []string) error {
|
||||
// setupDrivers is used to fingerprint the node to see if these drivers are
|
||||
// supported
|
||||
func (fm *FingerprintManager) setupDrivers(drivers []string) error {
|
||||
//FIXME Update fingerprinters to hclog
|
||||
tempLogger := log.New(os.Stdout, "", log.LstdFlags|log.Lmicroseconds)
|
||||
|
||||
//TODO(alex,hclog) Update fingerprinters to hclog
|
||||
var availDrivers []string
|
||||
driverCtx := driver.NewDriverContext("", "", "", "", fm.getConfig(), fm.getNode(), tempLogger, nil)
|
||||
driverCtx := driver.NewDriverContext("", "", "", "", fm.getConfig(), fm.getNode(), fm.logger.StandardLogger(&log.StandardLoggerOptions{InferLevels: true}), nil)
|
||||
for _, name := range drivers {
|
||||
|
||||
d, err := driver.NewDriver(name, driverCtx)
|
||||
|
||||
@@ -15,7 +15,7 @@ func TestFingerprintManager_Run_MockDriver(t *testing.T) {
|
||||
require := require.New(t)
|
||||
testClient := TestClient(t, nil)
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -24,7 +24,7 @@ func TestFingerprintManager_Run_MockDriver(t *testing.T) {
|
||||
testClient.shutdownCh,
|
||||
testClient.updateNodeFromFingerprint,
|
||||
testClient.updateNodeFromDriver,
|
||||
testlog.Logger(t),
|
||||
testlog.HCLogger(t),
|
||||
)
|
||||
|
||||
err := fm.Run()
|
||||
@@ -42,7 +42,7 @@ func TestFingerprintManager_Run_ResourcesFingerprint(t *testing.T) {
|
||||
require := require.New(t)
|
||||
testClient := TestClient(t, nil)
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -69,7 +69,7 @@ func TestFingerprintManager_Fingerprint_Run(t *testing.T) {
|
||||
require := require.New(t)
|
||||
testClient := TestClient(t, nil)
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -101,7 +101,7 @@ func TestFingerprintManager_Fingerprint_Periodic(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -163,7 +163,7 @@ func TestFingerprintManager_HealthCheck_Driver(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -263,7 +263,7 @@ func TestFingerprintManager_HealthCheck_Periodic(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -359,7 +359,7 @@ func TestFimgerprintManager_Run_InWhitelist(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -389,7 +389,7 @@ func TestFingerprintManager_Run_InBlacklist(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -421,7 +421,7 @@ func TestFingerprintManager_Run_Combination(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -454,7 +454,7 @@ func TestFingerprintManager_Run_WhitelistDrivers(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -484,7 +484,7 @@ func TestFingerprintManager_Run_AllDriversBlacklisted(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -518,7 +518,7 @@ func TestFingerprintManager_Run_DriversWhiteListBlacklistCombination(t *testing.
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
@@ -551,7 +551,7 @@ func TestFingerprintManager_Run_DriversInBlacklist(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
testClient.logger = testlog.Logger(t)
|
||||
testClient.logger = testlog.HCLogger(t)
|
||||
defer testClient.Shutdown()
|
||||
|
||||
fm := NewFingerprintManager(
|
||||
|
||||
@@ -41,7 +41,7 @@ func tempAllocDir(t testing.TB) *allocdir.AllocDir {
|
||||
t.Fatalf("failed to chmod dir: %v", err)
|
||||
}
|
||||
|
||||
return allocdir.NewAllocDir(testlog.Logger(t), dir)
|
||||
return allocdir.NewAllocDir(testlog.HCLogger(t), dir)
|
||||
}
|
||||
|
||||
type nopWriteCloser struct {
|
||||
|
||||
Reference in New Issue
Block a user