예제 #1
0
 async def ping(self):
     histogram = Histogram("test_histogram",
                           description="desc",
                           boundaries=[0.1, 1.6])
     histogram = ray.get(ray.put(histogram))  # Test serialization.
     histogram.record(1.5)
     ray.get(worker_should_exit.wait.remote())
예제 #2
0
def test_basic_custom_metrics(metric_mock):
    # Make sure each of metric works as expected.
    # -- Count --
    count = Count("count", tag_keys=("a", ))
    with pytest.raises(TypeError):
        count.inc("hi")
    with pytest.raises(ValueError):
        count.inc(0)
        count.inc(-1)
    count._metric = metric_mock
    count.record(1, {"a": "1"})
    metric_mock.record.assert_called_with(1, tags={"a": "1"})

    # -- Gauge --
    gauge = Gauge("gauge", description="gauge")
    gauge._metric = metric_mock
    gauge.record(4)
    metric_mock.record.assert_called_with(4, tags={})

    # -- Histogram
    histogram = Histogram(
        "hist", description="hist", boundaries=[1.0, 3.0], tag_keys=("a", "b"))
    histogram._metric = metric_mock
    tags = {"a": "10", "b": "b"}
    histogram.record(8, tags=tags)
    metric_mock.record.assert_called_with(8, tags=tags)
예제 #3
0
class MyActor:
    def __init__(self, name):
        self._curr_count = 0

        self.counter = Counter(
            "num_requests",
            description="Number of requests processed by the actor.",
            tag_keys=("actor_name", ))
        self.counter.set_default_tags({"actor_name": name})

        self.gauge = Gauge(
            "curr_count",
            description="Current count held by the actor. Goes up and down.",
            tag_keys=("actor_name", ))
        self.gauge.set_default_tags({"actor_name": name})

        self.histogram = Histogram("request_latency",
                                   description="Latencies of requests in ms.",
                                   boundaries=[0.1, 1],
                                   tag_keys=("actor_name", ))
        self.histogram.set_default_tags({"actor_name": name})

    def process_request(self, num):
        start = time.time()
        self._curr_count += num

        # Increment the total request count.
        self.counter.inc()
        # Update the gauge to the new value.
        self.gauge.set(self._curr_count)
        # Record the latency for this request in ms.
        self.histogram.observe(1000 * (time.time() - start))

        return self._curr_count
예제 #4
0
def test_basic_custom_metrics(metric_mock):
    # Make sure each of metric works as expected.
    # -- Count --
    count = Count("count", tag_keys=("a", ))
    count._metric = metric_mock
    count.record(1)
    metric_mock.record.assert_called_with(1, tags={})

    # -- Gauge --
    gauge = Gauge("gauge", description="gauge")
    gauge._metric = metric_mock
    gauge.record(4)
    metric_mock.record.assert_called_with(4, tags={})

    # -- Histogram
    histogram = Histogram("hist",
                          description="hist",
                          boundaries=[1.0, 3.0],
                          tag_keys=("a", "b"))
    histogram._metric = metric_mock
    histogram.record(4)
    metric_mock.record.assert_called_with(4, tags={})
    tags = {"a": "3"}
    histogram.record(10, tags=tags)
    metric_mock.record.assert_called_with(10, tags=tags)
    tags = {"a": "10", "b": "b"}
    histogram.record(8, tags=tags)
    metric_mock.record.assert_called_with(8, tags=tags)
예제 #5
0
def test_custom_metrics_info(metric_mock):
    # Make sure .info public method works.
    histogram = Histogram(
        "hist", description="hist", boundaries=[1.0, 2.0], tag_keys=("a", "b"))
    assert histogram.info["name"] == "hist"
    assert histogram.info["description"] == "hist"
    assert histogram.info["boundaries"] == [1.0, 2.0]
    assert histogram.info["tag_keys"] == ("a", "b")
    assert histogram.info["default_tags"] == {}
    histogram.set_default_tags({"a": "a"})
    assert histogram.info["default_tags"] == {"a": "a"}
예제 #6
0
def test_custom_metrics_edge_cases(metric_mock):
    # None or empty boundaries are not allowed.
    with pytest.raises(ValueError):
        Histogram("hist")

    with pytest.raises(ValueError):
        Histogram("hist", boundaries=[])

    # Empty name is not allowed.
    with pytest.raises(ValueError):
        Count("")

    # The tag keys must be a tuple type.
    with pytest.raises(TypeError):
        Count("name", tag_keys=("a"))
예제 #7
0
파일: tracing_utils.py 프로젝트: parasj/ray
 def __init__(
     self,
     gauges: List[str],
     histograms: List[Tuple[str, List[int]]],
 ):
     self.counts = {m: 0 for m in gauges}
     self.gauges = {m: Gauge(m) for m in gauges}
     self.reset_gauges()
     self.histograms = {m: Histogram(m, boundaries=b) for m, b in histograms}
     logging_utils.init()
예제 #8
0
    def __init__(self, name):
        self._curr_count = 0

        self.counter = Counter(
            "num_requests",
            description="Number of requests processed by the actor.",
            tag_keys=("actor_name", ))
        self.counter.set_default_tags({"actor_name": name})

        self.gauge = Gauge(
            "curr_count",
            description="Current count held by the actor. Goes up and down.",
            tag_keys=("actor_name", ))
        self.gauge.set_default_tags({"actor_name": name})

        self.histogram = Histogram("request_latency",
                                   description="Latencies of requests in ms.",
                                   boundaries=[0.1, 1],
                                   tag_keys=("actor_name", ))
        self.histogram.set_default_tags({"actor_name": name})
예제 #9
0
def test_custom_metrics_default_tags(metric_mock):
    histogram = Histogram("hist",
                          description="hist",
                          boundaries=[1.0, 2.0],
                          tag_keys=("a", "b")).set_default_tags({"b": "b"})
    histogram._metric = metric_mock

    # Check default tags.
    histogram.record(4)
    metric_mock.record.assert_called_with(4, tags={"b": "b"})

    # Check specifying non-default tags.
    histogram.record(10, tags={"a": "a"})
    metric_mock.record.assert_called_with(10, tags={"a": "a", "b": "b"})

    # Check overriding default tags.
    tags = {"a": "10", "b": "c"}
    histogram.record(8, tags=tags)
    metric_mock.record.assert_called_with(8, tags=tags)