Merge lp:~thumper/juju-core/logger-initial-state into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1826
Proposed branch: lp:~thumper/juju-core/logger-initial-state
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 165 lines (+20/-19)
5 files modified
cmd/jujud/machine.go (+6/-0)
environs/cloudinit/cloudinit.go (+5/-11)
environs/cloudinit/cloudinit_test.go (+4/-4)
provider/local/environ.go (+1/-2)
upstart/service.go (+4/-2)
To merge this branch: bzr merge lp:~thumper/juju-core/logger-initial-state
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+185962@code.launchpad.net

Commit message

A little clean up for initial agent logging.

Now that we have a logging worker that will set the log
levels to the system wide setting when it starts, we can
start all new agents with debug, and then as soon as the
agent starts, it will change it.

A drive by fix here to have the machine agent explicitly
remove the logfile writer from loggo if one has been set.
Machine agent upstart jobs that are around from before 1.16
will otherwise cause duplicate lines.

https://codereview.appspot.com/13717044/

Description of the change

A little clean up for initial agent logging.

Now that we have a logging worker that will set the log
levels to the system wide setting when it starts, we can
start all new agents with debug, and then as soon as the
agent starts, it will change it.

A drive by fix here to have the machine agent explicitly
remove the logfile writer from loggo if one has been set.
Machine agent upstart jobs that are around from before 1.16
will otherwise cause duplicate lines.

https://codereview.appspot.com/13717044/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :
Download full text (10.7 KiB)

Reviewers: mp+185962_code.launchpad.net,

Message:
Please take a look.

Description:
A little clean up for initial agent logging.

Now that we have a logging worker that will set the log
levels to the system wide setting when it starts, we can
start all new agents with debug, and then as soon as the
agent starts, it will change it.

A drive by fix here to have the machine agent explicitly
remove the logfile writer from loggo if one has been set.
Machine agent upstart jobs that are around from before 1.16
will otherwise cause duplicate lines.

https://code.launchpad.net/~thumper/juju-core/logger-initial-state/+merge/185962

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/13717044/

Affected files (+22, -19 lines):
   A [revision details]
   M cmd/jujud/machine.go
   M environs/cloudinit/cloudinit.go
   M environs/cloudinit/cloudinit_test.go
   M provider/local/environ.go
   M upstart/service.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20130916220230-s30jbjsc5zvfzii7
+New revision: <email address hidden>

Index: upstart/service.go
=== modified file 'upstart/service.go'
--- upstart/service.go 2013-09-13 05:20:56 +0000
+++ upstart/service.go 2013-09-16 22:02:24 +0000
@@ -42,9 +42,11 @@

  // MachineAgentUpstartService returns the upstart config for a machine
agent
  // based on the tag and machineId passed in.
