coreos / mayday

A diagnostics tool for capturing system state.
Apache License 2.0
80 stars 27 forks source link

Rewrite Mayday #29

Closed tschuy closed 8 years ago

tschuy commented 8 years ago

I rewrote mayday so all file operations are done in /mayday.go. This means it's possible to test things in /mayday/* without touching the filesystem.

Architectural changes:

Other changes:

Things I'm not sure on:

tschuy commented 8 years ago

@brianredbeard

colhom commented 8 years ago

configuration file! This I'm not 100% sure on. Right now it's just being read from the filesystem, in ../config.json from wherever the binary mayday is built (defaulting to bin/mayday). Obviously this isn't ideal; where should I put this? Should it even be separate?

A few points here:

What should I do with the other parts of the build script that mess with go env variables?

If you've switched from Godeps to using vendor and everything is working, good enough for now. Either @brianredbeard or I will clean up at a later date.

bump Travis to Go 1.6, and remove 1.4/1.5. This is necessary with vendoring.

I'm fine with go 1.6 or higher for our build environment.

testing journal.go. We can't just assume a system has systemd on it, and even if we do, we still don't want to touch the filesystem.

We'll treat journal.go as you would database access code or an API wrapper- we will consider it to be an external component and only seek to allow other components to unit test against it.

The way you have it is pretty ideal- it's basically just shelling out to journalctl... not really much to go wrong. We can perhaps write some integration tests which exercise it, but for now we'll just stub it out so other components can unit test against the Journal interface. (yes, more interfaces)

Great job intern.

tschuy commented 8 years ago

Ok, I've addressed pretty much all of the feedback except things relating to the journals (and the for loops). Tar now accepts a Tarable as its argument for .Add(), which is super nice.

tschuy commented 8 years ago

If I switch to for..range loops, then I have to deal with go copying the objects around like there's no tomorrow, which breaks some of my pointer passing because it reuses the objects it's copying into. it's easier to just use the "classic" for loops.

tschuy commented 8 years ago

Looking at your comments on Journal, now that it's just a Tarable like everything else the only parts there are to test are really

EDIT: Looked into mocking, it's stupendously easy in go, wow.

tschuy commented 8 years ago

Ok, this is ready to go pretty much I think. I didn't write any testing for the .Run() part of the journal, since as it turns out mocking is actually slightly harder than I thought with external libraries. (I'd have to do something like this.)

I'll keep poking at it, but for now I think I'm ready for this to be reviewed (and hopefully merged!)

tschuy commented 8 years ago

Ok, I've fixed the minor cleanup things (cbytes[:], for..range, renaming File to MaydayFile), and factored out SystemdJournal just a little bit so that it's slightly more testable.

We're up to:

colhom commented 8 years ago

LGTM!!

colhom commented 8 years ago

@tschuy maybe squash up into a few indicative milestones before the final merge. We have a lot of commits right now

tschuy commented 8 years ago

I've squashed everything into a slightly more reasonable number of commits. @colhom the only thing that's changed since you last checked it out is I got rid of .Run() as a Tarable interface method, and it's now called if necessary when accessing .Content() or .Header().

brianredbeard commented 8 years ago

LGTM

:+1: