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

Initial subscription decompression functionality #1408

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

slang25
Copy link
Member

@slang25 slang25 commented May 9, 2024

No description provided.

if (contentEncoding is not null)
{
var decompressor = _decompressionRegistry.GetDecompressor(contentEncoding.StringValue);
// TODO What to do when decompressor not found?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This created some interesting discussion, as my instinct is to throw here, if we see there is a Content-Encoding mentioning a compression we weren't expecting, however @hwoodiwiss pointed out that this could be a header someone is already legitimately using for other purposes, and we just broke them.

We could have some sort of opt-in behaviour, and if the default "no compression" configuration is detected then skip this block entirely. I was thinking we just had it on for subscription by default, but we might want to make that a major or minor version bump.

Copy link

codecov bot commented May 9, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 79.16%. Comparing base (bcb8eb6) to head (a712cad).
Report is 2 commits behind head on main.

Files Patch % Lines
...eHandling/Compression/GzipMessageBodyCompressor.cs 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1408      +/-   ##
==========================================
+ Coverage   79.09%   79.16%   +0.06%     
==========================================
  Files         138      141       +3     
  Lines        3234     3264      +30     
  Branches      448      449       +1     
==========================================
+ Hits         2558     2584      +26     
- Misses        445      449       +4     
  Partials      231      231              
Flag Coverage Δ
linux 79.16% <73.33%> (+0.06%) ⬆️
macos 48.37% <73.33%> (+0.44%) ⬆️
windows 48.40% <73.33%> (+0.47%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


namespace JustSaying.AwsTools.MessageHandling.Compression;

class GzipMessageBodyCompressor : IMessageBodyCompressor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you intended to make it public:

Suggested change
class GzipMessageBodyCompressor : IMessageBodyCompressor
internal sealed class GzipMessageBodyCompressor : IMessageBodyCompressor


namespace JustSaying.AwsTools.MessageHandling.Compression;

class GzipMessageBodyDecompressor : IMessageBodyDecompressor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GzipMessageBodyDecompressor : IMessageBodyDecompressor
internal sealed class GzipMessageBodyDecompressor : IMessageBodyDecompressor


class GzipMessageBodyCompressor : IMessageBodyCompressor
{
public string ContentEncoding { get; } = "gzip,base64";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public string ContentEncoding { get; } = "gzip,base64";
public string ContentEncoding { get; } = "gzip,base64";

internal interface IMessageBodyCompressor
{
string ContentEncoding { get; }
string Compress(string messageBody);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this async, or do we not have access to the required async methods the implementations use in all our TFMs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, I was thinking it should be sync because we are writing to and from in-memory streams. No strong opinion here from me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but if it's pluggable and we could make it async, it would enable async if for some reason it was being backed by a file or some other IO.

@@ -2,6 +2,7 @@
<PropertyGroup>
<IsShipping>true</IsShipping>
<TargetFrameworks>netstandard2.0;net461;net8.0</TargetFrameworks>
<NoWarn>$(NoWarn);RS0016;RS0017</NoWarn>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is being deleted post-draft?

src/JustSaying/JustSayingBus.cs Outdated Show resolved Hide resolved
Comment on lines +30 to +34
var memoryStream = new MemoryStream();
await using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
{
gzipStream.Write(Encoding.UTF8.GetBytes(payload));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add some unit tests for the (de)compression implementations.

slang25 and others added 4 commits May 9, 2024 11:33
…ompressionRegistry.cs

Co-authored-by: Martin Costello <martin@martincostello.com>
Co-authored-by: Martin Costello <martin@martincostello.com>
…patcherTests/WhenDispatchingMessage.cs

Co-authored-by: Martin Costello <martin@martincostello.com>
…pTests/BaseSubscriptionGroupTests.cs

Co-authored-by: Martin Costello <martin@martincostello.com>
@slang25 slang25 changed the title Initial subscription compression functionality Initial subscription decompression functionality May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants