Merge pull request #3979 from guidoiaquinti/master

Consolidate logging output
This commit is contained in:
Kyle Havlovitz 2018-03-26 10:07:20 -07:00 committed by GitHub
commit f7352182b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 33 deletions

View file

@ -659,7 +659,7 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error {
} }
wp.LogOutput = a.LogOutput wp.LogOutput = a.LogOutput
if err := wp.Run(addr); err != nil { if err := wp.Run(addr); err != nil {
a.logger.Printf("[ERR] Failed to run watch: %v", err) a.logger.Printf("[ERR] agent: Failed to run watch: %v", err)
} }
}(wp) }(wp)
} }
@ -908,7 +908,7 @@ func (a *Agent) makeRandomID() (string, error) {
return "", err return "", err
} }
a.logger.Printf("[DEBUG] Using random ID %q as node ID", id) a.logger.Printf("[DEBUG] agent: Using random ID %q as node ID", id)
return id, nil return id, nil
} }
@ -926,7 +926,7 @@ func (a *Agent) makeNodeID() (string, error) {
// Try to get a stable ID associated with the host itself. // Try to get a stable ID associated with the host itself.
info, err := host.Info() info, err := host.Info()
if err != nil { if err != nil {
a.logger.Printf("[DEBUG] Couldn't get a unique ID from the host: %v", err) a.logger.Printf("[DEBUG] agent: Couldn't get a unique ID from the host: %v", err)
return a.makeRandomID() return a.makeRandomID()
} }
@ -934,7 +934,7 @@ func (a *Agent) makeNodeID() (string, error) {
// control over this process. // control over this process.
id := strings.ToLower(info.HostID) id := strings.ToLower(info.HostID)
if _, err := uuid.ParseUUID(id); err != nil { if _, err := uuid.ParseUUID(id); err != nil {
a.logger.Printf("[DEBUG] Unique ID %q from host isn't formatted as a UUID: %v", a.logger.Printf("[DEBUG] agent: Unique ID %q from host isn't formatted as a UUID: %v",
id, err) id, err)
return a.makeRandomID() return a.makeRandomID()
} }
@ -950,7 +950,7 @@ func (a *Agent) makeNodeID() (string, error) {
buf[8:10], buf[8:10],
buf[10:16]) buf[10:16])
a.logger.Printf("[DEBUG] Using unique ID %q from host as node ID", id) a.logger.Printf("[DEBUG] agent: Using unique ID %q from host as node ID", id)
return id, nil return id, nil
} }
@ -1280,10 +1280,10 @@ func (a *Agent) JoinWAN(addrs []string) (n int, err error) {
// ForceLeave is used to remove a failed node from the cluster // ForceLeave is used to remove a failed node from the cluster
func (a *Agent) ForceLeave(node string) (err error) { func (a *Agent) ForceLeave(node string) (err error) {
a.logger.Printf("[INFO] Force leaving node: %v", node) a.logger.Printf("[INFO] agent: Force leaving node: %v", node)
err = a.delegate.RemoveFailedNode(node) err = a.delegate.RemoveFailedNode(node)
if err != nil { if err != nil {
a.logger.Printf("[WARN] Failed to remove node: %v", err) a.logger.Printf("[WARN] agent: Failed to remove node: %v", err)
} }
return err return err
} }
@ -1546,7 +1546,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes []*structs.Che
// Warn if the service name is incompatible with DNS // Warn if the service name is incompatible with DNS
if InvalidDnsRe.MatchString(service.Service) { if InvalidDnsRe.MatchString(service.Service) {
a.logger.Printf("[WARN] Service name %q will not be discoverable "+ a.logger.Printf("[WARN] agent: Service name %q will not be discoverable "+
"via DNS due to invalid characters. Valid characters include "+ "via DNS due to invalid characters. Valid characters include "+
"all alpha-numerics and dashes.", service.Service) "all alpha-numerics and dashes.", service.Service)
} }
@ -1554,7 +1554,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes []*structs.Che
// Warn if any tags are incompatible with DNS // Warn if any tags are incompatible with DNS
for _, tag := range service.Tags { for _, tag := range service.Tags {
if InvalidDnsRe.MatchString(tag) { if InvalidDnsRe.MatchString(tag) {
a.logger.Printf("[DEBUG] Service tag %q will not be discoverable "+ a.logger.Printf("[DEBUG] agent: Service tag %q will not be discoverable "+
"via DNS due to invalid characters. Valid characters include "+ "via DNS due to invalid characters. Valid characters include "+
"all alpha-numerics and dashes.", tag) "all alpha-numerics and dashes.", tag)
} }
@ -2182,7 +2182,7 @@ func (a *Agent) loadServices(conf *config.RuntimeConfig) error {
// Skip all partially written temporary files // Skip all partially written temporary files
if strings.HasSuffix(fi.Name(), "tmp") { if strings.HasSuffix(fi.Name(), "tmp") {
a.logger.Printf("[WARN] Ignoring temporary service file %v", fi.Name()) a.logger.Printf("[WARN] agent: Ignoring temporary service file %v", fi.Name())
continue continue
} }
@ -2205,7 +2205,7 @@ func (a *Agent) loadServices(conf *config.RuntimeConfig) error {
if err := json.Unmarshal(buf, &p); err != nil { if err := json.Unmarshal(buf, &p); err != nil {
// Backwards-compatibility for pre-0.5.1 persisted services // Backwards-compatibility for pre-0.5.1 persisted services
if err := json.Unmarshal(buf, &p.Service); err != nil { if err := json.Unmarshal(buf, &p.Service); err != nil {
a.logger.Printf("[ERR] Failed decoding service file %q: %s", file, err) a.logger.Printf("[ERR] agent: Failed decoding service file %q: %s", file, err)
continue continue
} }
} }
@ -2285,7 +2285,7 @@ func (a *Agent) loadChecks(conf *config.RuntimeConfig) error {
// Decode the check // Decode the check
var p persistedCheck var p persistedCheck
if err := json.Unmarshal(buf, &p); err != nil { if err := json.Unmarshal(buf, &p); err != nil {
a.logger.Printf("[ERR] Failed decoding check file %q: %s", file, err) a.logger.Printf("[ERR] agent: Failed decoding check file %q: %s", file, err)
continue continue
} }
checkID := p.Check.CheckID checkID := p.Check.CheckID

View file

@ -783,6 +783,6 @@ func (s *HTTPServer) AgentToken(resp http.ResponseWriter, req *http.Request) (in
return nil, nil return nil, nil
} }
s.agent.logger.Printf("[INFO] Updated agent's ACL token %q", target) s.agent.logger.Printf("[INFO] agent: Updated agent's ACL token %q", target)
return nil, nil return nil, nil
} }

View file

@ -150,11 +150,11 @@ func (c *CheckMonitor) check() {
select { select {
case <-time.After(timeout): case <-time.After(timeout):
if err := exec.KillCommandSubtree(cmd); err != nil { if err := exec.KillCommandSubtree(cmd); err != nil {
c.Logger.Printf("[WARN] Check %q failed to kill after timeout: %s", c.CheckID, err) c.Logger.Printf("[WARN] agent: Check %q failed to kill after timeout: %s", c.CheckID, err)
} }
msg := fmt.Sprintf("Timed out (%s) running check", timeout.String()) msg := fmt.Sprintf("Timed out (%s) running check", timeout.String())
c.Logger.Printf("[WARN] Check %q: %s", c.CheckID, msg) c.Logger.Printf("[WARN] agent: Check %q: %s", c.CheckID, msg)
outputStr := truncateAndLogOutput() outputStr := truncateAndLogOutput()
if len(outputStr) > 0 { if len(outputStr) > 0 {
@ -625,10 +625,10 @@ func (c *CheckDocker) doCheck() (string, *circbuf.Buffer, error) {
case 0: case 0:
return api.HealthPassing, buf, nil return api.HealthPassing, buf, nil
case 1: case 1:
c.Logger.Printf("[DEBUG] Check %q failed with exit code: %d", c.CheckID, exitCode) c.Logger.Printf("[DEBUG] agent: Check %q failed with exit code: %d", c.CheckID, exitCode)
return api.HealthWarning, buf, nil return api.HealthWarning, buf, nil
default: default:
c.Logger.Printf("[DEBUG] Check %q failed with exit code: %d", c.CheckID, exitCode) c.Logger.Printf("[DEBUG] agent: Check %q failed with exit code: %d", c.CheckID, exitCode)
return api.HealthCritical, buf, nil return api.HealthCritical, buf, nil
} }
} }
@ -684,10 +684,10 @@ func (c *CheckGRPC) run() {
func (c *CheckGRPC) check() { func (c *CheckGRPC) check() {
err := c.probe.Check() err := c.probe.Check()
if err != nil { if err != nil {
c.Logger.Printf("[DEBUG] Check %q failed: %s", c.CheckID, err.Error()) c.Logger.Printf("[DEBUG] agent: Check %q failed: %s", c.CheckID, err.Error())
c.Notify.UpdateCheck(c.CheckID, api.HealthCritical, err.Error()) c.Notify.UpdateCheck(c.CheckID, api.HealthCritical, err.Error())
} else { } else {
c.Logger.Printf("[DEBUG] Check %q is passing", c.CheckID) c.Logger.Printf("[DEBUG] agent: Check %q is passing", c.CheckID)
c.Notify.UpdateCheck(c.CheckID, api.HealthPassing, fmt.Sprintf("gRPC check %s: success", c.GRPC)) c.Notify.UpdateCheck(c.CheckID, api.HealthPassing, fmt.Sprintf("gRPC check %s: success", c.GRPC))
} }
} }

View file

@ -697,7 +697,7 @@ func (l *State) updateSyncState() error {
// The Serf check is created automatically and does not // The Serf check is created automatically and does not
// need to be deregistered. // need to be deregistered.
if id == structs.SerfCheckID { if id == structs.SerfCheckID {
l.logger.Printf("[DEBUG] Skipping remote check %q since it is managed automatically", id) l.logger.Printf("[DEBUG] agent: Skipping remote check %q since it is managed automatically", id)
continue continue
} }

View file

@ -76,7 +76,7 @@ func (c *cmd) init() {
func (c *cmd) Run(args []string) int { func (c *cmd) Run(args []string) int {
code := c.run(args) code := c.run(args)
if c.logger != nil { if c.logger != nil {
c.logger.Println("[INFO] Exit code:", code) c.logger.Println("[INFO] agent: Exit code:", code)
} }
return code return code
} }
@ -400,7 +400,7 @@ func (c *cmd) run(args []string) int {
case <-c.shutdownCh: case <-c.shutdownCh:
sig = os.Interrupt sig = os.Interrupt
case err := <-agent.RetryJoinCh(): case err := <-agent.RetryJoinCh():
c.logger.Println("[ERR] Retry join failed: ", err) c.logger.Println("[ERR] agent: Retry join failed: ", err)
return 1 return 1
case <-agent.ShutdownCh(): case <-agent.ShutdownCh():
// agent is already down! // agent is already down!
@ -412,14 +412,14 @@ func (c *cmd) run(args []string) int {
continue continue
case syscall.SIGHUP: case syscall.SIGHUP:
c.logger.Println("[INFO] Caught signal: ", sig) c.logger.Println("[INFO] agent: Caught signal: ", sig)
conf, err := c.handleReload(agent, config) conf, err := c.handleReload(agent, config)
if conf != nil { if conf != nil {
config = conf config = conf
} }
if err != nil { if err != nil {
c.logger.Println("[ERR] Reload config failed: ", err) c.logger.Println("[ERR] agent: Reload config failed: ", err)
} }
// Send result back if reload was called via HTTP // Send result back if reload was called via HTTP
if reloadErrCh != nil { if reloadErrCh != nil {
@ -427,19 +427,19 @@ func (c *cmd) run(args []string) int {
} }
default: default:
c.logger.Println("[INFO] Caught signal: ", sig) c.logger.Println("[INFO] agent: Caught signal: ", sig)
graceful := (sig == os.Interrupt && !(config.SkipLeaveOnInt)) || (sig == syscall.SIGTERM && (config.LeaveOnTerm)) graceful := (sig == os.Interrupt && !(config.SkipLeaveOnInt)) || (sig == syscall.SIGTERM && (config.LeaveOnTerm))
if !graceful { if !graceful {
c.logger.Println("[INFO] Graceful shutdown disabled. Exiting") c.logger.Println("[INFO] agent: Graceful shutdown disabled. Exiting")
return 1 return 1
} }
c.logger.Println("[INFO] Gracefully shutting down agent...") c.logger.Println("[INFO] agent: Gracefully shutting down agent...")
gracefulCh := make(chan struct{}) gracefulCh := make(chan struct{})
go func() { go func() {
if err := agent.Leave(); err != nil { if err := agent.Leave(); err != nil {
c.logger.Println("[ERR] Error on leave:", err) c.logger.Println("[ERR] agent: Error on leave:", err)
return return
} }
close(gracefulCh) close(gracefulCh)
@ -448,13 +448,13 @@ func (c *cmd) run(args []string) int {
gracefulTimeout := 15 * time.Second gracefulTimeout := 15 * time.Second
select { select {
case <-signalCh: case <-signalCh:
c.logger.Printf("[INFO] Caught second signal %v. Exiting\n", sig) c.logger.Printf("[INFO] agent: Caught second signal %v. Exiting\n", sig)
return 1 return 1
case <-time.After(gracefulTimeout): case <-time.After(gracefulTimeout):
c.logger.Println("[INFO] Timeout on graceful leave. Exiting") c.logger.Println("[INFO] agent: Timeout on graceful leave. Exiting")
return 1 return 1
case <-gracefulCh: case <-gracefulCh:
c.logger.Println("[INFO] Graceful exit completed") c.logger.Println("[INFO] agent: Graceful exit completed")
return 0 return 0
} }
} }
@ -463,7 +463,7 @@ func (c *cmd) run(args []string) int {
// handleReload is invoked when we should reload our configs, e.g. SIGHUP // handleReload is invoked when we should reload our configs, e.g. SIGHUP
func (c *cmd) handleReload(agent *agent.Agent, cfg *config.RuntimeConfig) (*config.RuntimeConfig, error) { func (c *cmd) handleReload(agent *agent.Agent, cfg *config.RuntimeConfig) (*config.RuntimeConfig, error) {
c.logger.Println("[INFO] Reloading configuration...") c.logger.Println("[INFO] agent: Reloading configuration...")
var errs error var errs error
newCfg := c.readConfig() newCfg := c.readConfig()
if newCfg == nil { if newCfg == nil {

View file

@ -62,7 +62,7 @@ OUTER:
if retry > maxBackoffTime { if retry > maxBackoffTime {
retry = maxBackoffTime retry = maxBackoffTime
} }
logger.Printf("consul.watch: Watch (type: %s) errored: %v, retry in %v", logger.Printf("[ERR] consul.watch: Watch (type: %s) errored: %v, retry in %v",
p.Type, err, retry) p.Type, err, retry)
select { select {
case <-time.After(retry): case <-time.After(retry):