Merge lp:~jameinel/juju-core/log-mongo-version into lp:~go-bot/juju-core/trunk

Proposed by John A Meinel
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 2646
Proposed branch: lp:~jameinel/juju-core/log-mongo-version
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 164 lines (+36/-13)
4 files modified
agent/mongo/mongo.go (+21/-7)
agent/mongo/mongo_test.go (+12/-3)
provider/openstack/local_test.go (+2/-2)
worker/provisioner/provisioner_task.go (+1/-1)
To merge this branch: bzr merge lp:~jameinel/juju-core/log-mongo-version
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+215656@code.launchpad.net

Commit message

agent/mongo: log version of mongo

Just before we start mongo, log the version so we know what we're
running. This is mostly just to aid us in debugging log files from
other people.

https://codereview.appspot.com/87570043/

Description of the change

agent/mongo: log version of mongo

Just before we start mongo, log the version so we know what we're
running. This is mostly just to aid us in debugging log files from
other people.

https://codereview.appspot.com/87570043/

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Reviewers: mp+215656_code.launchpad.net,

Message:
Please take a look.

Description:
agent/mongo: log version of mongo

Just before we start mongo, log the version so we know what we're
running. This is mostly just to aid us in debugging log files from
other people.

https://code.launchpad.net/~jameinel/juju-core/log-mongo-version/+merge/215656

(do not edit description out of merge proposal)

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

Affected files (+22, -0 lines):
   A [revision details]
   M agent/mongo/mongo.go
   M agent/mongo/mongo_test.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-20140414112125-eouvcipf4rmjrahn
+New revision: <email address hidden>

Index: agent/mongo/mongo.go
=== modified file 'agent/mongo/mongo.go'
--- agent/mongo/mongo.go 2014-04-12 09:18:12 +0000
+++ agent/mongo/mongo.go 2014-04-14 12:39:38 +0000
@@ -251,6 +251,17 @@
   return nil
  }

+func logMongoVersion(mongopath string) {
+ logger.Debugf("found mongod at: %s", mongopath)
+ cmd := exec.Command(mongopath, "--version")
+ output, err := cmd.CombinedOutput()
+ if err != nil {
+ logger.Infof("failed to read the output from %s --version", mongopath)
+ return
+ }
+ logger.Debugf("mongod --version:\n%s", string(output))
+}
+
  // mongoUpstartService returns the upstart config for the mongo state
service.
  //
  // This method assumes there exist "server.pem" and "shared_secret"
keyfiles in dataDir.
@@ -267,6 +278,7 @@
   if err != nil {
    return nil, err
   }
