Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Runtime: add protocol information for service discovery (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrychenhf authored Aug 12, 2023
1 parent b41a536 commit e0f0a1a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
14 changes: 12 additions & 2 deletions python/cloudtik/core/_private/service_discovery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# The standard keys and values used for service discovery

SERVICE_DISCOVERY_PROTOCOL = "protocol"
SERVICE_DISCOVERY_PROTOCOL_TCP = "TCP"
SERVICE_DISCOVERY_PROTOCOL_TCP = "tcp"
SERVICE_DISCOVERY_PROTOCOL_HTTP = "http"

SERVICE_DISCOVERY_PORT = "port"

Expand Down Expand Up @@ -83,9 +84,12 @@ def define_runtime_service(
service_discovery_config: Optional[Dict[str, Any]],
service_port,
node_kind=SERVICE_DISCOVERY_NODE_KIND_NODE,
protocol: str = None,
metrics: bool = False):
if not protocol:
protocol = SERVICE_DISCOVERY_PROTOCOL_TCP
service_def = {
SERVICE_DISCOVERY_PROTOCOL: SERVICE_DISCOVERY_PROTOCOL_TCP,
SERVICE_DISCOVERY_PROTOCOL: protocol,
SERVICE_DISCOVERY_PORT: service_port,
}

Expand All @@ -107,35 +111,41 @@ def define_runtime_service(
def define_runtime_service_on_worker(
service_discovery_config: Optional[Dict[str, Any]],
service_port,
protocol: str = None,
metrics: bool = False):
return define_runtime_service(
service_discovery_config,
service_port,
node_kind=SERVICE_DISCOVERY_NODE_KIND_WORKER,
protocol=protocol,
metrics=metrics)


def define_runtime_service_on_head(
service_discovery_config,
service_port,
protocol: str = None,
metrics: bool = False):
return define_runtime_service(
service_discovery_config,
service_port,
node_kind=SERVICE_DISCOVERY_NODE_KIND_HEAD,
protocol=protocol,
metrics=metrics)


def define_runtime_service_on_head_or_all(
service_discovery_config,
service_port, head_or_all,
protocol: str = None,
metrics: bool = False):
node_kind = SERVICE_DISCOVERY_NODE_KIND_NODE \
if head_or_all else SERVICE_DISCOVERY_NODE_KIND_HEAD
return define_runtime_service(
service_discovery_config,
service_port,
node_kind=node_kind,
protocol=protocol,
metrics=metrics)


Expand Down
5 changes: 3 additions & 2 deletions python/cloudtik/runtime/ai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from cloudtik.core._private.providers import _get_node_provider, _get_workspace_provider
from cloudtik.core._private.runtime_factory import BUILT_IN_RUNTIME_AI
from cloudtik.core._private.service_discovery.utils import get_canonical_service_name, define_runtime_service_on_head, \
get_service_discovery_config
get_service_discovery_config, SERVICE_DISCOVERY_PROTOCOL_HTTP
from cloudtik.core._private.utils import export_runtime_flags
from cloudtik.runtime.common.utils import get_runtime_endpoints_of

Expand Down Expand Up @@ -93,6 +93,7 @@ def _get_runtime_services(
service_discovery_config, cluster_name, MLFLOW_SERVICE_NAME)
services = {
service_name: define_runtime_service_on_head(
service_discovery_config, MLFLOW_SERVICE_PORT),
service_discovery_config, MLFLOW_SERVICE_PORT,
protocol=SERVICE_DISCOVERY_PROTOCOL_HTTP),
}
return services
3 changes: 3 additions & 0 deletions python/cloudtik/runtime/consul/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
SERVICE_CHECK_TIMEOUT_DEFAULT = 5

CONSUL_TAG_CLUSTER_NAME_FORMAT = "cloudtik-c-{}"
CONSUL_TAG_PROTOCOL_FORMAT = "cloudtik-p-{}"
CONSUL_TAG_METRICS = "cloudtik-m-metrics"


Expand Down Expand Up @@ -152,6 +153,8 @@ def _generate_service_config(cluster_name, runtime_type, runtime_service):
if metrics:
tags.append(CONSUL_TAG_METRICS)

# TODO: protocol as tag

labels = get_config_for_update(
service_config, SERVICE_DISCOVERY_LABELS)

Expand Down
3 changes: 2 additions & 1 deletion python/cloudtik/runtime/grafana/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
get_services_of_runtime
from cloudtik.core._private.service_discovery.utils import \
get_canonical_service_name, define_runtime_service_on_head_or_all, get_service_discovery_config, \
SERVICE_DISCOVERY_PORT, serialize_service_selector
SERVICE_DISCOVERY_PORT, serialize_service_selector, SERVICE_DISCOVERY_PROTOCOL_HTTP
from cloudtik.core._private.utils import RUNTIME_CONFIG_KEY

RUNTIME_PROCESSES = [
Expand Down Expand Up @@ -161,6 +161,7 @@ def _get_runtime_services(
service_name: define_runtime_service_on_head_or_all(
service_discovery_config, service_port,
_is_high_availability(grafana_config),
protocol=SERVICE_DISCOVERY_PROTOCOL_HTTP,
metrics=True),
}
return services
Expand Down
2 changes: 0 additions & 2 deletions python/cloudtik/runtime/nginx/conf/nginx-web-base.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load_module /etc/nginx/modules/ngx_http_js_module.so;

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
Expand Down
6 changes: 4 additions & 2 deletions python/cloudtik/runtime/nginx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cloudtik.core._private.service_discovery.runtime_services import get_service_discovery_runtime
from cloudtik.core._private.service_discovery.utils import get_canonical_service_name, \
get_service_discovery_config, define_runtime_service_on_head_or_all, exclude_runtime_of_cluster, \
serialize_service_selector
serialize_service_selector, SERVICE_DISCOVERY_PROTOCOL_HTTP
from cloudtik.core._private.utils import RUNTIME_CONFIG_KEY
from cloudtik.runtime.common.service_discovery.consul import get_service_dns_name, select_dns_service_tag

Expand Down Expand Up @@ -125,7 +125,9 @@ def _get_runtime_services(
services = {
service_name: define_runtime_service_on_head_or_all(
service_discovery_config, service_port,
_is_high_availability(nginx_config))
_is_high_availability(nginx_config),
protocol=SERVICE_DISCOVERY_PROTOCOL_HTTP,
)
}
return services

Expand Down
3 changes: 2 additions & 1 deletion python/cloudtik/runtime/node_exporter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from cloudtik.core._private.service_discovery.utils import \
get_canonical_service_name, define_runtime_service, \
get_service_discovery_config
get_service_discovery_config, SERVICE_DISCOVERY_PROTOCOL_HTTP

RUNTIME_PROCESSES = [
# The first element is the substring to filter.
Expand Down Expand Up @@ -67,6 +67,7 @@ def _get_runtime_services(
services = {
service_name: define_runtime_service(
service_discovery_config, service_port,
protocol=SERVICE_DISCOVERY_PROTOCOL_HTTP,
metrics=True),
}
return services
3 changes: 2 additions & 1 deletion python/cloudtik/runtime/prometheus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
define_runtime_service_on_head_or_all, get_service_discovery_config, is_service_for_metrics, SERVICE_DISCOVERY_PORT, \
SERVICE_SELECTOR_SERVICES, SERVICE_SELECTOR_TAGS, SERVICE_SELECTOR_LABELS, SERVICE_SELECTOR_EXCLUDE_LABELS, \
SERVICE_SELECTOR_RUNTIMES, SERVICE_SELECTOR_CLUSTERS, SERVICE_DISCOVERY_LABEL_RUNTIME, \
SERVICE_DISCOVERY_LABEL_CLUSTER, SERVICE_SELECTOR_EXCLUDE_JOINED_LABELS
SERVICE_DISCOVERY_LABEL_CLUSTER, SERVICE_SELECTOR_EXCLUDE_JOINED_LABELS, SERVICE_DISCOVERY_PROTOCOL_HTTP
from cloudtik.core._private.utils import RUNTIME_CONFIG_KEY

RUNTIME_PROCESSES = [
Expand Down Expand Up @@ -224,6 +224,7 @@ def _get_runtime_services(
service_name: define_runtime_service_on_head_or_all(
service_discovery_config, service_port,
_is_high_availability(prometheus_config),
protocol=SERVICE_DISCOVERY_PROTOCOL_HTTP,
metrics=True)
}
return services
Expand Down

0 comments on commit e0f0a1a

Please sign in to comment.