Skip to content

Commit

Permalink
Switch libcluster strategry from k8s to postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff committed Dec 17, 2024
1 parent 609fe8f commit f77baa3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
17 changes: 11 additions & 6 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,18 @@ config :sanbase, Sanbase.MetricExporter.S3, bucket: {:system, "METRICS_EXPORTER_

config :libcluster,
topologies: [
k8s: [
strategy: Elixir.Cluster.Strategy.Kubernetes,
postgres_topology: [
strategy: LibclusterPostgres.Strategy,
config: [
mode: :dns,
kubernetes_node_basename: "sanbase",
kubernetes_selector: "app=sanbase",
polling_interval: 10_000
hostname: "localhost",
username: "postgres",
password: "postgres",
database: "sanbase_dev",
port: 5432,
parameters: [],
ssl: false,
ssl_opts: nil,
channel_name: "sanbase_cluster"
]
]
]
Expand Down
4 changes: 3 additions & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import Config
config :phoenix_live_view, debug_heex_annotations: true
config :sanbase, Sanbase, url: {:system, "SANBASE_URL", "https://app-stage.santiment.net"}

port = String.to_integer(System.get_env("PORT") || "4000")

config :sanbase, SanbaseWeb.Endpoint,
http: [
port: 4000,
port: port,
protocol_options: [
# Bump up cowboy2's timeout to 100 seconds
idle_timeout: 100_000
Expand Down
18 changes: 18 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ if config_env() == :prod do
ssl: true,
ssl_opts: [verify: :verify_none]

config :libcluster,
topologies: [
postgres_topology: [
strategy: LibclusterPostgres.Strategy,
config: [
hostname: "localhost",
username: "postgres",
password: "postgres",
database: "santiment",
port: 5432,
parameters: [],
ssl: true,
ssl_opts: [verify: :verify_none],
channel_name: "sanbase_cluster"
]
]
]

config :ethereumex,
url: parity_url,
http_options: [timeout: 25_000, recv_timeout: 25_000],
Expand Down
14 changes: 13 additions & 1 deletion lib/sanbase/application/admin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Sanbase.Application.Admin do
A separate pod is required so the access to it can be better secured compared
to when the admin dashboard was part of the web pod
"""
import Sanbase.ApplicationUtils
require Logger

def init() do
Expand All @@ -18,7 +19,18 @@ defmodule Sanbase.Application.Admin do
def children() do
# Define workers and child supervisors to be supervised
children = [
{Oban, oban_admin_config()}
{Oban, oban_admin_config()},

# Start the libcluster in admin, so we can send messages to the web pods when some
# important tables changes.
start_in(
{Cluster.Supervisor,
[
Application.get_env(:libcluster, :topologies),
[name: Sanbase.ClusterSupervisor]
]},
[:dev, :prod]
)
]

opts = [
Expand Down
2 changes: 1 addition & 1 deletion lib/sanbase/application/web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule Sanbase.Application.Web do
Application.get_env(:libcluster, :topologies),
[name: Sanbase.ClusterSupervisor]
]},
[:prod]
[:dev, :prod]
)
]

Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ defmodule Sanbase.Mixfile do
{:kino_db, "~> 0.2.2"},
{:kino_vega_lite, "~> 0.1.9"},
{:libcluster, "~> 3.0"},
{:libcluster_postgres, "~> 0.1"},
{:map_diff, "~> 1.3"},
{:mint, "~> 1.0"},
{:mock, "~> 0.3"},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"kino_db": {:hex, :kino_db, "0.2.13", "2b7d5b71aa4fc1ebc6d415df62170b6807c6ff84d621f4fdfc226569cc49b399", [:mix], [{:adbc, "~> 0.2", [hex: :adbc, repo: "hexpm", optional: true]}, {:db_connection, "~> 2.4.2 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: true]}, {:explorer, "~> 0.8", [hex: :explorer, repo: "hexpm", optional: true]}, {:exqlite, "~> 0.11", [hex: :exqlite, repo: "hexpm", optional: true]}, {:kino, "~> 0.13", [hex: :kino, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.18 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:req_athena, "~> 0.2.0", [hex: :req_athena, repo: "hexpm", optional: true]}, {:req_bigquery, "~> 0.1.0", [hex: :req_bigquery, repo: "hexpm", optional: true]}, {:table, "~> 0.1", [hex: :table, repo: "hexpm", optional: false]}, {:tds, "~> 2.3.4 or ~> 2.4", [hex: :tds, repo: "hexpm", optional: true]}], "hexpm", "0dcdba30c99ce367f1026477fc6374b94dc1dc10126b33cc9129e02c7f1e1538"},
"kino_vega_lite": {:hex, :kino_vega_lite, "0.1.13", "03c00405987a2202e4b8014ee55eb7f5727691b3f13d76a3764f6eeccef45322", [:mix], [{:kino, "~> 0.7", [hex: :kino, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: false]}, {:vega_lite, "~> 0.1.8", [hex: :vega_lite, repo: "hexpm", optional: false]}], "hexpm", "00c72bc270e7b9d3c339f726cdab0012fd3f2fc75e36c7548e0f250fe420fa10"},
"libcluster": {:hex, :libcluster, "3.4.1", "271d2da892763bbef53c2872036c936fe8b80111eb1feefb2d30a3bb15c9b4f6", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.3", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1d568157f069c6afa70ec0d736704cf799734bdbb6343f0322af4a980301c853"},
"libcluster_postgres": {:hex, :libcluster_postgres, "0.1.2", "51380bb6b3a6e11b2614202c63169b464cf4867814da52cc3aa82dfc5ae22248", [:mix], [{:libcluster, "~> 3.3", [hex: :libcluster, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "b957ca609ec5dcddc37342a756bfc027029225bfb089bf0b32974f0ec0cac237"},
"map_diff": {:hex, :map_diff, "1.3.4", "4fa013ad4fff7b21694f3aa5890dad5a0679f11812fdd89a0ad06276a431faf8", [:mix], [], "hexpm", "32fc0b8fc158683a00a58298440b8cb884e7e779f9459e598df61d022b5412e9"},
"meck": {:hex, :meck, "0.9.2", "85ccbab053f1db86c7ca240e9fc718170ee5bda03810a6292b5306bf31bae5f5", [:rebar3], [], "hexpm", "81344f561357dc40a8344afa53767c32669153355b626ea9fcbc8da6b3045826"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
Expand Down

0 comments on commit f77baa3

Please sign in to comment.