Skip to content

Fix IPv6 support and support listening to a specific IP - #2226

Merged
Ziinc merged 10 commits into
Logflare:perf/ipv6from
tvogel:tv/fix-ipv6-and-listening
Jul 30, 2025
Merged

Fix IPv6 support and support listening to a specific IP#2226
Ziinc merged 10 commits into
Logflare:perf/ipv6from
tvogel:tv/fix-ipv6-and-listening

Conversation

@tvogel

@tvogel tvogel commented Oct 11, 2024

Copy link
Copy Markdown
Contributor

For running logflare on fly.io with their IPv6 based private networking, I had to fix/improve a few things. Please take a look and pick what you like!

(My first exposure to Elixir/Erlang, so thanks for that!)

Reorder build steps such that intermediate steps can more likely be reused,
in particular installed apt, npm and mix packages.
config/runtime.exs:
new variable PHX_HTTP_IP for specifying IP address to bind to;
Logflare.Repo,
:postgres_backend_adapter:
	set socket-options for IPv6;

SharedRepo,
ContextCache.Supervisor:
hand socket-options on;

update docs;
update .template.env;
Comment thread config/runtime.exs Outdated
Comment thread config/runtime.exs Outdated
Comment thread mix.exs Outdated
Comment thread lib/logflare/backends/adaptor/postgres_adaptor/shared_repo.ex Outdated
@Ziinc

Ziinc commented Oct 15, 2024

Copy link
Copy Markdown
Contributor

Thanks for the PR, looks like a good addition for self hosting setup

runtime.exs:
adapt logic from supabase/realtime:Realtime.Database.detect_ip_version/1;
use :inet.parse_address/1 instead of IP.from_string!/1;

shared_repo.ex:
apply code-review suggestion;
@tvogel
tvogel requested a review from Ziinc October 18, 2024 23:10

@Ziinc Ziinc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks for the adjustments, was OOO. I can take over the postgres adaptor backend adjustments needed.

Comment thread mix.exs Outdated
Comment thread config/runtime.exs Outdated
Comment thread config/runtime.exs Outdated
opts ++ fields
end