+ logMongoVersion(mongopath)

   conf := &upstart.Conf{
    Service: *svc,

Index: agent/mongo/mongo_test.go
=== modified file 'agent/mongo/mongo_test.go'
--- agent/mongo/mongo_test.go 2014-04-11 19:48:39 +0000
+++ agent/mongo/mongo_test.go 2014-04-14 12:39:38 +0000
@@ -119,6 +119,14 @@
   err = EnsureMongoServer(dir, port, namespace)
   c.Assert(err, gc.IsNil)
   c.Assert(svc.Installed(), jc.IsTrue)
+
+ // make sure that we log the version of mongodb as we get ready to
+ // start it
+ tlog := c.GetTestLog()
+ any := `(.|\n)*`
+ start := "^" + any
+ tail := any + "$"
+ c.Assert(tlog, gc.Matches, start+`mongod --version:\ndb version
v2\.\d+\.\d+`+tail)
  }

  func (s *MongoSuite) TestNoMongoDir(c *gc.C) {

Revision history for this message
Nate Finch (natefinch) wrote :

lgtm, a couple minor suggestions.

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go
File agent/mongo/mongo.go (right):

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go#newcode255
agent/mongo/mongo.go:255: logger.Debugf("found mongod at: %s",
mongopath)
maybe put this after the err check, just on the off chance we *don't*
find mongo there? or change the message to "checking version of mongo
at <path>?

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go#newcode259
agent/mongo/mongo.go:259: logger.Infof("failed to read the output from
%s --version", mongopath)
should we log the error? it could be "mongod not found"

https://codereview.appspot.com/87570043/

Revision history for this message
Roger Peppe (rogpeppe) wrote :

LGTM modulo the suggestions below.

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go
File agent/mongo/mongo.go (right):

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go#newcode259
agent/mongo/mongo.go:259: logger.Infof("failed to read the output from
%s --version", mongopath)
On 2014/04/16 10:47:20, nate.finch wrote:
> should we log the error? it could be "mongod not found"

the error is often not very useful actually.
it may be that the command returns a non-zero exit
status but actually produced some useful output.

worth logging the output too (with %q), I think, when there is an error.

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go#newcode262
agent/mongo/mongo.go:262: logger.Debugf("mongod --version:\n%s",
string(output))
I think this should be an Infof.

Also, no need for the string conversion (%s formats []byte
correctly as a string)

Additionally I'm not that keen on log messages with embedded newlines.
How about stripping space and using %q? Then the log line will look
like:

mongod --version: "db version v2.4.9\nWed Apr 16 12:25:32.774 git
version: nogitversion"

which looks pretty good to me and is easily greppable.

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go#newcode281
agent/mongo/mongo.go:281: logMongoVersion(mongopath)
I'm not sure this is a great place for this log message.
It seems like we're putting the log message here as
a side effect in a function that is otherwise side-effect
free.

Two possibilities:
1) make mongoUpstartService return the version string
2) make mongoUpstartService return the mongod executable
path and call logMongoVersion from EnsureMongoServer.

I think I prefer the latter.

https://codereview.appspot.com/87570043/

Revision history for this message
John A Meinel (jameinel) wrote :

Please take a look.

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go
File agent/mongo/mongo.go (right):

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go#newcode255
agent/mongo/mongo.go:255: logger.Debugf("found mongod at: %s",
mongopath)
On 2014/04/16 10:47:20, nate.finch wrote:
> maybe put this after the err check, just on the off chance we *don't*
find mongo
> there? or change the message to "checking version of mongo at <path>?

I originally had it as one message, but then I wanted to make sure to
log something on error. But I realize we'll have that data as long as we
put the path in the output, so I'll fix it to just at the end. (Nicer
not to have lots of lines anyway.

https://codereview.appspot.com/87570043/diff/1/agent/mongo/mongo.go#newcode259
agent/mongo/mongo.go:259: logger.Infof("failed to read the output from
%s --version", mongopath)
On 2014/04/16 10:47:20, nate.finch wrote:
> should we log the error? it could be "mongod not found"

logged

https://codereview.appspot.com/87570043/

Revision history for this message
Go Bot (go-bot) wrote :

Attempt to merge into lp:juju-core failed due to conflicts:

text conflict in agent/mongo/mongo.go
text conflict in agent/mongo/mongo_test.go

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'agent/mongo/mongo.go'
2--- agent/mongo/mongo.go 2014-04-15 15:12:49 +0000
3+++ agent/mongo/mongo.go 2014-04-17 12:10:55 +0000
4@@ -121,6 +121,7 @@
5
6 path, err := exec.LookPath("mongod")
7 if err != nil {
8+ logger.Infof("could not find %v or mongod in $PATH", JujuMongodPath)
9 return "", err
10 }
11 return path, nil
12@@ -185,10 +186,11 @@
13 return fmt.Errorf("cannot install mongod: %v", err)
14 }
15
16- upstartConf, err := mongoUpstartService(namespace, dataDir, dbDir, info.StatePort, withHA)
17+ upstartConf, mongoPath, err := mongoUpstartService(namespace, dataDir, dbDir, info.StatePort, withHA)
18 if err != nil {
19 return err
20 }
21+ logMongoVersion(mongoPath)
22
23 // TODO(natefinch) 2014-04-12 https://launchpad.net/bugs/1306902
24 // remove this once we support upgrading to HA
25@@ -247,6 +249,16 @@
26 return nil
27 }
28
29+func logMongoVersion(mongoPath string) {
30+ cmd := exec.Command(mongoPath, "--version")
31+ output, err := cmd.CombinedOutput()
32+ if err != nil {
33+ logger.Infof("failed to read the output from %s --version: %v", mongoPath, err)
34+ return
35+ }
36+ logger.Debugf("using mongod: %s --version: %q", mongoPath, output)
37+}
38+
39 func sslKeyPath(dataDir string) string {
40 return filepath.Join(dataDir, "server.pem")
41 }
42@@ -256,14 +268,16 @@
43 }
44
45 // mongoUpstartService returns the upstart config for the mongo state service.
46-//
47-func mongoUpstartService(namespace, dataDir, dbDir string, port int, withHA bool) (*upstart.Conf, error) {
48+// It also returns the path to the mongod executable that the upstart config
49+// will be using.
50+func mongoUpstartService(namespace, dataDir, dbDir string, port int, withHA bool) (*upstart.Conf, string, error) {
51 svc := upstart.NewService(ServiceName(namespace))
52
53 mongoPath, err := MongodPath()
54 if err != nil {
55- return nil, err
56+ return nil, "", err
57 }
58+
59 mongoCmd := mongoPath + " --auth" +
60 " --dbpath=" + utils.ShQuote(dbDir) +
61 " --sslOnNormalPorts" +
62@@ -287,7 +301,7 @@
63 },
64 Cmd: mongoCmd,
65 }
66- return conf, nil
67+ return conf, mongoPath, nil
68 }
69
70 func aptGetInstallMongod() error {
71@@ -334,11 +348,11 @@
72 func mongoNoauthCommand(dataDir string, port int) (*exec.Cmd, error) {
73 sslKeyFile := path.Join(dataDir, "server.pem")
74 dbDir := filepath.Join(dataDir, "db")
75- mongopath, err := MongodPath()
76+ mongoPath, err := MongodPath()
77 if err != nil {
78 return nil, err
79 }
80- cmd := exec.Command(mongopath,
81+ cmd := exec.Command(mongoPath,
82 "--noauth",
83 "--dbpath", dbDir,
84 "--sslOnNormalPorts",
85
86=== modified file 'agent/mongo/mongo_test.go'
87--- agent/mongo/mongo_test.go 2014-04-15 16:01:43 +0000
88+++ agent/mongo/mongo_test.go 2014-04-17 12:10:55 +0000
89@@ -49,11 +49,12 @@
90 }
91
92 func (s *MongoSuite) SetUpTest(c *gc.C) {
93+ s.LoggingSuite.SetUpTest(c)
94 // Try to make sure we don't execute any commands accidentally.
95 s.PatchEnvironment("PATH", "")
96
97 s.mongodPath = filepath.Join(c.MkDir(), "mongod")
98- err := ioutil.WriteFile(s.mongodPath, nil, 0755)
99+ err := ioutil.WriteFile(s.mongodPath, []byte("#!/bin/bash\n\nprintf %s 'db version v2.4.9'\n"), 0755)
100 c.Assert(err, gc.IsNil)
101 s.PatchValue(&JujuMongodPath, s.mongodPath)
102
103@@ -158,16 +159,24 @@
104 err = EnsureMongoServer(dataDir, namespace, testInfo, WithHA)
105 c.Assert(err, gc.IsNil)
106 assertInstalled()
107+
108+ // make sure that we log the version of mongodb as we get ready to
109+ // start it
110+ tlog := c.GetTestLog()
111+ any := `(.|\n)*`
112+ start := "^" + any
113+ tail := any + "$"
114+ c.Assert(tlog, gc.Matches, start+`using mongod: .*/mongod --version: "db version v2\.4\.9`+tail)
115 }
116
117 func (s *MongoSuite) TestMongoUpstartServiceWithHA(c *gc.C) {
118 dataDir := c.MkDir()
119
120- svc, err := mongoUpstartService("", dataDir, dataDir, 1234, WithHA)
121+ svc, _, err := mongoUpstartService("", dataDir, dataDir, 1234, WithHA)
122 c.Assert(err, gc.IsNil)
123 c.Assert(strings.Contains(svc.Cmd, "--replSet"), jc.IsTrue)
124
125- svc, err = mongoUpstartService("", dataDir, dataDir, 1234, WithoutHA)
126+ svc, _, err = mongoUpstartService("", dataDir, dataDir, 1234, WithoutHA)
127 c.Assert(err, gc.IsNil)
128 c.Assert(strings.Contains(svc.Cmd, "--replSet"), jc.IsFalse)
129 }
130
131=== modified file 'provider/openstack/local_test.go'
132--- provider/openstack/local_test.go 2014-04-08 15:51:39 +0000
133+++ provider/openstack/local_test.go 2014-04-17 12:10:55 +0000
134@@ -334,7 +334,7 @@
135 }
136 }
137 if !found {
138- c.Errorf("expected security group %g not found", name)
139+ c.Errorf("expected security group %q not found", name)
140 }
141 }
142 for _, group := range groups {
143@@ -346,7 +346,7 @@
144 }
145 }
146 if !found {
147- c.Errorf("existing security group %g is not expected", group.Name)
148+ c.Errorf("existing security group %q is not expected", group.Name)
149 }
150 }
151 }
152
153=== modified file 'worker/provisioner/provisioner_task.go'
154--- worker/provisioner/provisioner_task.go 2014-04-11 15:16:00 +0000
155+++ worker/provisioner/provisioner_task.go 2014-04-17 12:10:55 +0000
156@@ -481,7 +481,7 @@
157
158 err = machine.SetInstanceInfo(inst.Id(), nonce, metadata, networks, ifaces)
159 if err != nil && params.IsCodeNotImplemented(err) {
160- return fmt.Errorf("cannot provision instance %v for machine %q with networks: not implemented")
161+ return fmt.Errorf("cannot provision instance %v for machine %q with networks: not implemented", inst.Id(), machine)
162 } else if err == nil {
163 logger.Infof("started machine %s as instance %s with hardware %q, networks %v, interfaces %v", machine, inst.Id(), metadata, networks, ifaces)
164 return nil

Subscribers

People subscribed via source and target branches

to status/vote changes: