Refactor logsink to make it reusable for migration log transfer #6573

Merged
merged 6 commits into from Nov 20, 2016

Conversation

Projects
None yet
3 participants
Member

babbageclunk commented Nov 17, 2016

Extract the authentication and logging that the logsink handler does into AgentLoggingStrategy. This enables using a different logging strategy for migration log transfer (which will be in a follow-up PR) - in that case the logs won't be coming from a specific machine agent so each record will include the entity that originally logged it.

This also slightly changes the format of logsink.log - entity is moved from the line prefix to a normal column in the log file.

Member

babbageclunk commented Nov 18, 2016

This appears to be a spurious failure caused by Mongo dropping all connections on Windows.

Member

babbageclunk commented Nov 18, 2016

!!build!!

Member

babbageclunk commented Nov 18, 2016

Weird error from mongo:

/home/ubuntu/juju-core_2.1-beta2/src/github.com/juju/testing/mgo.go:449:
    c.Assert(err, jc.ErrorIsNil)
... value *net.OpError = &net.OpError{Op:"local error", Net:"", Source:net.Addr(nil), Addr:net.Addr(nil), Err:0xa} ("local error: unexpected message")
Member

babbageclunk commented Nov 18, 2016

!!build!!

apiserver/logsink.go
"gopkg.in/natefinch/lumberjack.v2"
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/state"
)
-func newLogSinkHandler(h httpContext, w io.Writer) http.Handler {
- return &logSinkHandler{ctxt: h, fileLogger: w}
+type LoggingStrategy interface {
@howbazaar

howbazaar Nov 18, 2016

Owner

Need a docstring for this

apiserver/logsink.go
}
-func newLogSinkWriter(logDir string) (io.WriteCloser, error) {
- logPath := filepath.Join(logDir, "logsink.log")
+type AgentLoggingStrategy struct {
@howbazaar

howbazaar Nov 18, 2016

Owner

This doesn't need to be exported if the new func returns the interface

@babbageclunk

babbageclunk Nov 20, 2016

Member

No, good point. In fact all of this is internal to the package. I left the interface and its methods as public because it feels weird to define a private interface.

apiserver/logsink.go
+ fileLogger io.Writer
+}
+
+func (s *AgentLoggingStrategy) Authenticate(req *http.Request) error {
@howbazaar

howbazaar Nov 18, 2016

Owner

Docstring

apiserver/logsink.go
+ return nil
+}
+
+func (s *AgentLoggingStrategy) Start() {
@howbazaar

howbazaar Nov 18, 2016

Owner

Docstring here too.

apiserver/logsink.go
+ s.dbLogger = state.NewEntityDbLogger(s.st, s.entity, s.version)
+}
+
+func (s *AgentLoggingStrategy) Log(m params.LogRecord) bool {
@howbazaar

howbazaar Nov 18, 2016

Owner

And this one

apiserver/logsink.go
+ return dbErr == nil && fileErr == nil
+}
+
+func (s *AgentLoggingStrategy) Stop() {
@howbazaar

howbazaar Nov 18, 2016

Owner

And here. I'm assuming that once you have stopped, you can never start again?

@babbageclunk

babbageclunk Nov 20, 2016

Member

Yeah, I've mentioned that in the comment.

apiserver/logsink.go
@@ -175,9 +218,10 @@ func (h *logSinkHandler) sendError(w io.Writer, req *http.Request, err error) {
}
// logToFile writes a single log message to the logsink log file.
-func (h *logSinkHandler) logToFile(prefix string, m params.LogRecord) error {
- _, err := h.fileLogger.Write([]byte(strings.Join([]string{
+func logToFile(logger io.Writer, prefix string, m params.LogRecord) error {
@howbazaar

howbazaar Nov 18, 2016

Owner

logger is often used as a global loggo.Logger variable name. Perhaps use "writer" here?

@@ -189,8 +189,8 @@ func (s *logsinkSuite) TestLogging(c *gc.C) {
logPath := filepath.Join(s.LogDir, "logsink.log")
logContents, err := ioutil.ReadFile(logPath)
c.Assert(err, jc.ErrorIsNil)
- line0 := modelUUID + " machine-0: 2015-06-01 23:02:01 INFO some.where foo.go:42 all is well\n"
- line1 := modelUUID + " machine-0: 2015-06-01 23:02:02 ERROR else.where bar.go:99 oh noes\n"
+ line0 := modelUUID + ": machine-0 2015-06-01 23:02:01 INFO some.where foo.go:42 all is well\n"
@howbazaar

howbazaar Nov 18, 2016

Owner

Why did the colon move?

@babbageclunk

babbageclunk Nov 20, 2016

Member

Because the entity stopped being part of the prefix and started being part of the log record. I got the impression from Menno that the log is for backup but anything that wants the data structured is reading from the DB, so a small change to the format here wouldn't be a problem. Do you think that's right?

@howbazaar

howbazaar Nov 20, 2016

Owner

Yeah, the logsink is purely a last ditch backup if neeeded. It is fine, I was just wondering.

babbageclunk added some commits Nov 7, 2016

Rename state.DbLogger to EntityDbLogger
In preparation for making a DbLogger that isn't entity-specific.
Add DbLogger for logging from any entity
This will be used for log records transferred as part of migration.
Decouple the logsink handler from EntityDbLogger
We want to use this endpoint for migration log transfer as well - the
LoggingStrategy captures the authentication and logging so that we can
do slightly different things for the migration endpoint.

Because the file logger isn't created per-request, it gets passed in
when creating the strategy.
Pass the full logfile name into newLogSinkWriter
This will let us use a different logfile for the migration logsink
endpoint.
Add entity to params.LogRecord
Move it from the line prefix to the line proper in the log file - it'll
be passed in on the log record in the migration version of the endpoint.
func (s *ConfigSuite) TestDefaultsPassValidation(c *gc.C) {
attrs := testing.FakeConfig().Merge(testing.Attrs{
- "type": "rackspace",
+ "type": "rackspace",
@howbazaar

howbazaar Nov 20, 2016

Owner

Hmm I just did this one too.

@babbageclunk

babbageclunk Nov 20, 2016

Member

I probably should have pushed it with no-verify instead.

Member

babbageclunk commented Nov 20, 2016

$$merge$$

On Mon, 21 Nov 2016, 11:19 Tim Penhey, notifications@github.com wrote:

@howbazaar approved this pull request.

In provider/rackspace/config_test.go
#6573 (review):

func (s *ConfigSuite) TestDefaultsPassValidation(c *gc.C) {
attrs := testing.FakeConfig().Merge(testing.Attrs{

  • "type":                  "rackspace",
    
  • "type": "rackspace",
    

Hmm I just did this one too.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#6573 (review), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAiYx1B4Wco1NEScg5lP3FkDGZNLAkguks5rAMdigaJpZM4K024T
.

Contributor

jujubot commented Nov 20, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit c0faeca into juju:develop Nov 20, 2016

@babbageclunk babbageclunk deleted the babbageclunk:logsink-refactor branch Nov 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment