Skip to content

Commit

Permalink
fix: support IPv6, allow specific binding to IPs
Browse files Browse the repository at this point in the history
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;
  • Loading branch information
tvogel committed Oct 11, 2024
1 parent dcf967e commit b9121d4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .template.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PHX_HTTP_IP=
PHX_HTTP_PORT=
PHX_URL_HOST=
PHX_URL_PORT=
PHX_URL_SCHEME=
Expand Down
13 changes: 11 additions & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ config :logflare,
config :logflare,
LogflareWeb.Endpoint,
filter_nil_kv_pairs.(
http: filter_nil_kv_pairs.(port: System.get_env("PHX_HTTP_PORT")),
http: filter_nil_kv_pairs.(
port: System.get_env("PHX_HTTP_PORT"),
ip:
case System.get_env("PHX_HTTP_IP") do
nil -> nil
value -> IP.from_string!(value)
end
),
url:
filter_nil_kv_pairs.(
host: System.get_env("PHX_URL_HOST"),
Expand Down Expand Up @@ -77,6 +84,7 @@ config :logflare,
hostname: System.get_env("DB_HOSTNAME"),
password: System.get_env("DB_PASSWORD"),
username: System.get_env("DB_USERNAME"),
socket_options: [ :inet6 ],
after_connect:
if(System.get_env("DB_SCHEMA"),
do: {Postgrex, :query!, ["set search_path=#{System.get_env("DB_SCHEMA")}", []]},
Expand Down Expand Up @@ -211,7 +219,8 @@ cond do
:postgres_backend_adapter,
filter_nil_kv_pairs.(
url: System.get_env("POSTGRES_BACKEND_URL"),
schema: System.get_env("POSTGRES_BACKEND_SCHEMA")
schema: System.get_env("POSTGRES_BACKEND_SCHEMA"),
socket_options: [:inet6]
)

config_env() != :test ->
Expand Down
1 change: 1 addition & 0 deletions docs/docs.logflare.com/docs/self-hosting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ All browser authentication will be disabled when in single-tenant mode.
| `LOGFLARE_PUBLIC_ACCESS_TOKEN` | string, defaults to `nil` | If set, creates a public access token for the provisioned user, for ingestion or querying usage. Single-tenant mode only. |
| `LOGFLARE_PRIVATE_ACCESS_TOKEN` | string, defaults to `nil` | If set, creates a private access token for the provisioned user, for management API usage. Single-tenant mode only. |
| `LOGFLARE_SUPABASE_MODE` | Boolean, defaults to `false` | A special mode for Logflare, where Supabase-specific resources will be seeded. Intended for Suapbase self-hosted usage. |
| `PHX_HTTP_IP` | String, defaults to `nil` | Allows configuration of the HTTP server IP to bind to. Specifying an IPv6 like `::` will enable IPv6. |
| `PHX_HTTP_PORT` | Integer, defaults to `4000` | Allows configuration of the HTTP server port. |
| `DB_SCHEMA` | String, defaults to `nil` | Allows configuration of the database schema to scope Logflare operations. |
| `LOGFLARE_LOG_LEVEL` | String, defaults to `info`. <br/>Options: `error`,`warning`, `info` | Allows runtime configuration of log level. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ defmodule Logflare.Backends.Adaptor.PostgresAdaptor.SharedRepo do

opts ++ fields
end
opts = opts ++ (Map.take(config, [:socket_options]) |> Map.to_list())

with {:error, {:already_started, pid}} <- Supervisor.start_child({__MODULE__, opts}) do
{:ok, pid}
Expand Down
4 changes: 3 additions & 1 deletion lib/logflare/context_cache/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ defmodule Logflare.ContextCache.Supervisor do
password = Application.get_env(:logflare, Repo)[:password]
database = Application.get_env(:logflare, Repo)[:database]
port = Application.get_env(:logflare, Repo)[:port]
socket_options = Application.get_env(:logflare, Repo)[:socket_options]

slot = Application.get_env(:logflare, CacheBuster)[:replication_slot]
publications = Application.get_env(:logflare, CacheBuster)[:publications]
Expand All @@ -98,7 +99,8 @@ defmodule Logflare.ContextCache.Supervisor do
port: port,
username: username,
database: database,
password: password
password: password,
tcp_opts: socket_options
},
slot: slot,
wal_position: {"0", "0"},
Expand Down
5 changes: 4 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ defmodule Logflare.Mixfile do
{:opentelemetry_exporter, "~> 1.6"},
{:opentelemetry_phoenix, "~> 1.1"},
{:opentelemetry_cowboy, "~> 0.2"},
{:live_monaco_editor, "~> 0.1"}
{:live_monaco_editor, "~> 0.1"},

# IP address parsing
{:net_address, "~> 0.3.1"}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"mint": {:hex, :mint, "1.6.2", "af6d97a4051eee4f05b5500671d47c3a67dac7386045d87a904126fd4bbcea2e", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "5ee441dffc1892f1ae59127f74afe8fd82fda6587794278d924e4d90ea3d63f9"},
"mix_test_watch": {:hex, :mix_test_watch, "1.1.1", "eee6fc570d77ad6851c7bc08de420a47fd1e449ef5ccfa6a77ef68b72e7e51ad", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "f82262b54dee533467021723892e15c3267349849f1f737526523ecba4e6baae"},
"money": {:hex, :money, "1.12.3", "a0396428e21c36c8a40462a1f17b6038781b2544d00696c8b27026205b54dbe4", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.0 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "4902dcac18aca4788be9d6b04d1a59a5bcbceca700f33eab8fe13eb6a6c36dde"},
"net_address": {:hex, :net_address, "0.3.1", "70832e5a35a2c9f2d6e5bcf43e3164b9c4f7515ca7cc8740d2d38aab39ffa0e9", [:mix], [], "hexpm", "eb20da348f1ad88fdfaaa4e8923a3906ac54b54cb67ac1731f86bce07cb2b081"},
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
Expand Down

0 comments on commit b9121d4

Please sign in to comment.