-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update waiter compute delay util and adds waiter logger middleware
- Loading branch information
1 parent
c4c9a5d
commit b8cdbaa
Showing
5 changed files
with
114 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package rand | ||
|
||
import ( | ||
"crypto/rand" | ||
"fmt" | ||
"io" | ||
"math/big" | ||
) | ||
|
||
func init() { | ||
Reader = rand.Reader | ||
} | ||
|
||
// Reader provides a random reader that can reset during testing. | ||
var Reader io.Reader | ||
|
||
// Int63n returns a int64 between zero and value of max, read from an io.Reader source. | ||
func Int63n(reader io.Reader, max int64) (int64, error) { | ||
bi, err := rand.Int(reader, big.NewInt(max)) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to read random value, %w", err) | ||
} | ||
|
||
return bi.Int64(), nil | ||
} | ||
|
||
// CryptoRandInt63n returns a random int64 between zero and value of max | ||
//obtained from the crypto rand source. | ||
func CryptoRandInt63n(max int64) (int64, error) { | ||
return Int63n(Reader, max) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package waiter | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/awslabs/smithy-go/logging" | ||
"github.com/awslabs/smithy-go/middleware" | ||
) | ||
|
||
// Logger is the Logger middleware used by the waiter to log an attempt | ||
type Logger struct { | ||
// Attempt is the current attempt to be logged | ||
Attempt int64 | ||
} | ||
|
||
// ID representing the Logger middleware | ||
func (*Logger) ID() string { | ||
return "WaiterLogger" | ||
} | ||
|
||
// HandleInitialize performs handling of request in initialize stack step | ||
func (m *Logger) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) ( | ||
out middleware.InitializeOutput, metadata middleware.Metadata, err error, | ||
) { | ||
logger := middleware.GetLogger(ctx) | ||
|
||
logger.Logf(logging.Debug, fmt.Sprintf("attempting waiter request, attempt count: %d", m.Attempt)) | ||
|
||
return next.HandleInitialize(ctx, in) | ||
} | ||
|
||
// AddLogger is helper util to add waiter logger after `SetLogger` middleware in | ||
func (m Logger) AddLogger(stack *middleware.Stack) error { | ||
return stack.Initialize.Insert(&m, "SetLogger", middleware.After) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters