Skip to content

Force localhost connections when client connects to localhost #305

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

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

Zerpet
Copy link
Member

@Zerpet Zerpet commented Sep 19, 2023

Fixes #296

It is common to have a local instance of RabbitMQ running locally,
either via a local rabbit (e.g. installed from source), or inside a
container (e.g. Docker or local Kubernetes). In both cases, our client
may not work without providing an address resolver, or without changing
the advertised host/port in rabbit via an env variable. Specifically,
our clients won't work if the client can't resolve the hostname of the
local machine.

For exampe, a laptop may have a hostname mylaptop.some-company.com.
Rabbit won't be impacted as long as it works in a single-node
configuration. However, the client smart features to locate the stream
leaders and replicas will get "confused" because it can't resolve the
hostname.

This commit changes the smart layer, so that it won't try to locate the
stream replicas if the client is connected to localhost. Instead, it
will force the producer/consumer connections to be localhost, and it
will assume that stream replicas/leader are in localhost. This is true
for single-node rabbits in local development environments. The smart
feature to locate leader/replicas remains unchanged for non-local
connections.

@Zerpet Zerpet self-assigned this Sep 19, 2023
@Zerpet
Copy link
Member Author

Zerpet commented Sep 19, 2023

Requires some manual QA before merging.

@Gsantomaggio @lukebakken could we introduce this in a patch release? Arguably it doesn't add new functionality, but a slight change in behaviour.

@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Patch coverage: 57.74% and project coverage change: -0.20% ⚠️

Comparison is base (c9f7563) 92.86% compared to head (3624282) 92.66%.

❗ Current head 3624282 differs from pull request most recent head 049343f. Consider uploading reports for the commit 049343f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #305      +/-   ##
==========================================
- Coverage   92.86%   92.66%   -0.20%     
==========================================
  Files         112      112              
  Lines        9742     9795      +53     
  Branches      774      786      +12     
==========================================
+ Hits         9047     9077      +30     
- Misses        532      546      +14     
- Partials      163      172       +9     
Files Changed Coverage Δ
Tests/FilterTest.cs 95.65% <0.00%> (-4.35%) ⬇️
Tests/RawProducerSystemTests.cs 97.56% <42.85%> (-1.39%) ⬇️
Tests/SuperStreamConsumerTests.cs 94.24% <45.45%> (-3.51%) ⬇️
RabbitMQ.Stream.Client/StreamSystem.cs 81.62% <84.84%> (-1.46%) ⬇️

... and 2 files with indirect coverage changes

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

Copy link
Member

@Gsantomaggio Gsantomaggio left a comment

Choose a reason for hiding this comment

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

Looks good to me, should we do #305 (comment) ?

@Zerpet
Copy link
Member Author

Zerpet commented Sep 20, 2023

Looks good to me, should we do #305 (comment) ?

I don't think we should mark the test to be skipped. In my commit, the test is marked "maybe skip", and it will always run, at least to the point where the SkipException is thrown.

Allow me to do manual QA for a couple hours before we consider merging.

@Zerpet Zerpet marked this pull request as ready for review September 21, 2023 15:19
Zerpet and others added 2 commits September 21, 2023 16:20
Related to #296

It is common to have a local instance of RabbitMQ running locally,
either via a local rabbit (e.g. installed from source), or inside a
container (e.g. Docker or local Kubernetes). In both cases, our client
may not work without providing an address resolver, or without changing
the advertised host/port in rabbit via an env variable. Specifically,
our clients won't work if the client can't resolve the hostname of the
local machine.

For exampe, a laptop may have a hostname mylaptop.some-company.com.
Rabbit won't be impacted as long as it works in a single-node
configuration. However, the client smart features to locate the stream
leaders and replicas will get "confused" because it can't resolve the
hostname.

This commit changes the smart layer, so that it won't try to locate the
stream replicas if the client is connected to localhost. Instead, it
will force the producer/consumer connections to be localhost, and it
will assume that stream replicas/leader are in localhost. This is true
for single-node rabbits in local development environments. The smart
feature to locate leader/replicas remains unchanged for non-local
connections.

Signed-off-by: Aitor Perez Cedres <[email protected]>
Signed-off-by: Gabriele Santomaggio <[email protected]>
@Zerpet
Copy link
Member Author

Zerpet commented Sep 21, 2023

Rebased branched on top of main. We should be good to merge after CI passes.

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.

Unable to create producer when connected to localhost and rabbit uses a hostname
3 participants