Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agents/grpc/proto/reconfigure.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ message ReconfigureBody {
optional bool tracingEnabled = 10;
optional uint32 tracingModulesBlacklist = 11;
optional bool contCpuProfile = 12;
optional bool assetsEnabled = 13;
}

message ReconfigureEvent {
Expand Down
44 changes: 32 additions & 12 deletions agents/grpc/src/grpc_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ void PopulateReconfigureEvent(grpcagent::ReconfigureEvent* reconfigure_event,
if (it != config.end()) {
body->set_contcpuprofile(*it);
}
it = config.find("assetsEnabled");
if (it != config.end()) {
body->set_assetsenabled(*it);
}
}

void PopulateStartupTimesEvent(grpcagent::StartupTimesEvent* st_events,
Expand Down Expand Up @@ -424,6 +428,8 @@ GrpcAgent::GrpcAgent(): hooks_init_(false),
agent_id_(GetAgentId()),
auth_retries_(0),
unauthorized_(false),
assets_enabled_(true),
cont_cpu_profile_enabled_(false),
profile_on_exit_(false) {
ASSERT_EQ(0, uv_loop_init(&loop_));
ASSERT_EQ(0, uv_cond_init(&start_cond_));
Expand Down Expand Up @@ -1170,12 +1176,19 @@ int GrpcAgent::config(const json& config) {
ret = setup_metrics_timer(period);
}

// uint64_t period = NSOLID_SPANS_FLUSH_INTERVAL;
// auto spans_flush_interval =
// per_process::system_environment->Get(kNSOLID_SPANS_FLUSH_INTERVAL);
// if (spans_flush_interval.has_value()) {
// period = std::stoull(spans_flush_interval.value());
// }
{
auto it = config_.find("assetsEnabled");
if (it != config_.end() && it->is_boolean()) {
assets_enabled_.store(*it, std::memory_order_release);
}
}

{
auto it = config_.find("contCpuProfile");
if (it != config_.end() && it->is_boolean()) {
cont_cpu_profile_enabled_.store(*it, std::memory_order_release);
}
}

return ret;
}
Expand Down Expand Up @@ -1731,6 +1744,10 @@ void GrpcAgent::reconfigure(const grpcagent::CommandRequest& request) {
out["contCpuProfile"] = body.contcpuprofile();
}

if (body.has_assetsenabled()) {
out["assetsEnabled"] = body.assetsenabled();
}

DebugJSON("Reconfigure out: \n%s\n", out);

UpdateConfig(out.dump());
Expand Down Expand Up @@ -2068,18 +2085,21 @@ ErrorType GrpcAgent::do_start_prof_init(
const grpcagent::CommandRequest& req,
const ProfileType& type,
ProfileOptions& options) {

if (!assets_enabled_.load(std::memory_order_acquire)) {
return ErrorType::EAssetsDisabled;
}

const grpcagent::ProfileArgs& args = req.args().profile();
uint64_t thread_id = args.thread_id();
uint64_t duration = args.duration();
StartProfiling start_profiling = nullptr;

// Check if continuous profiling is enabled for this profile type
if (type == ProfileType::kCpu) {
auto it = config_.find("contCpuProfile");
if (it != config_.end() && it->get<bool>() == true) {
// Continuous CPU profiling is enabled, don't allow manual CPU profiles
return ErrorType::EInProgressError;
}
if (type == ProfileType::kCpu &&
cont_cpu_profile_enabled_.load(std::memory_order_acquire)) {
// Continuous CPU profiling is enabled, don't allow manual CPU profiles
return ErrorType::EInProgressError;
}

switch (type) {
Expand Down
2 changes: 2 additions & 0 deletions agents/grpc/src/grpc_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ class GrpcAgent: public std::enable_shared_from_this<GrpcAgent>,
log_exporter_;

// Profiling
std::atomic<bool> assets_enabled_;
std::atomic<bool> cont_cpu_profile_enabled_;
nsuv::ns_mutex profile_state_lock_;
ProfileState profile_state_[ProfileType::kNumberOfProfileTypes];
std::atomic<bool> profile_on_exit_;
Expand Down
3 changes: 2 additions & 1 deletion agents/grpc/src/grpc_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
X(ESnapshotDisabled, 500, "Heap Snapshots disabled", 1004) \
X(ENoMemory, 500, "Internal Runtime Error", 1005) \
X(ENotAvailable, 404, "Resource not available", 1006) \
X(ESourceCodeFileError, 500, "Internal Runtime Error", 1007)
X(ESourceCodeFileError, 500, "Internal Runtime Error", 1007) \
X(EAssetsDisabled, 500, "Assets collection disabled", 1008)

namespace node {
namespace nsolid {
Expand Down
78 changes: 48 additions & 30 deletions agents/grpc/src/proto/reconfigure.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading