Repository navigation
logos-messaging: optional Store and Edge nodes #463
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
Open
radiken
wants to merge
6
commits into
master
Choose a base branch
from
alan/logos-messaging-store-edge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−24
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d3b686
logos-messaging: optional Store and Edge nodes
radiken 85bd487
logos-messaging: Edge nodes are ready at PartiallyConnected
radiken 0ff316f
logos-messaging: bootstrap without the filter service
radiken 4b8f3c9
logos-messaging: relay message lines at INFO from v0.40.0 on
radiken f61289e
logos-messaging: optional connection limit for the Store nodes
radiken 923c49c
logos-messaging: black formatting
radiken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,11 +4,19 @@ | |
| import logging | ||
| import random | ||
| from datetime import timedelta | ||
| from typing import List, Literal | ||
| from typing import List, Literal, Optional | ||
|
|
||
| import aiohttp | ||
| from kubernetes.client import V1Probe | ||
| from pydantic import BaseModel, ConfigDict, Field, NonNegativeFloat, NonNegativeInt, PositiveInt | ||
| from pydantic import ( | ||
| BaseModel, | ||
| ConfigDict, | ||
| Field, | ||
| NonNegativeFloat, | ||
| NonNegativeInt, | ||
| PositiveInt, | ||
| model_validator, | ||
| ) | ||
|
|
||
| # Project Imports | ||
| from src.deployments.core.configs.container import Image | ||
|
|
@@ -24,7 +32,7 @@ | |
| from src.deployments.registry import experiment | ||
| from src.deployments.waku.bridge import Bridge | ||
| from src.deployments.waku.builders.builders import WakuStatefulSetBuilder | ||
| from src.deployments.waku.builders.helpers import find_waku_container_config | ||
| from src.deployments.waku.builders.helpers import find_waku_command, find_waku_container_config | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -41,6 +49,18 @@ class ExpConfig(BaseModel): | |
|
|
||
| num_relay_nodes: PositiveInt = 20 | ||
| num_bootstrap_nodes: PositiveInt = 3 | ||
| num_store_nodes: NonNegativeInt = 0 | ||
| """Store nodes without the Messaging API.""" | ||
| store_max_connections: Optional[PositiveInt] = None | ||
| """`--max-connections` on the Store nodes, the regression default when unset.""" | ||
| num_edge_nodes: NonNegativeInt = 0 | ||
| """Messaging API nodes in Edge mode, sent to like the relays.""" | ||
| reliability: bool = False | ||
| """Confirm each send with a Store node.""" | ||
| idle_before_edge: NonNegativeFloat = 0 | ||
| """Wait between the relays and Store nodes being ready and deploying the Edge nodes.""" | ||
| delay_cold_start: NonNegativeFloat = 0 | ||
| """Wait between all nodes being ready and the first send.""" | ||
| num_messages: NonNegativeInt = 20 | ||
| msg_size_kbytes: PositiveInt = 1 | ||
| delay_after_publish: NonNegativeFloat = 1 | ||
|
|
@@ -58,6 +78,14 @@ class ExpConfig(BaseModel): | |
| ) | ||
| ) | ||
|
|
||
| @model_validator(mode="after") | ||
| def check_store_nodes(self): | ||
| if self.reliability and not self.num_store_nodes: | ||
| raise ValueError("reliability needs Store nodes") | ||
| if self.num_edge_nodes and not self.num_store_nodes: | ||
| raise ValueError("Edge nodes need a Store peer to report PartiallyConnected") | ||
|
Comment on lines
+85
to
+86
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still a thing? |
||
| return self | ||
|
|
||
|
|
||
| class MessagingBridge(Bridge): | ||
| interval: Literal["complete", "messages"] = "messages" | ||
|
|
@@ -81,34 +109,75 @@ def build_bootstrap(namespace: str, config: ExpConfig) -> V1Deployable: | |
| ) | ||
| .with_bootstrap(CMD_TYPE) | ||
| .with_env("SERVICE", "zerotesting-bootstrap") | ||
| .with_args({"--log-level": config.log_level}, on_duplicate="replace") | ||
| .with_args({"--log-level": config.log_level, "--filter": False}, on_duplicate="replace") | ||
| .with_binary(LOGOS_DELIVERY_BINARY) | ||
| .with_image(config.image) | ||
| .build() | ||
| ) | ||
|
|
||
|
|
||
| def build_relays(namespace: str, config: ExpConfig) -> V1Deployable: | ||
| args = { | ||
| "--log-level": config.log_level, | ||
| "--entry-layer": "messaging", | ||
| "--reliability": "false", | ||
| } | ||
| builder = ( | ||
| def node_builder( | ||
| name: str, num_nodes: int, namespace: str, config: ExpConfig, args: dict | ||
| ) -> WakuStatefulSetBuilder: | ||
| return ( | ||
| WakuStatefulSetBuilder() | ||
| .with_waku_config(name="relay-0", namespace=namespace, num_nodes=config.num_relay_nodes) | ||
| .with_waku_config(name=name, namespace=namespace, num_nodes=num_nodes) | ||
| .with_regression(CMD_TYPE, config.num_bootstrap_nodes) | ||
| .with_env("SERVICE", "zerotesting-bootstrap") | ||
| .with_args(args, on_duplicate="replace") | ||
| .with_binary(LOGOS_DELIVERY_BINARY) | ||
| .with_image(config.image) | ||
| .with_env("RELAY_MSG_INFO_LOGS", "1") | ||
| .with_args({"--log-level": config.log_level, **args}, on_duplicate="replace") | ||
| ) | ||
|
|
||
|
|
||
| def messaging_builder( | ||
| name: str, num_nodes: int, namespace: str, config: ExpConfig, args: dict | ||
| ) -> WakuStatefulSetBuilder: | ||
| """Messaging API nodes that subscribe to the content topic at startup.""" | ||
| args = { | ||
| "--entry-layer": "messaging", | ||
| "--reliability": str(config.reliability).lower(), | ||
| **args, | ||
| } | ||
| builder = node_builder(name, num_nodes, namespace, config, args) | ||
| container = find_waku_container_config(builder.config) | ||
| container.command_config.insert_commands([subscribe_on_start(config.content_topic)], index=0) | ||
| return builder | ||
|
|
||
|
|
||
| def build_relays(namespace: str, config: ExpConfig) -> V1Deployable: | ||
| builder = messaging_builder("relay-0", config.num_relay_nodes, namespace, config, {}) | ||
| container = find_waku_container_config(builder.config) | ||
| container.with_readiness_probe( | ||
| messaging_readiness_probe(container.readiness_probe, config.content_topic), overwrite=True | ||
| ) | ||
| return builder.build() | ||
| return builder.with_binary(LOGOS_DELIVERY_BINARY).with_image(config.image).build() | ||
|
|
||
|
|
||
| def build_edge_nodes(namespace: str, config: ExpConfig) -> V1Deployable: | ||
| """Edge mode nodes. They find their filter, lightpush and Store peers through discv5.""" | ||
| builder = messaging_builder( | ||
| "edge-0", config.num_edge_nodes, namespace, config, {"--mode": "Edge"} | ||
| ) | ||
| container = find_waku_container_config(builder.config) | ||
| command = find_waku_command(container.command_config) | ||
| # Edge mode only sets flags that are unset, so an explicit --relay would keep relay on. | ||
| command.args = [ | ||
| arg for arg in command.args if not (isinstance(arg, tuple) and arg[0] == "--relay") | ||
| ] | ||
| container.with_readiness_probe( | ||
| edge_readiness_probe(container.readiness_probe, config.content_topic), overwrite=True | ||
| ) | ||
| return builder.with_binary(LOGOS_DELIVERY_BINARY).with_image(config.image).build() | ||
|
|
||
|
|
||
| def build_store_nodes(namespace: str, config: ExpConfig) -> V1Deployable: | ||
| """Relays without the Messaging API that archive every message in a Postgres sidecar.""" | ||
| args = ( | ||
| {"--max-connections": config.store_max_connections} if config.store_max_connections else {} | ||
| ) | ||
| builder = node_builder("store-0", config.num_store_nodes, namespace, config, args).with_store() | ||
| builder.config.namespace = namespace | ||
| return builder.with_binary(LOGOS_DELIVERY_BINARY).with_image(config.image).build() | ||
|
|
||
|
|
||
| def subscribe_on_start(content_topic: str) -> str: | ||
|
|
@@ -120,17 +189,32 @@ def subscribe_on_start(content_topic: str) -> str: | |
| ) | ||
|
|
||
|
|
||
| def messaging_readiness_probe(mesh_probe: V1Probe, content_topic: str) -> V1Probe: | ||
| """`mesh_probe` (topic mesh >= dLow), after a subscription check that latches once it passes.""" | ||
| subscribed = ( | ||
| def subscription_check(content_topic: str) -> str: | ||
| """Shell check that the node is subscribed to the topic. It latches once it passes.""" | ||
| return ( | ||
| f"[ -f /tmp/subscribed ] || {{ curl -sf localhost:{REST_PORT}/messaging/v1/subscriptions" | ||
| f" | grep -qF '\"{content_topic}\"' && touch /tmp/subscribed; }} || exit 1;\n" | ||
| ) | ||
|
|
||
|
|
||
| def messaging_readiness_probe(mesh_probe: V1Probe, content_topic: str) -> V1Probe: | ||
| """`mesh_probe` (topic mesh >= dLow), after a subscription check that latches once it passes.""" | ||
| shell, flag, check = mesh_probe._exec.command | ||
| mesh_probe._exec.command = [shell, flag, subscribed + check] | ||
| mesh_probe._exec.command = [shell, flag, subscription_check(content_topic) + check] | ||
| return mesh_probe | ||
|
|
||
|
|
||
| def edge_readiness_probe(probe: V1Probe, content_topic: str) -> V1Probe: | ||
| """`probe` timings, the subscription check, then `/health` at least `PartiallyConnected`.""" | ||
| connected = ( | ||
| f"curl -sf localhost:{REST_PORT}/health" | ||
| f' | grep -qE \'"connectionStatus":"(Partially)?Connected"\'\n' | ||
| ) | ||
| shell, flag, _ = probe._exec.command | ||
| probe._exec.command = [shell, flag, subscription_check(content_topic) + connected] | ||
| return probe | ||
|
|
||
|
|
||
| @experiment(name="logos-messaging") | ||
| class LogosMessagingExperiment(BaseExperiment[ExpConfig]): | ||
| """Relay nodes on the Messaging API, sent to over REST and measured from their logs.""" | ||
|
|
@@ -171,12 +255,22 @@ async def _run(self): | |
|
|
||
| await self.deploy(deployment=build_bootstrap(self.namespace, self.config)) | ||
| relays = build_relays(self.namespace, self.config) | ||
| await self.deploy(deployment=relays) | ||
| stores = ( | ||
| [build_store_nodes(self.namespace, self.config)] if self.config.num_store_nodes else [] | ||
| ) | ||
| await self.deploy(deployment=[relays, *stores]) | ||
| senders = [relays] | ||
| if self.config.num_edge_nodes: | ||
| if not self.dry_run: | ||
| await asyncio.sleep(self.config.idle_before_edge) | ||
| senders.append(build_edge_nodes(self.namespace, self.config)) | ||
| await self.deploy(deployment=senders[-1]) | ||
| if self.dry_run: | ||
| self.log_event("dry_run_done") | ||
| return | ||
|
|
||
| pods = [f"{relays.metadata.name}-{index}" for index in range(relays.spec.replicas)] | ||
| await asyncio.sleep(self.config.delay_cold_start) | ||
| pods = [f"{s.metadata.name}-{index}" for s in senders for index in range(s.spec.replicas)] | ||
| requester = requester_address(self.namespace) | ||
| await clear_requester_cache(requester) | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What it means Bootstrap and Store nodes have no API. They do not have messaging API?