-func MachineAgentUpstartService(name, toolsDir, dataDir, logDir, tag,
machineId, logConfig string, env map[string]string) *Conf {
+func MachineAgentUpstartService(name, toolsDir, dataDir, logDir, tag,
machineId string, env map[string]string) *Conf {
   svc := NewService(name)
   logFile := filepath.Join(logDir, tag+".log")
+ // The machine agent always starts with debug turned on. The logger
worker
+ // will update this to the system logging environment as soon as it
starts.
   return &Conf{
    Service: *svc,
    Desc: fmt.Sprintf("juju %s agent", tag),
@@ -55,7 +57,7 @@
     " machine" +
     " --data-dir " + utils.ShQuote(dataDir) +
     " --machine-id " + machineId +
- " " + logConfig,
+ " --debug",
    Out: logFile,
    Env: env,
   }

Index: cmd/jujud/machine.go
=== modified file 'cmd/jujud/machine.go'
--- cmd/jujud/machine.go 2013-09-12 22:18:10 +0000
+++ cmd/jujud/machine.go 2013-09-17 01:58:35 +0000
@@ -10,6 +10,7 @@
   "time"

   "launchpad.net/gnuflag"
+ "launchpad.net/loggo"
   "launchpad.net/tomb"

   "launchpad.net/juju-core/agent"
@@ -97,6 +98,11 @@

  // Run runs a machine agent.
  func (a *MachineAgent) Run(_ *cmd.Context) error {
+ // Due to changes in the logging, and needing to care about old
+ // environments that have been upgraded, we need to explicitly remove the
+ // file writer if one has been added, otherwise we will get duplicate
+ // lines of all logging in the log file.
+ loggo.RemoveWriter("logfile")
   defer a.tomb.Done()
   log.Infof("machine agent %v start", a.Tag())
   if err := a.Conf.read(a.Tag()); err != nil {

Index: environs/cloudinit/cl...

Revision history for this message
Ian Booth (wallyworld) wrote :

LGTM, although I'd prefer to see an integration style test that confirms
that debug is used and then turned off as expected. We do this sort of
thing elsewhere for other similar "live" sets of tests.

https://codereview.appspot.com/13717044/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/jujud/machine.go'
2--- cmd/jujud/machine.go 2013-09-12 22:18:10 +0000
3+++ cmd/jujud/machine.go 2013-09-17 02:01:38 +0000
4@@ -10,6 +10,7 @@
5 "time"
6
7 "launchpad.net/gnuflag"
8+ "launchpad.net/loggo"
9 "launchpad.net/tomb"
10
11 "launchpad.net/juju-core/agent"
12@@ -97,6 +98,11 @@
13
14 // Run runs a machine agent.
15 func (a *MachineAgent) Run(_ *cmd.Context) error {
16+ // Due to changes in the logging, and needing to care about old
17+ // environments that have been upgraded, we need to explicitly remove the
18+ // file writer if one has been added, otherwise we will get duplicate
19+ // lines of all logging in the log file.
20+ loggo.RemoveWriter("logfile")
21 defer a.tomb.Done()
22 log.Infof("machine agent %v start", a.Tag())
23 if err := a.Conf.read(a.Tag()); err != nil {
24
25=== modified file 'environs/cloudinit/cloudinit.go'
26--- environs/cloudinit/cloudinit.go 2013-09-16 02:30:27 +0000
27+++ environs/cloudinit/cloudinit.go 2013-09-17 02:01:38 +0000
28@@ -147,13 +147,6 @@
29 fmt.Sprintf("echo -n %s > $bin/downloaded-url.txt", shquote(cfg.Tools.URL)),
30 )
31
32- // TODO (thumper): work out how to pass the logging config to the children
33- debugFlag := ""
34- // TODO: disable debug mode by default when the system is stable.
35- if true {
36- debugFlag = " --debug"
37- }
38-
39 if err := cfg.addLogging(c); err != nil {
40 return nil, err
41 }
42@@ -189,16 +182,17 @@
43 }
44 c.AddScripts(
45 fmt.Sprintf("echo %s > %s", shquote(cfg.StateInfoURL), BootstrapStateURLFile),
46+ // The bootstrapping is always run with debug on.
47 cfg.jujuTools()+"/jujud bootstrap-state"+
48 " --data-dir "+shquote(cfg.DataDir)+
49 " --env-config "+shquote(base64yaml(cfg.Config))+
50 " --constraints "+shquote(cfg.Constraints.String())+
51- debugFlag,
52+ " --debug",
53 "rm -rf "+shquote(acfg.Dir()),
54 )
55 }
56
57- if err := cfg.addMachineAgentToBoot(c, machineTag, cfg.MachineId, debugFlag); err != nil {
58+ if err := cfg.addMachineAgentToBoot(c, machineTag, cfg.MachineId); err != nil {
59 return nil, err
60 }
61
62@@ -279,7 +273,7 @@
63 return acfg, nil
64 }
65
66-func (cfg *MachineConfig) addMachineAgentToBoot(c *cloudinit.Config, tag, machineId, logConfig string) error {
67+func (cfg *MachineConfig) addMachineAgentToBoot(c *cloudinit.Config, tag, machineId string) error {
68 // Make the agent run via a symbolic link to the actual tools
69 // directory, so it can upgrade itself without needing to change
70 // the upstart script.
71@@ -288,7 +282,7 @@
72 c.AddScripts(fmt.Sprintf("ln -s %v %s", cfg.Tools.Version, shquote(toolsDir)))
73
74 name := "jujud-" + tag
75- conf := upstart.MachineAgentUpstartService(name, toolsDir, cfg.DataDir, "/var/log/juju/", tag, machineId, logConfig, nil)
76+ conf := upstart.MachineAgentUpstartService(name, toolsDir, cfg.DataDir, "/var/log/juju/", tag, machineId, nil)
77 cmds, err := conf.InstallCommands()
78 if err != nil {
79 return fmt.Errorf("cannot make cloud-init upstart script for the %s agent: %v", tag, err)
80
81=== modified file 'environs/cloudinit/cloudinit_test.go'
82--- environs/cloudinit/cloudinit_test.go 2013-09-16 02:30:27 +0000
83+++ environs/cloudinit/cloudinit_test.go 2013-09-17 02:01:38 +0000
84@@ -110,7 +110,7 @@
85 /var/lib/juju/tools/1\.2\.3-precise-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --env-config '[^']*' --constraints 'mem=2048M' --debug
86 rm -rf '/var/lib/juju/agents/bootstrap'
87 ln -s 1\.2\.3-precise-amd64 '/var/lib/juju/tools/machine-0'
88-cat >> /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju machine-0 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-0/jujud machine --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nEOF\\n
89+cat >> /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju machine-0 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-0/jujud machine --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nEOF\\n
90 start jujud-machine-0
91 `,
92 }, {
93@@ -174,7 +174,7 @@
94 /var/lib/juju/tools/1\.2\.3-raring-amd64/jujud bootstrap-state --data-dir '/var/lib/juju' --env-config '[^']*' --constraints 'mem=2048M' --debug
95 rm -rf '/var/lib/juju/agents/bootstrap'
96 ln -s 1\.2\.3-raring-amd64 '/var/lib/juju/tools/machine-0'
97-cat >> /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju machine-0 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-0/jujud machine --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nEOF\\n
98+cat >> /etc/init/jujud-machine-0\.conf << 'EOF'\\ndescription "juju machine-0 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-0/jujud machine --data-dir '/var/lib/juju' --machine-id 0 --debug >> /var/log/juju/machine-0\.log 2>&1\\nEOF\\n
99 start jujud-machine-0
100 `,
101 }, {
102@@ -216,7 +216,7 @@
103 install -m 600 /dev/null '/var/lib/juju/agents/machine-99/agent\.conf'
104 printf '%s\\n' '.*' > '/var/lib/juju/agents/machine-99/agent\.conf'
105 ln -s 1\.2\.3-linux-amd64 '/var/lib/juju/tools/machine-99'
106-cat >> /etc/init/jujud-machine-99\.conf << 'EOF'\\ndescription "juju machine-99 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-99/jujud machine --data-dir '/var/lib/juju' --machine-id 99 --debug >> /var/log/juju/machine-99\.log 2>&1\\nEOF\\n
107+cat >> /etc/init/jujud-machine-99\.conf << 'EOF'\\ndescription "juju machine-99 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-99/jujud machine --data-dir '/var/lib/juju' --machine-id 99 --debug >> /var/log/juju/machine-99\.log 2>&1\\nEOF\\n
108 start jujud-machine-99
109 `,
110 }, {
111@@ -259,7 +259,7 @@
112 install -m 600 /dev/null '/var/lib/juju/agents/machine-2-lxc-1/agent\.conf'
113 printf '%s\\n' '.*' > '/var/lib/juju/agents/machine-2-lxc-1/agent\.conf'
114 ln -s 1\.2\.3-linux-amd64 '/var/lib/juju/tools/machine-2-lxc-1'
115-cat >> /etc/init/jujud-machine-2-lxc-1\.conf << 'EOF'\\ndescription "juju machine-2-lxc-1 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-2-lxc-1/jujud machine --data-dir '/var/lib/juju' --machine-id 2/lxc/1 --debug >> /var/log/juju/machine-2-lxc-1\.log 2>&1\\nEOF\\n
116+cat >> /etc/init/jujud-machine-2-lxc-1\.conf << 'EOF'\\ndescription "juju machine-2-lxc-1 agent"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 20000 20000\\n\\nexec /var/lib/juju/tools/machine-2-lxc-1/jujud machine --data-dir '/var/lib/juju' --machine-id 2/lxc/1 --debug >> /var/log/juju/machine-2-lxc-1\.log 2>&1\\nEOF\\n
117 start jujud-machine-2-lxc-1
118 `,
119 },
120
121=== modified file 'provider/local/environ.go'
122--- provider/local/environ.go 2013-09-12 02:28:20 +0000
123+++ provider/local/environ.go 2013-09-17 02:01:38 +0000
124@@ -462,14 +462,13 @@
125 toolsDir := agenttools.ToolsDir(dataDir, tag)
126
127 logDir := env.config.logDir()
128- logConfig := "--debug" // TODO(thumper): specify loggo config
129 machineEnvironment := map[string]string{
130 "USER": env.config.user,
131 "HOME": osenv.Home(),
132 }
133 agentService := upstart.MachineAgentUpstartService(
134 env.machineAgentServiceName(),
135- toolsDir, dataDir, logDir, tag, machineId, logConfig, machineEnvironment)
136+ toolsDir, dataDir, logDir, tag, machineId, machineEnvironment)
137
138 agentService.InitDir = upstartScriptLocation
139 logger.Infof("installing service %s to %s", env.machineAgentServiceName(), agentService.InitDir)
140
141=== modified file 'upstart/service.go'
142--- upstart/service.go 2013-09-13 05:20:56 +0000
143+++ upstart/service.go 2013-09-17 02:01:38 +0000
144@@ -42,9 +42,11 @@
145
146 // MachineAgentUpstartService returns the upstart config for a machine agent
147 // based on the tag and machineId passed in.
148-func MachineAgentUpstartService(name, toolsDir, dataDir, logDir, tag, machineId, logConfig string, env map[string]string) *Conf {
149+func MachineAgentUpstartService(name, toolsDir, dataDir, logDir, tag, machineId string, env map[string]string) *Conf {
150 svc := NewService(name)
151 logFile := filepath.Join(logDir, tag+".log")
152+ // The machine agent always starts with debug turned on. The logger worker
153+ // will update this to the system logging environment as soon as it starts.
154 return &Conf{
155 Service: *svc,
156 Desc: fmt.Sprintf("juju %s agent", tag),
157@@ -55,7 +57,7 @@
158 " machine" +
159 " --data-dir " + utils.ShQuote(dataDir) +
160 " --machine-id " + machineId +
161- " " + logConfig,
162+ " --debug",
163 Out: logFile,
164 Env: env,
165 }

Subscribers

People subscribed via source and target branches

to status/vote changes: