Skip to content

Commit

Permalink
sonda: adapt setup for deployment (#3151)
Browse files Browse the repository at this point in the history
Referenced issue: status-im/infra-hq#135

Signed-off-by: markoburcul <[email protected]>
  • Loading branch information
markoburcul authored Oct 25, 2024
1 parent b4d3678 commit 02c8f35
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
12 changes: 7 additions & 5 deletions apps/sonda/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ EXTRA_ARGS=
RLN_RELAY_CONTRACT_ADDRESS=

# -------------------- SONDA CONFIG ------------------
METRICS_PORT=8004
NODE_REST_ADDRESS="http://nwaku:8645"
CLUSTER_ID=16
SHARD=32
# Comma separated list of store nodes to poll
STORE_NODES="/dns4/store-01.do-ams3.shards.test.status.im/tcp/30303/p2p/16Uiu2HAmAUdrQ3uwzuE4Gy4D56hX6uLKEeerJAnhKEHZ3DxF1EfT,\
/dns4/store-02.do-ams3.shards.test.status.im/tcp/30303/p2p/16Uiu2HAm9aDJPkhGxc2SFcEACTFdZ91Q5TJjp76qZEhq9iF59x7R,\
/dns4/store-01.gc-us-central1-a.shards.test.status.im/tcp/30303/p2p/16Uiu2HAmMELCo218hncCtTvC2Dwbej3rbyHQcR8erXNnKGei7WPZ,\
/dns4/store-02.gc-us-central1-a.shards.test.status.im/tcp/30303/p2p/16Uiu2HAmJnVR7ZzFaYvciPVafUXuYGLHPzSUigqAmeNw9nJUVGeM,\
/dns4/store-01.ac-cn-hongkong-c.shards.test.status.im/tcp/30303/p2p/16Uiu2HAm2M7xs7cLPc3jamawkEqbr7cUJX11uvY7LxQ6WFUdUKUT,\
STORE_NODES="/dns4/store-01.do-ams3.shards.test.status.im/tcp/30303/p2p/16Uiu2HAmAUdrQ3uwzuE4Gy4D56hX6uLKEeerJAnhKEHZ3DxF1EfT,
/dns4/store-02.do-ams3.shards.test.status.im/tcp/30303/p2p/16Uiu2HAm9aDJPkhGxc2SFcEACTFdZ91Q5TJjp76qZEhq9iF59x7R,
/dns4/store-01.gc-us-central1-a.shards.test.status.im/tcp/30303/p2p/16Uiu2HAmMELCo218hncCtTvC2Dwbej3rbyHQcR8erXNnKGei7WPZ,
/dns4/store-02.gc-us-central1-a.shards.test.status.im/tcp/30303/p2p/16Uiu2HAmJnVR7ZzFaYvciPVafUXuYGLHPzSUigqAmeNw9nJUVGeM,
/dns4/store-01.ac-cn-hongkong-c.shards.test.status.im/tcp/30303/p2p/16Uiu2HAm2M7xs7cLPc3jamawkEqbr7cUJX11uvY7LxQ6WFUdUKUT,
/dns4/store-02.ac-cn-hongkong-c.shards.test.status.im/tcp/30303/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P"
# Wait time in seconds between two consecutive queries
QUERY_DELAY=60
Expand Down
22 changes: 21 additions & 1 deletion apps/sonda/Dockerfile.sonda
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
FROM python:3.9.18-alpine3.18

RUN pip install requests argparse prometheus_client
ENV METRICS_PORT=8004
ENV NODE_REST_ADDRESS="http://nwaku:8645"
ENV QUERY_DELAY=60
ENV STORE_NODES=""
ENV CLUSTER_ID=1
ENV SHARD=1
ENV HEALTH_THRESHOLD=5

WORKDIR /opt

COPY sonda.py /opt/sonda.py

RUN pip install requests argparse prometheus_client

CMD python -u /opt/sonda.py \
--metrics-port=$METRICS_PORT \
--node-rest-address="${NODE_REST_ADDRESS}" \
--delay-seconds=$QUERY_DELAY \
--pubsub-topic="/waku/2/rs/${CLUSTER_ID}/${SHARD}" \
--store-nodes="${STORE_NODES}" \
--health-threshold=$HEALTH_THRESHOLD
29 changes: 18 additions & 11 deletions apps/sonda/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

version: "3.7"
x-logging: &logging
logging:
driver: json-file
Expand All @@ -15,6 +14,8 @@ x-rln-environment: &rln_env
RLN_RELAY_CRED_PASSWORD: ${RLN_RELAY_CRED_PASSWORD:-} # Optional: Add your RLN_RELAY_CRED_PASSWORD after the "-"

x-sonda-env: &sonda_env
METRICS_PORT: ${METRICS_PORT:-8004}
NODE_REST_ADDRESS: ${NODE_REST_ADDRESS:-"http://nwaku:8645"}
CLUSTER_ID: ${CLUSTER_ID:-1}
SHARD: ${SHARD:-0}
STORE_NODES: ${STORE_NODES:-}
Expand All @@ -24,7 +25,8 @@ x-sonda-env: &sonda_env
# Services definitions
services:
nwaku:
image: ${NWAKU_IMAGE:-harbor.status.im/wakuorg/nwaku:v0.30.1}
image: ${NWAKU_IMAGE:-harbor.status.im/wakuorg/nwaku:deploy-status-prod}
container_name: nwaku
restart: on-failure
ports:
- 30304:30304/tcp
Expand Down Expand Up @@ -54,29 +56,27 @@ services:
entrypoint: sh
command:
- /opt/run_node.sh
networks:
- nwaku-sonda

sonda:
build:
context: .
dockerfile: Dockerfile.sonda
container_name: sonda
ports:
- 127.0.0.1:8004:8004
- 127.0.0.1:${METRICS_PORT}:${METRICS_PORT}
environment:
<<:
- *sonda_env
command: >
python -u /opt/sonda.py
--delay-seconds=${QUERY_DELAY}
--pubsub-topic=/waku/2/rs/${CLUSTER_ID}/${SHARD}
--store-nodes=${STORE_NODES}
--health-threshold=${HEALTH_THRESHOLD}
volumes:
- ./sonda.py:/opt/sonda.py:Z
depends_on:
- nwaku
networks:
- nwaku-sonda

prometheus:
image: docker.io/prom/prometheus:latest
container_name: prometheus
volumes:
- ./monitoring/prometheus-config.yml:/etc/prometheus/prometheus.yml:Z
command:
Expand All @@ -86,9 +86,12 @@ services:
restart: on-failure:5
depends_on:
- nwaku
networks:
- nwaku-sonda

grafana:
image: docker.io/grafana/grafana:latest
container_name: grafana
env_file:
- ./monitoring/configuration/grafana-plugins.env
volumes:
Expand All @@ -104,4 +107,8 @@ services:
restart: on-failure:5
depends_on:
- prometheus
networks:
- nwaku-sonda

networks:
nwaku-sonda:
19 changes: 10 additions & 9 deletions apps/sonda/sonda.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@

# Argparser configuration
parser = argparse.ArgumentParser(description='')
parser.add_argument('-p', '--pubsub-topic', type=str, help='pubsub topic', default='/waku/2/rs/1/0')
parser.add_argument('-d', '--delay-seconds', type=int, help='delay in second between messages', default=60)
parser.add_argument('-n', '--store-nodes', type=str, help='comma separated list of store nodes to query', required=True)
parser.add_argument('-t', '--health-threshold', type=int, help='consecutive successful store requests to consider a store node healthy', default=5)
parser.add_argument('-m', '--metrics-port', type=int, default=8004, help='Port to expose prometheus metrics.')
parser.add_argument('-a', '--node-rest-address', type=str, default="http://nwaku:8645", help='Address of the waku node to send messages to.')
parser.add_argument('-p', '--pubsub-topic', type=str, default='/waku/2/rs/1/0', help='PubSub topic.')
parser.add_argument('-d', '--delay-seconds', type=int, default=60, help='Delay in seconds between messages.')
parser.add_argument('-n', '--store-nodes', type=str, required=True, help='Comma separated list of store nodes to query.')
parser.add_argument('-t', '--health-threshold', type=int, default=5, help='Consecutive successful store requests to consider a store node healthy.')
args = parser.parse_args()


Expand Down Expand Up @@ -178,22 +180,21 @@ def main():
store_nodes = [s.strip() for s in args.store_nodes.split(",")]
log_with_utc(f'Store nodes to query: {store_nodes}')

# Start Prometheus HTTP server at port 8004
start_http_server(8004)
# Start Prometheus HTTP server at port set by the CLI(default 8004)
start_http_server(args.metrics_port)

node_rest_address = 'http://nwaku:8645'
while True:
timestamp = time.time_ns()

# Send Sonda message
res = send_sonda_msg(node_rest_address, args.pubsub_topic, SONDA_CONTENT_TOPIC, timestamp)
res = send_sonda_msg(args.node_rest_address, args.pubsub_topic, SONDA_CONTENT_TOPIC, timestamp)

log_with_utc(f'sleeping: {args.delay_seconds} seconds')
time.sleep(args.delay_seconds)

# Only send store query if message was successfully published
if(res):
send_store_queries(node_rest_address, store_nodes, args.pubsub_topic, SONDA_CONTENT_TOPIC, timestamp)
send_store_queries(args.node_rest_address, store_nodes, args.pubsub_topic, SONDA_CONTENT_TOPIC, timestamp)

# Update node health metrics
for store_node in store_nodes:
Expand Down

0 comments on commit 02c8f35

Please sign in to comment.