From a6c483e82c587920995466b9427f8782d5093bd0 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 2 Aug 2023 23:57:28 +0530 Subject: [PATCH 1/8] Updated readme section to configure logging --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 7d1159f3..f0b22981 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,11 @@ if err != nil { } fmt.Print(status, status.ChannelId) ``` + +## Configure logging +- You can log messages by passing logger inside clientOptions. +- There is also an option provided to configure loglevel. + ## Note on usage of ablytest package Although the `ablytest` package is available as a part of ably-go, we do not recommend using it as a sandbox for your own testing, since it's specifically intended for client library SDKs and we don’t provide any guarantees for support or that it will remain publicly accessible. It can lead to unexpected behaviour, since some beta features may be deployed on the `sandbox` environment so that they can be tested before going into production. From 6f4984b2ec8e5d0762b923528a873912b81b78c2 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Fri, 4 Aug 2023 23:48:15 +0530 Subject: [PATCH 2/8] Updated readme with example code for logging --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index f0b22981..14e52fa5 100644 --- a/README.md +++ b/README.md @@ -330,6 +330,23 @@ fmt.Print(status, status.ChannelId) - You can log messages by passing logger inside clientOptions. - There is also an option provided to configure loglevel. +```go +// stdLogger wraps log.Logger to satisfy the Logger interface. +type stdLogger struct { + *log.Logger +} + +func (s *stdLogger) Printf(level LogLevel, format string, v ...interface{}) { + s.Logger.Printf(fmt.Sprintf("[%s] %s", level, format), v...) +} + +client, err = ably.NewRealtime( +ably.WithKey("xxx:xxx"), +ably.WithLogHandler(&stdLogger{Logger: log.New(os.Stderr, "", log.LstdFlags)}), +ably.WithLogLevel(ably.LogWarning) +) +``` + ## Note on usage of ablytest package Although the `ablytest` package is available as a part of ably-go, we do not recommend using it as a sandbox for your own testing, since it's specifically intended for client library SDKs and we don’t provide any guarantees for support or that it will remain publicly accessible. It can lead to unexpected behaviour, since some beta features may be deployed on the `sandbox` environment so that they can be tested before going into production. From f0a6049d355b145ec3abdfa5c399f6545db0cc06 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Sat, 5 Aug 2023 23:16:35 +0530 Subject: [PATCH 3/8] Updated example to configure logging and loglevel --- README.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 14e52fa5..beeacd82 100644 --- a/README.md +++ b/README.md @@ -327,23 +327,28 @@ fmt.Print(status, status.ChannelId) ``` ## Configure logging -- You can log messages by passing logger inside clientOptions. +- You need to create a custom Logger that implements `ably.Logger` interface. - There is also an option provided to configure loglevel. ```go -// stdLogger wraps log.Logger to satisfy the Logger interface. -type stdLogger struct { +type customLogger struct { *log.Logger } -func (s *stdLogger) Printf(level LogLevel, format string, v ...interface{}) { +func (s *customLogger) Printf(level ably.LogLevel, format string, v ...interface{}) { s.Logger.Printf(fmt.Sprintf("[%s] %s", level, format), v...) } +func NewCustomLogger() *customLogger { + logger := &customLogger{} + logger.Logger = log.New(os.Stdout, "", log.LstdFlags) + return logger +} + client, err = ably.NewRealtime( -ably.WithKey("xxx:xxx"), -ably.WithLogHandler(&stdLogger{Logger: log.New(os.Stderr, "", log.LstdFlags)}), -ably.WithLogLevel(ably.LogWarning) + ably.WithKey("xxx:xxx"), + ably.WithLogHandler(NewCustomLogger()), + ably.WithLogLevel(ably.LogWarning), ) ``` From 7428f9fe0403c9ec3f59577f926b3477d88876c4 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 7 Aug 2023 23:21:05 +0530 Subject: [PATCH 4/8] Updated readme for logging and maxMessageSize section --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index beeacd82..0b54bd4f 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ if err != nil { #### Update MaxMessageSize/read limit for realtime message subscription - The default `MaxMessageSize` is automatically configured by Ably when connection is established with Ably. -- This value defaults to 64kb, please [get in touch](https://ably.com/support) if you would like to request a higher limit for your account. +- This value defaults to [16kb for free and 64kb for PAYG account](https://faqs.ably.com/what-is-the-maximum-message-size), please [get in touch](https://ably.com/support) if you would like to request a higher limit for your account. - Upgrading your account to higher limit will automatically update `MaxMessageSize` property and should accordingly set the client side connection read limit. - If you are still facing issues when receiving large messages or intentionally want to reduce the limit, you can explicitly update the connection read limit: @@ -327,6 +327,7 @@ fmt.Print(status, status.ChannelId) ``` ## Configure logging +- By default, internal logger prints output to stdout with default logging level of `warning`. - You need to create a custom Logger that implements `ably.Logger` interface. - There is also an option provided to configure loglevel. From 1999408b6aeeb664bd8f3bdc0c9f887470c68865 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 7 Aug 2023 23:22:23 +0530 Subject: [PATCH 5/8] Reduced header size of configure logging section --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b54bd4f..7fe03763 100644 --- a/README.md +++ b/README.md @@ -326,8 +326,8 @@ if err != nil { fmt.Print(status, status.ChannelId) ``` -## Configure logging -- By default, internal logger prints output to stdout with default logging level of `warning`. +### Configure logging +- By default, internal logger prints output to `stdout` with default logging level of `warning`. - You need to create a custom Logger that implements `ably.Logger` interface. - There is also an option provided to configure loglevel. From b056adca94ca37fda2e032464ce9bbe5d2d9f786 Mon Sep 17 00:00:00 2001 From: zak Date: Tue, 3 Oct 2023 12:37:11 +0100 Subject: [PATCH 6/8] Fix message extras unmarshaled to incompatible json type Message extras should be a json compatible map[string]interface{}, but when marshalling to msgpack and back again, any nested objects become map[interface{}]interface{} which is incompatible with json marshalling. Set the map type on the msgpack handle to map[string]interface{} so that nested objects are correctly unmarshaled. --- ably/internal/ablyutil/msgpack.go | 2 ++ ably/internal/ablyutil/msgpack_test.go | 26 ++++++++++++++++++++++++ ably/proto_message_decoding_test.go | 28 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/ably/internal/ablyutil/msgpack.go b/ably/internal/ablyutil/msgpack.go index 98dd66ce..ae19ce1c 100644 --- a/ably/internal/ablyutil/msgpack.go +++ b/ably/internal/ablyutil/msgpack.go @@ -3,6 +3,7 @@ package ablyutil import ( "bytes" "io" + "reflect" "github.com/ugorji/go/codec" ) @@ -13,6 +14,7 @@ func init() { handle.Raw = true handle.WriteExt = true handle.RawToString = true + handle.MapType = reflect.TypeOf(map[string]interface{}(nil)) } // UnmarshalMsgpack decodes the MessagePack-encoded data and stores the result in the diff --git a/ably/internal/ablyutil/msgpack_test.go b/ably/internal/ablyutil/msgpack_test.go index 59e98cef..0b35ff0e 100644 --- a/ably/internal/ablyutil/msgpack_test.go +++ b/ably/internal/ablyutil/msgpack_test.go @@ -5,6 +5,7 @@ package ablyutil import ( "bytes" + "encoding/json" "testing" ) @@ -31,3 +32,28 @@ func TestMsgpack(t *testing.T) { } }) } + +func TestMsgpackJson(t *testing.T) { + extras := map[string]interface{}{ + "headers": map[string]interface{}{ + "version": 1, + }, + } + + b, err := MarshalMsgpack(extras) + if err != nil { + t.Fatal(err) + } + + var got map[string]interface{} + err = UnmarshalMsgpack(b, &got) + if err != nil { + t.Fatal(err) + } + + buff := bytes.Buffer{} + err = json.NewEncoder(&buff).Encode(got) + if err != nil { + t.Fatal(err) + } +} diff --git a/ably/proto_message_decoding_test.go b/ably/proto_message_decoding_test.go index 060e7408..f96d5a48 100644 --- a/ably/proto_message_decoding_test.go +++ b/ably/proto_message_decoding_test.go @@ -107,6 +107,34 @@ func loadMsgpackFixtures() ([]MsgpackTestFixture, error) { return o, err } +func TestMsgpackExtrasJsonCompatible(t *testing.T) { + p := protocolMessage{ + Messages: []*Message{ + { + Name: "my event", + Data: "hello world", + Extras: map[string]interface{}{ + "headers": map[string]interface{}{ + "version": 1, + }, + }, + }, + }, + } + + b, err := ablyutil.MarshalMsgpack(p) + assert.NoError(t, err) + + var got ProtocolMessage + assert.NoError(t, ablyutil.UnmarshalMsgpack(b, &got)) + + msg, err := got.Messages[0].withDecodedData(nil) + assert.NoError(t, err) + + buff := bytes.Buffer{} + assert.NoError(t, json.NewEncoder(&buff).Encode(msg)) +} + func TestMsgpackDecoding(t *testing.T) { msgpackTestFixtures, err := loadMsgpackFixtures() require.NoError(t, err) From d62e6963426afe9aefad576fbf6fe90fb6623f0b Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Thu, 5 Oct 2023 08:12:20 +0100 Subject: [PATCH 7/8] bump version --- ably/proto_http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ably/proto_http.go b/ably/proto_http.go index b049d732..be793610 100644 --- a/ably/proto_http.go +++ b/ably/proto_http.go @@ -11,7 +11,7 @@ const ( ablyVersionHeader = "X-Ably-Version" ablyErrorCodeHeader = "X-Ably-Errorcode" ablyErrorMessageHeader = "X-Ably-Errormessage" - libraryVersion = "1.2.13" + libraryVersion = "1.2.14" libraryName = "go" ablyVersion = "1.2" ablyClientIDHeader = "X-Ably-ClientId" From bd627ae60bc07459e998e0f789bed3c263b8af04 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Thu, 5 Oct 2023 08:13:13 +0100 Subject: [PATCH 8/8] bump readme --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c48371cc..5c82c2f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log -# Changelog +## [1.2.14](https://github.com/ably/ably-go/tree/1.2.14) + +[Full Changelog](https://github.com/ably/ably-go/compare/v1.2.13...v1.2.14) + +**Merged pull requests:** + +- Fix message extras unmarshaled to incompatible json type [\#624](https://github.com/ably/ably-go/pull/624) ([zknill](https://github.com/zknill)) ## [1.2.13](https://github.com/ably/ably-go/tree/1.2.13)