Skip to content
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

[INF-187] Add elastic search to discovery provider #3800

Merged
merged 4 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions dev-tools/audius-compose
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import eth_account
import solana.keypair


def generate_env(protocol_dir, creator_node_replicas):
def generate_env(protocol_dir, creator_node_replicas, discovery_provider_replicas):
config = {}
if (protocol_dir / "dev-tools/config.json").exists():
config = json.load((protocol_dir / "dev-tools/config.json").open())

env = {}

env["CREATOR_NODE_REPLICAS"] = str(creator_node_replicas)

env["DISCOVERY_PROVIDER_REPLICAS"] = str(discovery_provider_replicas)

env["CONTENT_NODE_VERSION"] = json.loads(
(protocol_dir / "creator-node/.version.json").read_text(),
)["version"]
Expand Down Expand Up @@ -104,9 +108,10 @@ def cli(ctx, protocol_dir):

@cli.command()
@click.option("-c", "--creator-node-replicas", default=3, type=int)
@click.option("-d", "--discovery-provider-replicas", default=3, type=int)
@click.pass_obj
def build(protocol_dir, creator_node_replicas):
generate_env(protocol_dir, creator_node_replicas)
def build(protocol_dir, creator_node_replicas, discovery_provider_replicas):
generate_env(protocol_dir, creator_node_replicas, discovery_provider_replicas)

subprocess.run(
[
Expand All @@ -124,7 +129,7 @@ def build(protocol_dir, creator_node_replicas):
@click.option("-d", "--discovery-provider-replicas", default=3, type=int)
@click.pass_obj
def up(protocol_dir, creator_node_replicas, discovery_provider_replicas):
generate_env(protocol_dir, creator_node_replicas)
generate_env(protocol_dir, creator_node_replicas, discovery_provider_replicas)

subprocess.run(
[
Expand All @@ -134,10 +139,6 @@ def up(protocol_dir, creator_node_replicas, discovery_provider_replicas):
protocol_dir,
"up",
"--build",
"--scale",
f"creator-node={creator_node_replicas}",
"--scale",
f"discovery-provider={discovery_provider_replicas}",
"-d",
],
)
Expand Down Expand Up @@ -212,7 +213,7 @@ def ps(protocol_dir):

print(
"CONTAINER ID".ljust(13),
"NAME".ljust(25),
"NAME".ljust(35),
"STATUS".ljust(10),
"PORTS",
)
Expand All @@ -237,13 +238,15 @@ def ps(protocol_dir):
if service["Service"] == "discovery-provider":
name = f"{service['Service']}-{replica}"
ports[5000 + replica - 1] = 5000
if service["Service"] == "discovery-provider-elasticsearch":
name = f"{service['Service']}-{replica}"

ports = sorted(ports.items())
ports = ", ".join(f"{target}->{published}" for target, published in ports)

print(
service["ID"][:12].ljust(13),
name.ljust(25),
name.ljust(35),
status.ljust(10),
ports,
)
Expand Down
6 changes: 6 additions & 0 deletions dev-tools/startup/discovery-provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ export audius_discprov_url="http://$(hostname -i):5000"
export audius_delegate_owner_wallet=$(printenv "DP${replica}_DELEGATE_OWNER_ADDRESS")
export audius_delegate_private_key=$(printenv "DP${replica}_DELEGATE_OWNER_PRIVATE_KEY")

elasticsearch_host=$(nslookup $(hostname -i) | grep -o "name = .*" | grep -o "[^ ]\+$" | sed 's/discovery-provider/discovery-provider-elasticsearch/')
if nslookup "$elasticsearch_host" >/dev/null 2>&1; then
export audius_elasticsearch_url="http://$elasticsearch_host:9200"
export audius_elasticsearch_run_indexer="true"
fi

# Run register script in background as it waits for the node to be healthy
./scripts/register.py &
30 changes: 29 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@ services:

# discovery-provider

discovery-provider-elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.1.0
environment:
discovery.type: single-node
xpack.security.enabled: false
ES_JAVA_OPTS: -Xms512m -Xmx512m
healthcheck:
test:
[
"CMD-SHELL",
"curl --fail http://localhost:9200/_cluster/health || exit 1"
]
interval: 10s
timeout: 5s
retries: 15
logging: *default-logging
deploy:
mode: replicated
replicas: "${DISCOVERY_PROVIDER_REPLICAS}"

discovery-provider:
build: discovery-provider
command: sh -c ". /tmp/dev-tools/startup/startup.sh && scripts/start.sh"
Expand All @@ -319,7 +339,9 @@ services:

audius_discprov_dev_mode: "true"
volumes:
- ./discovery-provider:/audius-discovery-provider
- ./discovery-provider/alembic:/audius-discovery-provider/alembic
- ./discovery-provider/solana-tx-parser:/audius-discovery-provider/solana-tx-parser
- ./discovery-provider/src:/audius-discovery-provider/src
- poa-contracts-abis:/audius-discovery-provider/build/contracts
- eth-contracts-abis:/audius-discovery-provider/build/eth-contracts
- solana-programs-idl:/audius-discovery-provider/idl
Expand All @@ -331,9 +353,12 @@ services:
condition: service_healthy
solana-test-validator:
condition: service_healthy
discovery-provider-elasticsearch:
condition: service_healthy
logging: *default-logging
deploy:
mode: replicated
replicas: "${DISCOVERY_PROVIDER_REPLICAS}"

# creator-node

Expand Down Expand Up @@ -381,6 +406,9 @@ services:
logging: *default-logging
deploy:
mode: replicated
replicas: "${CREATOR_NODE_REPLICAS}"

# port forwarder

proxy:
image: alpine:3.16.0
Expand Down