Skip to content

Commit

Permalink
PullRequest: 303 Optimize metric configs (mars-project#2996)
Browse files Browse the repository at this point in the history
Merge branch cp-from-github-2996 of git@gitlab.alipay-inc.com:ray-project/mars.git into master
https://code.alipay.com/ray-project/mars/pull_requests/303?tab=diff

Signed-off-by: 慕白 <chaokun.yck@antgroup.com>


* Optimize metric configs (mars-project#2996)
  • Loading branch information
不涸 committed May 6, 2022
1 parent 9a99b9a commit f6f2d9b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion mars/deploy/oscar/base_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ web:
access_log_level: warning
metrics:
backend: console
port: 0 # Need to assign a port argument when using prometheus
# If backend is prometheus, then we can add prometheus config as follows:
# prometheus:
# port: 8988
3 changes: 2 additions & 1 deletion mars/deploy/oscar/ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ async def start(self):
logger.info("Start cluster with config %s", self._config)
# init metrics to guarantee metrics use in driver
metric_configs = self._config.get("metrics", {})
init_metrics(metric_configs.get("backend"), port=metric_configs.get("port"))
metric_backend = metric_configs.get("backend")
init_metrics(metric_backend, config=metric_configs.get(metric_backend))
address_to_resources = dict()
supervisor_standalone = (
self._config.get("cluster", {})
Expand Down
7 changes: 4 additions & 3 deletions mars/metrics/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.

import logging
import time

from contextlib import contextmanager
from enum import Enum
from queue import PriorityQueue
import time
from typing import Optional, Tuple, NamedTuple, Callable, List
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple

from .backends.console import console_metric
from .backends.prometheus import prometheus_metric
Expand All @@ -34,7 +34,7 @@
}


def init_metrics(backend="console", port=0):
def init_metrics(backend="console", config: Dict[str, Any] = None):
backend = backend or "console"
if backend not in _backends_cls:
raise NotImplementedError(f"Do not support metric backend {backend}")
Expand All @@ -44,6 +44,7 @@ def init_metrics(backend="console", port=0):
try:
from prometheus_client import start_http_server

port = config.get("port", 0) if config else 0
start_http_server(port)
logger.info("Finished startup prometheus http server and port is %d", port)
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion mars/metrics/tests/test_metric_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_init_metrics():
assert api._metric_backend == "console"
init_metrics("prometheus")
assert api._metric_backend == "prometheus"
init_metrics(backend="prometheus", port=0)
init_metrics(backend="prometheus", config={"port": 0})
assert api._metric_backend == "prometheus"
init_metrics("ray")
assert api._metric_backend == "ray"
Expand Down
3 changes: 2 additions & 1 deletion mars/oscar/backends/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def __init__(
init_extension_entrypoints()
# init metrics
metric_configs = self._config.get_metric_configs()
init_metrics(metric_configs.get("backend"), port=metric_configs.get("port"))
metric_backend = metric_configs.get("backend")
init_metrics(metric_backend, config=metric_configs.get(metric_backend))
if "MARS_LOG_LEVEL" in os.environ:
level = os.environ["MARS_LOG_LEVEL"].upper()
level = getattr(logging, level)
Expand Down

0 comments on commit f6f2d9b

Please sign in to comment.