mirror of
https://github.com/wassname/ray.git
synced 2026-08-12 12:20:11 +08:00
[Metrics] Call GetMeasureDoubleByName to prevent override (#12860)
This commit is contained in:
@@ -2,6 +2,7 @@ import json
|
||||
import pathlib
|
||||
import platform
|
||||
from pprint import pformat
|
||||
import time
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import requests
|
||||
@@ -293,6 +294,33 @@ def test_custom_metrics_edge_cases(metric_mock):
|
||||
Count("name", tag_keys=("a"))
|
||||
|
||||
|
||||
def test_metrics_override_shouldnt_warn(ray_start_regular, log_pubsub):
|
||||
# https://github.com/ray-project/ray/issues/12859
|
||||
|
||||
@ray.remote
|
||||
def override():
|
||||
a = Count("num_count", description="")
|
||||
b = Count("num_count", description="")
|
||||
a.record(1)
|
||||
b.record(1)
|
||||
|
||||
ray.get(override.remote())
|
||||
|
||||
# Check the stderr from the worker.
|
||||
start = time.time()
|
||||
while True:
|
||||
if (time.time() - start) > 5:
|
||||
break
|
||||
msg = log_pubsub.get_message()
|
||||
if msg is None:
|
||||
time.sleep(0.01)
|
||||
continue
|
||||
|
||||
log_lines = json.loads(ray.utils.decode(msg["data"]))["lines"]
|
||||
for line in log_lines:
|
||||
assert "Attempt to register measure" not in line
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
sys.exit(pytest.main(["-v", __file__]))
|
||||
|
||||
+13
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "opencensus/stats/internal/aggregation_window.h"
|
||||
#include "opencensus/stats/internal/set_aggregation_window.h"
|
||||
#include "opencensus/stats/measure_registry.h"
|
||||
|
||||
namespace ray {
|
||||
|
||||
@@ -78,14 +79,24 @@ bool StatsConfig::IsInitialized() const { return is_initialized_; }
|
||||
///
|
||||
/// Metric
|
||||
///
|
||||
using MeasureDouble = opencensus::stats::Measure<double>;
|
||||
void Metric::Record(double value, const TagsType &tags) {
|
||||
if (StatsConfig::instance().IsStatsDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (measure_ == nullptr) {
|
||||
measure_.reset(new opencensus::stats::Measure<double>(
|
||||
opencensus::stats::Measure<double>::Register(name_, description_, unit_)));
|
||||
// Measure could be registered before, so we try to get it first.
|
||||
MeasureDouble registered_measure =
|
||||
opencensus::stats::MeasureRegistry::GetMeasureDoubleByName(name_);
|
||||
|
||||
if (registered_measure.IsValid()) {
|
||||
measure_.reset(new MeasureDouble(registered_measure));
|
||||
} else {
|
||||
measure_.reset(
|
||||
new MeasureDouble(MeasureDouble::Register(name_, description_, unit_)));
|
||||
}
|
||||
|
||||
RegisterView();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user