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

fix: time.Since should not be used in defer statement #2014

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ func NewImmuClient(options *Options) (*immuClient, error) {
return c, nil
}

func (c *immuClient) debugElapsedTime(method string, start time.Time) {
c.Logger.Debugf("method immuclient.%s took %s", method, time.Since(start))
}

func (c *immuClient) getServerIdentity() string {
// TODO: Allow customizing this value
return c.Options.Bind()
Expand Down Expand Up @@ -994,7 +998,7 @@ func (c *immuClient) CurrentState(ctx context.Context) (*schema.ImmutableState,
}

start := time.Now()
defer c.Logger.Debugf("Current state finished in %s", time.Since(start))
defer c.debugElapsedTime("CurrentState", start)

return c.ServiceClient.CurrentState(ctx, &empty.Empty{})
}
Expand All @@ -1006,7 +1010,7 @@ func (c *immuClient) Get(ctx context.Context, key []byte, opts ...GetOption) (*s
}

start := time.Now()
defer c.Logger.Debugf("get finished in %s", time.Since(start))
defer c.debugElapsedTime("Get", start)

req := &schema.KeyRequest{Key: key}
for _, opt := range opts {
Expand Down Expand Up @@ -1040,7 +1044,7 @@ func (c *immuClient) GetAtRevision(ctx context.Context, key []byte, rev int64) (
// Gets reads a single value for given key with additional server-provided proof validation.
func (c *immuClient) VerifiedGet(ctx context.Context, key []byte, opts ...GetOption) (vi *schema.Entry, err error) {
start := time.Now()
defer c.Logger.Debugf("VerifiedGet finished in %s", time.Since(start))
defer c.debugElapsedTime("VerifiedGet", start)

req := &schema.KeyRequest{Key: key}
for _, opt := range opts {
Expand Down Expand Up @@ -1307,7 +1311,7 @@ func (c *immuClient) VerifiedSet(ctx context.Context, key []byte, value []byte)
}

start := time.Now()
defer c.Logger.Debugf("VerifiedSet finished in %s", time.Since(start))
defer c.debugElapsedTime("VerifiedSet", start)

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down Expand Up @@ -1467,7 +1471,7 @@ func (c *immuClient) GetAll(ctx context.Context, keys [][]byte) (*schema.Entries
}

start := time.Now()
defer c.Logger.Debugf("get-batch finished in %s", time.Since(start))
defer c.debugElapsedTime("GetAll", start)

keyList := &schema.KeyListRequest{}

Expand Down Expand Up @@ -1495,12 +1499,11 @@ func (c *immuClient) TxByID(ctx context.Context, tx uint64) (*schema.Tx, error)
}

start := time.Now()
defer c.Logger.Debugf("by-index finished in %s", time.Since(start))
defer c.debugElapsedTime("TxByID", start)

t, err := c.ServiceClient.TxById(ctx, &schema.TxRequest{
Tx: tx,
})

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1533,7 +1536,7 @@ func (c *immuClient) VerifiedTxByID(ctx context.Context, tx uint64) (*schema.Tx,
}

start := time.Now()
defer c.Logger.Debugf("VerifiedTxByID finished in %s", time.Since(start))
defer c.debugElapsedTime("VerifiedTxByID", start)

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down Expand Up @@ -1619,7 +1622,7 @@ func (c *immuClient) History(ctx context.Context, req *schema.HistoryRequest) (s
}

start := time.Now()
defer c.Logger.Debugf("history finished in %s", time.Since(start))
defer c.debugElapsedTime("History", start)

return c.ServiceClient.History(ctx, req)
}
Expand All @@ -1640,7 +1643,7 @@ func (c *immuClient) SetReferenceAt(ctx context.Context, key []byte, referencedK
}

start := time.Now()
defer c.Logger.Debugf("SetReference finished in %s", time.Since(start))
defer c.debugElapsedTime("SetReferenceAt", start)

txhdr, err := c.ServiceClient.SetReference(ctx, &schema.ReferenceRequest{
Key: key,
Expand Down Expand Up @@ -1683,7 +1686,7 @@ func (c *immuClient) VerifiedSetReferenceAt(ctx context.Context, key []byte, ref
}

start := time.Now()
defer c.Logger.Debugf("safereference finished in %s", time.Since(start))
defer c.debugElapsedTime("VerifiedSetReferenceAt", start)

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down Expand Up @@ -1798,7 +1801,7 @@ func (c *immuClient) ZAddAt(ctx context.Context, set []byte, score float64, key
}

start := time.Now()
defer c.Logger.Debugf("zadd finished in %s", time.Since(start))
defer c.debugElapsedTime("ZAddAt", start)

hdr, err := c.ServiceClient.ZAdd(ctx, &schema.ZAddRequest{
Set: set,
Expand Down Expand Up @@ -1848,7 +1851,7 @@ func (c *immuClient) VerifiedZAddAt(ctx context.Context, set []byte, score float
}

start := time.Now()
defer c.Logger.Debugf("safezadd finished in %s", time.Since(start))
defer c.debugElapsedTime("VerifiedZAddAt", start)

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *immuClient) _streamVerifiedSet(ctx context.Context, kvs []*stream.KeyVa
defer c.StateService.CacheUnlock()

start := time.Now()
defer c.Logger.Debugf("StreamVerifiedSet finished in %s", time.Since(start))
defer c.debugElapsedTime("_streamVerifiedSet", start)

state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
if err != nil {
Expand Down
Loading