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

stream/multiconnection: Default process reporter #1734

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 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
1 change: 1 addition & 0 deletions config/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ type Exchange struct {
HTTPTimeout time.Duration `json:"httpTimeout"`
HTTPUserAgent string `json:"httpUserAgent,omitempty"`
HTTPDebugging bool `json:"httpDebugging,omitempty"`
WebsocketMetricsLogging bool `json:"websocketMetricsLogging"`
WebsocketResponseCheckTimeout time.Duration `json:"websocketResponseCheckTimeout"`
WebsocketResponseMaxLimit time.Duration `json:"websocketResponseMaxLimit"`
WebsocketTrafficTimeout time.Duration `json:"websocketTrafficTimeout"`
Expand Down
39 changes: 39 additions & 0 deletions config/versions/v4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package versions

import (
"context"
"encoding/json"

Check failure on line 5 in config/versions/v4.go

View workflow job for this annotation

GitHub Actions / lint

import 'encoding/json' is not allowed from list 'prevent_json_package_use': Please use the custom JSON package github.com/thrasher-corp/gocryptotrader/encoding/json instead of encoding/json to allow sonic/json switching. (depguard)

"github.com/buger/jsonparser"
)

// Version4 is an ExchangeVersion to add the websocketMetricsLogging field
type Version4 struct {
}

func init() {
Manager.registerVersion(4, &Version4{})
}

// Exchanges returns all exchanges: "*"
func (v *Version4) Exchanges() []string { return []string{"*"} }

// UpgradeExchange will upgrade the exchange config with the websocketMetricsLogging field
func (v *Version4) UpgradeExchange(_ context.Context, e []byte) ([]byte, error) {
if len(e) == 0 {
return e, nil
}
if _, _, _, err := jsonparser.Get(e, "websocketMetricsLogging"); err == nil {
return e, nil
}
val, err := json.Marshal(false)
if err != nil {
return nil, err
}
return jsonparser.Set(e, val, "websocketMetricsLogging")
}

// DowngradeExchange will downgrade the exchange config by removing the websocketMetricsLogging field
func (v *Version4) DowngradeExchange(_ context.Context, e []byte) ([]byte, error) {
return jsonparser.Delete(e, "websocketMetricsLogging"), nil
}
47 changes: 47 additions & 0 deletions config/versions/v4_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package versions

import (
"context"
"testing"

"github.com/stretchr/testify/require"
)

func TestVersion4UpgradeExchange(t *testing.T) {
t.Parallel()

got, err := (&Version4{}).UpgradeExchange(context.Background(), nil)
require.NoError(t, err)
require.Nil(t, got)

payload := []byte(`{"name":"test"}`)
expected := []byte(`{"name":"test","websocketMetricsLogging":false}`)
got, err = (&Version4{}).UpgradeExchange(context.Background(), payload)
require.NoError(t, err)
require.Equal(t, expected, got)

payload = []byte(`{"name":"test","websocketMetricsLogging":true}`)
got, err = (&Version4{}).UpgradeExchange(context.Background(), payload)
require.NoError(t, err)
require.Equal(t, payload, got)
}

func TestVersion4DowngradeExchange(t *testing.T) {
t.Parallel()

got, err := (&Version4{}).DowngradeExchange(context.Background(), nil)
require.NoError(t, err)
require.Nil(t, got)

payload := []byte(`{"name":"test","websocketMetricsLogging":false}`)
expected := []byte(`{"name":"test"}`)
got, err = (&Version4{}).DowngradeExchange(context.Background(), payload)
require.NoError(t, err)
require.Equal(t, expected, got)
}

func TestVersion4Exchanges(t *testing.T) {
t.Parallel()
assert := require.New(t)
assert.Equal([]string{"*"}, (&Version4{}).Exchanges())
}
24 changes: 24 additions & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -345,6 +346,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -422,6 +424,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -499,6 +502,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -582,6 +586,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -658,6 +663,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -737,6 +743,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -819,6 +826,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -931,6 +939,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1008,6 +1017,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1134,6 +1144,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1211,6 +1222,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1291,6 +1303,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1431,6 +1444,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1510,6 +1524,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1619,6 +1634,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1694,6 +1710,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1771,6 +1788,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1848,6 +1866,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -1928,6 +1947,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -2035,6 +2055,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -2113,6 +2134,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -2230,6 +2252,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down Expand Up @@ -2308,6 +2331,7 @@
"enabled": true,
"verbose": false,
"httpTimeout": 15000000000,
"websocketMetricsLogging": false,
"websocketResponseCheckTimeout": 30000000,
"websocketResponseMaxLimit": 7000000000,
"websocketTrafficTimeout": 30000000000,
Expand Down
Loading
Loading