Skip to content

Commit

Permalink
agents: remove start/stop from JS API
Browse files Browse the repository at this point in the history
The user shouldn't have access to start/stop. No need to expose them.

Also remove stop() completely.

PR-URL: #123
Reviewed-by: Santiago Gimeno <santiago.gimeno@gmail.com>
  • Loading branch information
trevnorris authored and santigimeno committed Jun 17, 2024
1 parent 9ff2ece commit 8cf3fd0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
12 changes: 0 additions & 12 deletions agents/statsd/src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ static void Send(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(StatsDAgent::Inst()->send(sv, full_size));
}

static void Start(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(StatsDAgent::Inst()->start());
}

static void Stop(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(StatsDAgent::Inst()->stop());
}

static void Tags(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
std::string tags = StatsDAgent::Inst()->tags();
Expand Down Expand Up @@ -156,9 +148,7 @@ static void RegisterStatusCb(const FunctionCallbackInfo<Value>& args) {
static void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(Bucket);
registry->Register(Send);
registry->Register(Start);
registry->Register(Status);
registry->Register(Stop);
registry->Register(Tags);
registry->Register(TcpIp);
registry->Register(UdpIp);
Expand All @@ -178,8 +168,6 @@ void InitStatsDAgent(Local<Object> exports,

NODE_SET_METHOD(exports, "bucket", Bucket);
NODE_SET_METHOD(exports, "send", Send);
NODE_SET_METHOD(exports, "start", Start);
NODE_SET_METHOD(exports, "stop", Stop);
NODE_SET_METHOD(exports, "tags", Tags);
NODE_SET_METHOD(exports, "tcpIp", TcpIp);
NODE_SET_METHOD(exports, "udpIp", UdpIp);
Expand Down
28 changes: 10 additions & 18 deletions agents/statsd/src/statsd_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,16 @@ StatsDAgent::StatsDAgent(): hooks_init_(false),

StatsDAgent::~StatsDAgent() {
int r;
ASSERT_EQ(0, stop());

if (status_ != Unconfigured) {
if (utils::are_threads_equal(thread_.base(), uv_thread_self())) {
do_stop();
} else {
ASSERT_EQ(0, shutdown_.send());
ASSERT_EQ(0, thread_.join());
}
}

uv_mutex_destroy(&start_lock_);
uv_cond_destroy(&start_cond_);
// The destructor will be called from the main thread, being StatsDAgent a
Expand Down Expand Up @@ -537,23 +546,6 @@ void StatsDAgent::do_start() {
uv_mutex_unlock(&start_lock_);
}

// This method can only be called:
// 1) From the StatsDAgent thread when disabling the agent via configuration.
// 2) From the main JS thread on exit as this is a static Singleton.
int StatsDAgent::stop() {
int r = 0;
if (status_ != Unconfigured) {
if (utils::are_threads_equal(thread_.base(), uv_thread_self())) {
do_stop();
} else {
ASSERT_EQ(0, shutdown_.send());
ASSERT_EQ(0, thread_.join());
}
}

return r;
}

void StatsDAgent::do_stop() {
{
nsuv::ns_rwlock::scoped_wrlock lock(stop_lock_);
Expand Down
5 changes: 3 additions & 2 deletions agents/statsd/src/statsd_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@ class StatsDAgent: public std::enable_shared_from_this<StatsDAgent> {

int setup_metrics_timer(uint64_t period);

// TODO(trevnorris): This is only meant to be used by the global instance,
// not by the public. Change the way the global instance works so that this
// isn't necessary.
int start();

int stop();

// Dynamically set the current configuration of the agent.
// The JSON schema of the currently supported configuration with its
// default values:
Expand Down

0 comments on commit 8cf3fd0

Please sign in to comment.