opts = opts ++ [socket_options: config[:socket_options]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tvogel this shouldn't use the global config actually, we can add this in temporarily but it should be part of the backend's config instead. This would require adjusting the self-hosted backend config building.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why shouldn't it use the socket_options determined for the respective DB_HOSTNAME which it determines in

          Map.take(config, [:username, :password, :hostname, :database, :port, :ssl])

? In which cases would you use different options?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this case, with inserts into one postgres instance it is ok. However, it will not apply in the situation where there is 2 postgres instances in a multi-backend setup, 1 on ipv6 and the other on ipv4. The same socket options would not apply

Comment thread lib/logflare/backends/adaptor/postgres_adaptor/shared_repo.ex Outdated
Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>
@tvogel

tvogel commented Nov 4, 2024

Copy link
Copy Markdown
Contributor Author

(Sorry for the late replies - I was traveling.)

@6ixfalls

Copy link
Copy Markdown

@Ziinc, any update on this pull request? Hitting this issue currently as well and would love for this to be merged.

@Ziinc

Ziinc commented Jan 22, 2025

Copy link
Copy Markdown
Contributor

@tvogel could you adjust the two remaining issues for the merge?

  1. socket opts only on single tenant mode
  2. case clause fallback

@Ziinc
Ziinc changed the base branch from main to perf/ipv6 July 30, 2025 18:37
@Ziinc
Ziinc merged commit 77529da into Logflare:perf/ipv6 Jul 30, 2025
2 of 5 checks passed
Ziinc added a commit that referenced this pull request Jul 30, 2025
* perf: reduce docker rebuild overhead

Reorder build steps such that intermediate steps can more likely be reused,
in particular installed apt, npm and mix packages.

* fix: support IPv6, allow specific binding to IPs

config/runtime.exs:
new variable PHX_HTTP_IP for specifying IP address to bind to;
Logflare.Repo,
:postgres_backend_adapter:
	set socket-options for IPv6;

SharedRepo,
ContextCache.Supervisor:
hand socket-options on;

update docs;
update .template.env;

* fix: address code-review

runtime.exs:
adapt logic from supabase/realtime:Realtime.Database.detect_ip_version/1;
use :inet.parse_address/1 instead of IP.from_string!/1;

shared_repo.ex:
apply code-review suggestion;

* address formatting linter

* Update mix.exs: remove dependency not longer required

Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>

* fix: only forward socket opts for single tenant PG

* fix: fallback for host

* fix: fallback for socket options

---------

Co-authored-by: Chase Granberry <chase@logflare.app>
Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>
Ziinc added a commit that referenced this pull request Aug 21, 2025
* perf: reduce docker rebuild overhead

Reorder build steps such that intermediate steps can more likely be reused,
in particular installed apt, npm and mix packages.

* fix: support IPv6, allow specific binding to IPs

config/runtime.exs:
new variable PHX_HTTP_IP for specifying IP address to bind to;
Logflare.Repo,
:postgres_backend_adapter:
	set socket-options for IPv6;

SharedRepo,
ContextCache.Supervisor:
hand socket-options on;

update docs;
update .template.env;

* fix: address code-review

runtime.exs:
adapt logic from supabase/realtime:Realtime.Database.detect_ip_version/1;
use :inet.parse_address/1 instead of IP.from_string!/1;

shared_repo.ex:
apply code-review suggestion;

* address formatting linter

* Update mix.exs: remove dependency not longer required

Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>

* fix: only forward socket opts for single tenant PG

* fix: fallback for host

* fix: fallback for socket options

---------

Co-authored-by: Chase Granberry <chase@logflare.app>
Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>
Ziinc added a commit that referenced this pull request Aug 21, 2025
* Fix IPv6 support and support listening to a specific IP (#2226)

* perf: reduce docker rebuild overhead

Reorder build steps such that intermediate steps can more likely be reused,
in particular installed apt, npm and mix packages.

* fix: support IPv6, allow specific binding to IPs

config/runtime.exs:
new variable PHX_HTTP_IP for specifying IP address to bind to;
Logflare.Repo,
:postgres_backend_adapter:
	set socket-options for IPv6;

SharedRepo,
ContextCache.Supervisor:
hand socket-options on;

update docs;
update .template.env;

* fix: address code-review

runtime.exs:
adapt logic from supabase/realtime:Realtime.Database.detect_ip_version/1;
use :inet.parse_address/1 instead of IP.from_string!/1;

shared_repo.ex:
apply code-review suggestion;

* address formatting linter

* Update mix.exs: remove dependency not longer required

Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>

* fix: only forward socket opts for single tenant PG

* fix: fallback for host

* fix: fallback for socket options

---------

Co-authored-by: Chase Granberry <chase@logflare.app>
Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>

* chore: fix compilation errors

* chore: remove net_address from lockfile

* chore: PR comments

---------

Co-authored-by: Tilman Vogel <tilman.vogel@web.de>
Co-authored-by: Chase Granberry <chase@logflare.app>
djwhitt pushed a commit that referenced this pull request May 18, 2026
* Fix IPv6 support and support listening to a specific IP (#2226)

* perf: reduce docker rebuild overhead

Reorder build steps such that intermediate steps can more likely be reused,
in particular installed apt, npm and mix packages.

* fix: support IPv6, allow specific binding to IPs

config/runtime.exs:
new variable PHX_HTTP_IP for specifying IP address to bind to;
Logflare.Repo,
:postgres_backend_adapter:
	set socket-options for IPv6;

SharedRepo,
ContextCache.Supervisor:
hand socket-options on;

update docs;
update .template.env;

* fix: address code-review

runtime.exs:
adapt logic from supabase/realtime:Realtime.Database.detect_ip_version/1;
use :inet.parse_address/1 instead of IP.from_string!/1;

shared_repo.ex:
apply code-review suggestion;

* address formatting linter

* Update mix.exs: remove dependency not longer required

Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>

* fix: only forward socket opts for single tenant PG

* fix: fallback for host

* fix: fallback for socket options

---------

Co-authored-by: Chase Granberry <chase@logflare.app>
Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>

* chore: fix compilation errors

* chore: remove net_address from lockfile

* chore: PR comments

---------

Co-authored-by: Tilman Vogel <tilman.vogel@web.de>
Co-authored-by: Chase Granberry <chase@logflare.app>
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.

4 participants