From b8b62f13483cacfc1cdd8af2a25e64dee7cd1495 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 10 Jan 2023 10:29:50 +0300 Subject: [PATCH 1/2] [#50] Use `native.connect` timeouts everywhere Also, use defaults from the SDK itself, allow user to provide 0. Signed-off-by: Evgenii Stratonikov --- README.md | 4 +++- examples/native.js | 2 +- examples/native_onsite.js | 2 +- internal/native/native.go | 9 +++++++-- scenarios/run_scenarios.md | 4 ++++ scenarios/verify.js | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 90e1ca0..a640c8e 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,12 @@ xk6 build --with github.com/TrueCloudLab/xk6-frostfs=. Create native client with `connect` method. Arguments: - frostfs storage node endpoint - hex encoded private key (empty value produces random key) +- dial timeout in seconds (0 for the default value) +- stream timeout in seconds (0 for the default value) ```js import native from 'k6/x/frostfs/native'; -const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "") +const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "", 0, 0) ``` ### Methods diff --git a/examples/native.js b/examples/native.js index d60fedc..45bb5fc 100644 --- a/examples/native.js +++ b/examples/native.js @@ -3,7 +3,7 @@ import {fail} from "k6"; import native from 'k6/x/frostfs/native'; const payload = open('../go.sum', 'b'); -const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb") +const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb", 0, 0) export const options = { stages: [ diff --git a/examples/native_onsite.js b/examples/native_onsite.js index 267080c..0ef6ce7 100644 --- a/examples/native_onsite.js +++ b/examples/native_onsite.js @@ -3,7 +3,7 @@ import native from 'k6/x/frostfs/native'; const payload = open('../go.sum', 'b'); const container = "AjSxSNNXbJUDPqqKYm1VbFVDGCakbpUNH8aGjPmGAH3B" -const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "") +const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "", 0, 0) const frostfs_obj = frostfs_cli.onsite(container, payload) export const options = { diff --git a/internal/native/native.go b/internal/native/native.go index 3e974c7..f09b729 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -74,8 +74,13 @@ func (n *Native) Connect(endpoint, hexPrivateKey string, dialTimeout, streamTime var prmDial client.PrmDial prmDial.SetServerURI(endpoint) - prmDial.SetTimeout(time.Duration(dialTimeout) * time.Second) - prmDial.SetStreamTimeout(time.Duration(streamTimeout) * time.Second) + if dialTimeout > 0 { + prmDial.SetTimeout(time.Duration(dialTimeout) * time.Second) + } + + if streamTimeout > 0 { + prmDial.SetStreamTimeout(time.Duration(streamTimeout) * time.Second) + } err = cli.Dial(prmDial) if err != nil { diff --git a/scenarios/run_scenarios.md b/scenarios/run_scenarios.md index 0a42706..c008cc6 100644 --- a/scenarios/run_scenarios.md +++ b/scenarios/run_scenarios.md @@ -39,6 +39,8 @@ Options (in addition to the common options): * `DELETERS` - number of VUs performing delete operations (using deleters requires that options `DELETE_AGE` and `REGISTRY_FILE` are specified as well). * `DELETE_AGE` - age of object in seconds before which it can not be deleted. This parameter can be used to control how many objects we have in the system under load. * `SLEEP_DELETE` - time interval (in seconds) between deleting VU iterations. + * `DIAL_TIMEOUT` - timeout to connect to a node (in seconds). + * `STREAM_TIMEOUT` - timeout for a single stream message for `PUT`/`GET` operations (in seconds). ## HTTP @@ -121,6 +123,8 @@ Options: * `REGISTRY_FILE` - database file from which objects for verification should be read. * `SLEEP` - time interval (in seconds) between VU iterations. * `SELECTION_SIZE` - size of batch to select for deletion (default: 1000). + * `DIAL_TIMEOUT` - timeout to connect to a node (in seconds). + * `STREAM_TIMEOUT` - timeout for a single stream message for `PUT`/`GET` operations (in seconds). ## Verify preset diff --git a/scenarios/verify.js b/scenarios/verify.js index a5c16ab..43bb018 100644 --- a/scenarios/verify.js +++ b/scenarios/verify.js @@ -25,7 +25,7 @@ let grpc_client = undefined; if (__ENV.GRPC_ENDPOINTS) { const grpcEndpoints = __ENV.GRPC_ENDPOINTS.split(','); const grpcEndpoint = grpcEndpoints[Math.floor(Math.random() * grpcEndpoints.length)]; - grpc_client = native.connect(grpcEndpoint, ''); + grpc_client = native.connect(grpcEndpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 0, __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 0); } // Connect to random S3 endpoint -- 2.45.2 From e2aa43ef39bc6fcbb4d01254dbb26e424250e583 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 1 Feb 2023 21:46:11 +0300 Subject: [PATCH 2/2] [#8] internal: Add full timestamp and endpoint to logs Signed-off-by: Evgenii Stratonikov --- internal/logging/log.go | 47 +++++++++++++++++++++++++++++++++++++++ internal/native/native.go | 5 +++++ internal/s3/s3.go | 5 +++++ 3 files changed, 57 insertions(+) create mode 100644 internal/logging/log.go diff --git a/internal/logging/log.go b/internal/logging/log.go new file mode 100644 index 0000000..3aa0c4e --- /dev/null +++ b/internal/logging/log.go @@ -0,0 +1,47 @@ +package logging + +import ( + "github.com/sirupsen/logrus" + "go.k6.io/k6/js/modules" +) + +// InitTimestamp makes `console.log` print full timestamp instead of raw seconds. +func InitTimestamp(vu modules.VU) { + lg, ok := vu.InitEnv().Logger.(*logrus.Logger) + if !ok { + return + } + + format := lg.Formatter + switch f := format.(type) { + case *logrus.TextFormatter: + f.ForceColors = true + f.FullTimestamp = true + f.TimestampFormat = "15:04:05" + case *logrus.JSONFormatter: + f.TimestampFormat = "15:04:05" + } +} + +// LogWithField adds default field to a modules.VU logger. +func LogWithField(vu modules.VU, name string, value interface{}) { + lg, ok := vu.InitEnv().Logger.(*logrus.Logger) + if !ok { + return + } + + lg.AddHook(defaultFieldHook{name: name, value: value}) +} + +type defaultFieldHook struct { + name string + value interface{} +} + +func (defaultFieldHook) Levels() []logrus.Level { + return []logrus.Level{logrus.InfoLevel} +} +func (h defaultFieldHook) Fire(e *logrus.Entry) error { + e.Data[h.name] = h.value + return nil +} diff --git a/internal/native/native.go b/internal/native/native.go index f09b729..8edf9bf 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -8,6 +8,7 @@ import ( "github.com/TrueCloudLab/frostfs-sdk-go/client" frostfsecdsa "github.com/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa" "github.com/TrueCloudLab/frostfs-sdk-go/session" + "github.com/TrueCloudLab/xk6-frostfs/internal/logging" "github.com/google/uuid" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "go.k6.io/k6/js/modules" @@ -41,6 +42,8 @@ func init() { // NewModuleInstance implements the modules.Module interface and returns // a new instance for each VU. func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { + logging.InitTimestamp(vu) + mi := &Native{vu: vu} return mi } @@ -52,6 +55,8 @@ func (n *Native) Exports() modules.Exports { } func (n *Native) Connect(endpoint, hexPrivateKey string, dialTimeout, streamTimeout int) (*Client, error) { + logging.LogWithField(n.vu, "endpoint", endpoint) + var ( cli client.Client pk *keys.PrivateKey diff --git a/internal/s3/s3.go b/internal/s3/s3.go index 965bd50..f2e5077 100644 --- a/internal/s3/s3.go +++ b/internal/s3/s3.go @@ -7,6 +7,7 @@ import ( "strconv" "time" + "github.com/TrueCloudLab/xk6-frostfs/internal/logging" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/s3" @@ -41,6 +42,8 @@ func init() { // NewModuleInstance implements the modules.Module interface and returns // a new instance for each VU. func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance { + logging.InitTimestamp(vu) + mi := &S3{vu: vu} return mi } @@ -52,6 +55,8 @@ func (s *S3) Exports() modules.Exports { } func (s *S3) Connect(endpoint string, params map[string]string) (*Client, error) { + logging.LogWithField(s.vu, "endpoint", endpoint) + resolver := aws.EndpointResolverWithOptionsFunc(func(_, _ string, _ ...interface{}) (aws.Endpoint, error) { return aws.Endpoint{ URL: endpoint, -- 2.45.2