Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDE-14 audit logging support #8

Merged
merged 8 commits into from
Feb 16, 2018
Merged

Conversation

emreathelix
Copy link
Contributor

No description provided.

VERSION Outdated
@@ -1 +1 @@
1.2.1
1.2.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't match version in Changelog. Seems like 1.3.0 is correct as this is adding functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops sorry about that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, easy to fix!

@@ -28,6 +29,8 @@ type RecordEventCallArgs struct {
}

type StructuredOutputLogProvider struct {
providers.LogProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually the first time I've looked at the way we do log chaining, so let me know if this is incorrect, but does the next provider have to be explicitly called in all the various log methods below? (Not seeing it being invoked elsewhere.) I.e., in func (p *StructuredOutputLogProvider) Error(...), you'd call

if p.nextProvider != nil {
    p.nextProvider.Error(ctx, report, args...)
}

And same for the other six methods defined in LogProvider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. Otherwise, it wouldn't really be chaining I guess.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good- feel free to check that with Chris if there's any ambiguity, since there could be something I'm missing.

rawLogCalls: rawLogCalls,
recordCalls: []RecordCallArgs{},
recordEventCalls: []RecordEventCallArgs{},
}

if nextProvider != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible to test the behavior of this block in the unit tests? The rest of this method is already covered, so you'd just need to add a test for nextProvider == nil/another for nextProvider != nil.

"Metric 3": "Value 3",
"Metric 4": "Value 4",
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think you should also test that calling lp.Wait() causes lp.nextProvider.Wait() to be called. Looks like you could use dummy/provider as essentially a mock for nextProvider, to accomplish that verification.

Copy link
Contributor

@jpecknerhelix jpecknerhelix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM- just need to add the additional test for Wait() that I commented on

@emreathelix
Copy link
Contributor Author

Thanks for all the help @jpecknerhelix

@@ -186,6 +186,17 @@ var _ = Describe("bufferedLogProvider", func() {
Ω(lp.LogProvider).Should(Equal(chaining.LogProvider(dummyProvider)))
})

It("Should call wait on the next provider", func() {
ws := new(dummy.WaitState)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add Ω(ws.Get()).Should(BeFalse()) after this line as a sanity check

@jpecknerhelix
Copy link
Contributor

No problem! Btw, are the unit tests for the reported_at suite failing on your machine too? I'm seeing this in the last few master commits, so it wasn't introduced in this branch. So IMO it's not a blocker for this PR.

@jpecknerhelix
Copy link
Contributor

^ @emreathelix, CC: @chriswhelix

@emreathelix
Copy link
Contributor Author

@jpecknerhelix All tests are passing for me both on master and this branch. Make sure you've run glide up, glide install

@jpecknerhelix
Copy link
Contributor

Weird, I'm actually seeing more errors after running glide up and glide install.

@jpecknerhelix
Copy link
Contributor

Created a ticket in JIRA for the failing test issue.

log/log.go Outdated
@@ -24,6 +24,10 @@ func SetDefaultProvider(provider providers.LogProvider) {
defaultProvider = provider
}

func GetDefaultProvider() providers.LogProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idiomatic name in Go should be just DefaultProvider().

rawLogCalls: rawLogCalls,
recordCalls: []RecordCallArgs{},
recordEventCalls: []RecordEventCallArgs{},
}

if nextProvider != nil {
lp.LogProvider = chaining.LogProvider(nextProvider)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you want to do is here always set lp.LogProvider to the chaining provider, even if nextProvider is nil; then you don't need to bother with all the nil-checking in individual methods, because the chaining provider does it for you (that's its main job).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok.. Didn't check the internals of the chaining provider.

if p.LogProvider != nil {
p.LogProvider.Wait()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to implement this at all; the chaining provider will give you an empty default implementation.

return LogProvider(nil).(*StructuredOutputLogProvider)
}

func LogProvider(nextProvider providers.LogProvider) providers.LogProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need two different constructors here, with different signatures?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because NewStructuredOutputLogProvider() is already being used in other services. I didn't wanna break any existing functionality.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, OK. Let's mark the old one deprecated using the Go convention (see: https://rakyll.org/deprecated/), and have this also return *StructuredOutputLogProvider to avoid awkward casting of its result.

Copy link
Contributor

@chriswhelix chriswhelix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@emreathelix emreathelix merged commit 777300c into master Feb 16, 2018
@emreathelix emreathelix deleted the HDE-14-audit-logging-support branch February 16, 2018 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants