audit-log: Walk reply structs to collect errors #8225

Merged
merged 1 commit into from Dec 14, 2017

Conversation

Projects
None yet
3 participants
Member

babbageclunk commented Dec 14, 2017

Description of change

We want to be able to reflect any errors from API methods in the audit log. Since the responses could have any number of errors, we collect them from the response by looking for *Error attributes or slices of result objects with *Error attributes.

QA steps

Bootstrap a controller with auditing enabled. Deploy 2 units of ubuntu. Then run juju remove-unit ubuntu/3 ubuntu/1 ubuntu/2. In the audit log you should see the conversation with the remove-unit command, the corresponding Application.DestroyUnit method call, and the error response with:

[{"message":"unit \"ubuntu/3" does not exist","code":""},null,{"message":"unit \"ubuntu/2\" does not exist","code":""}]]

The null in the middle corresponds to the successful removal of ubuntu/1.

Member

babbageclunk commented Dec 14, 2017

That looks like a spurious failure - retrying here.

Looks good, just an optimisation.

+ }
+
+ result := make([]*params.Error, value.Len())
+ for i := 0; i < value.Len(); i++ {
@wallyworld

wallyworld Dec 14, 2017

Owner

This will leave nil values in the result slice, is that intended?
I guess so because that will result in a nil auditlog.Error value?

@babbageclunk

babbageclunk Dec 14, 2017

Member

Yes, that was intentional - although maybe I can make that clearer if by using append instead.

apiserver/observer/recorder.go
+ item := value.Index(i)
+ // We know item's a struct.
+ errorValue := item.Field(errorField)
+ if errorValue.CanInterface() {
@wallyworld

wallyworld Dec 14, 2017

Owner

Can we use tryErrorPointer() here?
if errVal, ok := tryErrorPointer(errorValue); ok {
result[i] = errVal
}

or even

result[i], _ = tryErrorPointer(errorValue)

@babbageclunk

babbageclunk Dec 14, 2017

Member

Oh yeah - in fact, I think that was why I originally split it out!

Member

babbageclunk commented Dec 14, 2017

$$merge$$

Contributor

jujubot commented Dec 14, 2017

Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju

@jujubot jujubot merged commit 71750c5 into juju:2.3 Dec 14, 2017

1 check passed

continuous-integration/jenkins/pr-merge This commit looks good
Details

@babbageclunk babbageclunk deleted the babbageclunk:audit-errors branch Dec 15, 2017

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