-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RTC 389] Add DNSpoll distribution strategy (#109)
* Add DNS strategy * Add CI for DNS cluster * Changes after review * Fix credo issues * Add spec for read_boolean * Remove JF_DIST_NODE_BASENAME * Update lib/jellyfish/config_reader.ex Co-authored-by: Michał Śledź <[email protected]> * Update lib/jellyfish/config_reader.ex Co-authored-by: Michał Śledź <[email protected]> * Update test/jellyfish/config_reader_test.exs Co-authored-by: Michał Śledź <[email protected]> * Update test/jellyfish/config_reader_test.exs Co-authored-by: Michał Śledź <[email protected]> * Update lib/jellyfish/config_reader.ex Co-authored-by: Michał Śledź <[email protected]> * Update lib/jellyfish/config_reader.ex Co-authored-by: Michał Śledź <[email protected]> * Remove spec * Add do_read_nodes_list_config --------- Co-authored-by: Michał Śledź <[email protected]>
- Loading branch information
Showing
7 changed files
with
276 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
version: "3" | ||
|
||
x-jellyfish-template: &jellyfish-template | ||
build: . | ||
environment: &jellyfish-environment | ||
JF_SERVER_API_TOKEN: "development" | ||
JF_DIST_ENABLED: "true" | ||
JF_DIST_STRATEGY_NAME: "DNS" | ||
restart: on-failure | ||
|
||
services: | ||
test: | ||
image: membraneframeworklabs/docker_membrane | ||
command: | ||
- sh | ||
- -c | ||
- | | ||
cd app/ | ||
mix deps.get | ||
MIX_ENV=ci mix test --only cluster | ||
volumes: | ||
- .:/app | ||
- /app/_build | ||
- /app/deps | ||
networks: | ||
dns-network: | ||
aliases: | ||
- dnsmasq | ||
depends_on: | ||
- app1 | ||
- app2 | ||
- dnsmasq | ||
|
||
app1: | ||
<<: *jellyfish-template | ||
environment: | ||
<<: *jellyfish-environment | ||
JF_HOST: "localhost:4001" | ||
JF_PORT: 4001 | ||
JF_DIST_NODE_NAME: [email protected] | ||
JF_DIST_QUERY: app.dns-network | ||
ports: | ||
- 4001:4001 | ||
networks: | ||
dns-network: | ||
ipv4_address: 172.28.1.2 | ||
aliases: | ||
- app.dns-network | ||
dns: | ||
- 172.28.1.4:5353 | ||
|
||
app2: | ||
container_name: name | ||
<<: *jellyfish-template | ||
environment: | ||
<<: *jellyfish-environment | ||
JF_HOST: "localhost:4002" | ||
JF_PORT: 4002 | ||
JF_DIST_NODE_NAME: [email protected] | ||
JF_DIST_QUERY: app.dns-network | ||
ports: | ||
- 4002:4002 | ||
networks: | ||
dns-network: | ||
# Register IP under alias | ||
ipv4_address: 172.28.1.3 | ||
aliases: | ||
- app.dns-network | ||
dns: | ||
- 172.28.1.4:5353 | ||
|
||
dnsmasq: | ||
image: andyshinn/dnsmasq:2.78 | ||
volumes: | ||
- /etc/resolv.conf:/etc/resolv.dnsmasq.conf | ||
command: -d -q --no-hosts --no-resolv --no-poll --server 127.0.0.11 --listen-address 0.0.0.0 --port 5353 --log-queries --log-facility=- --address=/./127.0.0.11 | ||
networks: | ||
dns-network: | ||
ipv4_address: 172.28.1.4 | ||
aliases: | ||
- dnsmasq | ||
|
||
networks: | ||
dns-network: | ||
ipam: | ||
config: | ||
- subnet: 172.28.1.0/24 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,36 +112,105 @@ defmodule Jellyfish.ConfigReaderTest do | |
end | ||
end | ||
|
||
test "read_dist_config/0" do | ||
test "read_dist_config/0 NODES_LIST" do | ||
with_env ["JF_DIST_ENABLED", "JF_DIST_COOKIE", "JF_DIST_NODE_NAME", "JF_DIST_NODES"] do | ||
assert ConfigReader.read_dist_config() == [ | ||
enabled: false, | ||
strategy: nil, | ||
node_name: nil, | ||
cookie: nil, | ||
nodes: [] | ||
strategy_config: nil | ||
] | ||
|
||
System.put_env("JF_DIST_ENABLED", "true") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_COOKIE", "testcookie") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_NODE_NAME", "testnodename@abc@def") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_NODE_NAME", "testnodename") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_NODE_NAME", "[email protected]") | ||
|
||
assert ConfigReader.read_dist_config() == [ | ||
enabled: true, | ||
strategy: Cluster.Strategy.Epmd, | ||
node_name: :"[email protected]", | ||
cookie: :testcookie, | ||
nodes: [] | ||
strategy_config: [hosts: []] | ||
] | ||
|
||
System.put_env("JF_DIST_NODES", "[email protected] [email protected]") | ||
|
||
assert ConfigReader.read_dist_config() == [ | ||
enabled: true, | ||
strategy: Cluster.Strategy.Epmd, | ||
node_name: :"[email protected]", | ||
cookie: :testcookie, | ||
strategy_config: [hosts: [:"[email protected]", :"[email protected]"]] | ||
] | ||
end | ||
end | ||
|
||
test "read_dist_config/0 DNS" do | ||
with_env [ | ||
"JF_DIST_ENABLED", | ||
"JF_DIST_COOKIE", | ||
"JF_DIST_NODE_NAME", | ||
"JF_DIST_NODES", | ||
"JF_DIST_STRATEGY_NAME" | ||
] do | ||
assert ConfigReader.read_dist_config() == [ | ||
enabled: false, | ||
strategy: nil, | ||
node_name: nil, | ||
cookie: nil, | ||
strategy_config: nil | ||
] | ||
|
||
System.put_env("JF_DIST_ENABLED", "true") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_STRATEGY_NAME", "DNS") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_COOKIE", "testcookie") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_NODE_NAME", "[email protected]") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_QUERY", "my-app.example.com") | ||
|
||
assert ConfigReader.read_dist_config() == [ | ||
enabled: true, | ||
strategy: Cluster.Strategy.DNSPoll, | ||
node_name: :"[email protected]", | ||
cookie: :testcookie, | ||
nodes: [:"[email protected]", :"[email protected]"] | ||
strategy_config: [ | ||
polling_interval: 5_000, | ||
query: "my-app.example.com", | ||
node_basename: "testnodename" | ||
] | ||
] | ||
|
||
System.put_env( | ||
"JF_DIST_POLLING_INTERVAL", | ||
"10000" | ||
) | ||
|
||
assert ConfigReader.read_dist_config() == [ | ||
enabled: true, | ||
strategy: Cluster.Strategy.DNSPoll, | ||
node_name: :"[email protected]", | ||
cookie: :testcookie, | ||
strategy_config: [ | ||
polling_interval: 10_000, | ||
query: "my-app.example.com", | ||
node_basename: "testnodename" | ||
] | ||
] | ||
|
||
System.put_env("JF_DIST_POLLING_INTERVAL", "abcd") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
System.put_env("JF_DIST_POLLING_INTERVAL", "-25") | ||
assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end | ||
end | ||
end | ||
end |