Add full timestamp and endpoint to logs #8

Merged
fyrchik merged 2 commits from k6-update into master 2023-02-03 14:12:26 +00:00
8 changed files with 74 additions and 6 deletions

View file

@ -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

View file

@ -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: [

View file

@ -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 = {

47
internal/logging/log.go Normal file
View file

@ -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
}

View file

@ -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
@ -74,8 +79,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 {

View file

@ -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,

View file

@ -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

View file

@ -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