From 32302d8d24ab28d6ec203e579e9ed8787e23c712 Mon Sep 17 00:00:00 2001 From: mitz Date: Thu, 4 Jul 2019 16:08:28 +0900 Subject: [PATCH 1/2] [audit] No longer record state transition Also, show graphql request log. --- gql/resolver_impl.go | 12 ++++++++++++ models/etcd/machine.go | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gql/resolver_impl.go b/gql/resolver_impl.go index d8ec4c43..76a31c5d 100644 --- a/gql/resolver_impl.go +++ b/gql/resolver_impl.go @@ -9,6 +9,7 @@ import ( "sort" "time" + "github.com/cybozu-go/log" "github.com/cybozu-go/sabakan/v2" "github.com/vektah/gqlparser/gqlerror" ) @@ -110,6 +111,11 @@ type mutationResolver struct{ *Resolver } func (r *mutationResolver) SetMachineState(ctx context.Context, serial string, state sabakan.MachineState) (*sabakan.MachineStatus, error) { now := time.Now() + log.Info("SetMachineState is called", map[string]interface{}{ + "serial": serial, + "state": state, + }) + err := r.Model.Machine.SetState(ctx, serial, state) if err != nil { switch err { @@ -184,6 +190,12 @@ func (r *queryResolver) Machine(ctx context.Context, serial string) (*sabakan.Ma } func (r *queryResolver) SearchMachines(ctx context.Context, having, notHaving *MachineParams) ([]sabakan.Machine, error) { now := time.Now() + + log.Info("SearchMachines is called", map[string]interface{}{ + "having": having, + "notHaving": notHaving, + }) + machines, err := r.Model.Machine.Query(ctx, sabakan.Query{}) if err != nil { return nil, err diff --git a/models/etcd/machine.go b/models/etcd/machine.go index d10c6f06..299775d5 100644 --- a/models/etcd/machine.go +++ b/models/etcd/machine.go @@ -154,8 +154,6 @@ RETRY: } } - d.addLog(ctx, time.Now(), tresp.Header.Revision, sabakan.AuditMachines, serial, - "state", state.String()) return nil } From 86d57b9c180af13bac133c5c89198950591fc089 Mon Sep 17 00:00:00 2001 From: mitz Date: Thu, 4 Jul 2019 17:46:00 +0900 Subject: [PATCH 2/2] Fix log format --- gql/resolver_impl.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gql/resolver_impl.go b/gql/resolver_impl.go index 76a31c5d..9b75723f 100644 --- a/gql/resolver_impl.go +++ b/gql/resolver_impl.go @@ -181,6 +181,11 @@ type queryResolver struct{ *Resolver } func (r *queryResolver) Machine(ctx context.Context, serial string) (*sabakan.Machine, error) { now := time.Now() + + log.Info("Machine is called", map[string]interface{}{ + "serial": serial, + }) + machine, err := r.Model.Machine.Get(ctx, serial) if err != nil { return &sabakan.Machine{}, err @@ -193,7 +198,7 @@ func (r *queryResolver) SearchMachines(ctx context.Context, having, notHaving *M log.Info("SearchMachines is called", map[string]interface{}{ "having": having, - "notHaving": notHaving, + "nothaving": notHaving, }) machines, err := r.Model.Machine.Query(ctx, sabakan.Query{})