Skip to content
Closed
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
27 changes: 22 additions & 5 deletions agents/grpc/src/grpc_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ int GrpcAgent::config(const json& config) {
auto insecure_str =
per_process::system_environment->Get(kNSOLID_GRPC_INSECURE);
// Only parse the insecure flag in non SaaS mode.
if (!saas_ && insecure_str.has_value()) {
if (insecure_str.has_value() && (!saas_ || saas_->testing)) {
// insecure = std::stoull(insecure_str.value());
insecure = std::stoi(insecure_str.value());
}
Expand Down Expand Up @@ -1666,11 +1666,28 @@ void GrpcAgent::parse_saas_token(const std::string& token) {
return;
}

std::string endpoint;
bool is_testing = false;
bool is_staging = token.find("staging") != std::string::npos;
std::string endpoint = is_staging ?
console_id + ".grpc.staging.nodesource.io:443" :
console_id + ".grpc.nodesource.io:443";
saas_ = std::make_unique<SaaSInfo>(SaaSInfo{token, std::move(endpoint)});
if (is_staging) {
endpoint = console_id + ".grpc.staging.nodesource.io:443";
} else {
is_testing = token.find("testing") != std::string::npos;
if (is_testing) {
// For testing, set endpoint to the string after the last dot in the token
size_t last_dot = token.rfind('.');
if (last_dot != std::string::npos && last_dot + 1 < token.size()) {
endpoint = token.substr(last_dot + 1);
} else {
endpoint = "localhost:50051"; // fallback if no dot is found
}
} else {
endpoint = console_id + ".grpc.nodesource.io:443";
}
}

saas_ = std::make_unique<SaaSInfo>(
SaaSInfo{token, std::move(endpoint), is_testing});
}

bool GrpcAgent::pending_profiles() const {
Expand Down
1 change: 1 addition & 0 deletions agents/grpc/src/grpc_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class GrpcAgent: public std::enable_shared_from_this<GrpcAgent>,
struct SaaSInfo {
std::string token;
std::string endpoint;
bool testing;
};

GrpcAgent();
Expand Down
4 changes: 1 addition & 3 deletions lib/nsolid.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ function updateConfig(config = {}) {

if (nsolidConfig.saas) {
if (!config.command) {
nsolidConfig.command = undefined;
nsolidConfig.command = null;
}

if (nsolidConfig.command) {
Expand All @@ -724,8 +724,6 @@ function updateConfig(config = {}) {
const url = parseSaasEnvVar(nsolidConfig.saas, 0);
if (!url) {
nsolidConfig.saas = undefined;
} else if (!nsolidConfig.grpc) {
nsolidConfig.command = url;
} else {
nsolidConfig.grpc = '' + config.grpc;
}
Expand Down
61 changes: 34 additions & 27 deletions test/agents/test-grpc-basic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const tests = [];

tests.push({
name: 'should work if agent is killed with signal',
test: async () => {
test: async (getEnv) => {
return new Promise((resolve) => {
const grpcServer = new GRPCServer();
grpcServer.start(mustSucceed(async (port) => {
Expand All @@ -23,11 +23,7 @@ tests.push({
resolve();
}));

const env = {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_GRPC: `localhost:${port}`,
};
const env = getEnv(port);

const opts = {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
Expand All @@ -43,7 +39,7 @@ tests.push({

tests.push({
name: 'should work if agent exits gracefully without error',
test: async () => {
test: async (getEnv) => {
return new Promise((resolve) => {
const grpcServer = new GRPCServer();
grpcServer.start(mustSucceed(async (port) => {
Expand All @@ -53,11 +49,7 @@ tests.push({
resolve();
}));

const env = {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_GRPC: `localhost:${port}`,
};
const env = getEnv(port);

const opts = {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
Expand All @@ -76,7 +68,7 @@ tests.push({

tests.push({
name: 'should work if agent exits gracefully with error code',
test: async () => {
test: async (getEnv) => {
return new Promise((resolve) => {
const grpcServer = new GRPCServer();
grpcServer.start(mustSucceed(async (port) => {
Expand All @@ -86,11 +78,7 @@ tests.push({
resolve();
}));

const env = {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_GRPC: `localhost:${port}`,
};
const env = getEnv(port);

const opts = {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
Expand All @@ -109,7 +97,7 @@ tests.push({

tests.push({
name: 'should work if agent exits with exception',
test: async () => {
test: async (getEnv) => {
return new Promise((resolve) => {
const grpcServer = new GRPCServer();
grpcServer.start(mustSucceed(async (port) => {
Expand All @@ -120,11 +108,7 @@ tests.push({
resolve();
}));

const env = {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_GRPC: `localhost:${port}`,
};
const env = getEnv(port);

const opts = {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
Expand All @@ -141,7 +125,30 @@ tests.push({
},
});

for (const { name, test } of tests) {
console.log(`[basic] ${name}`);
await test();
const testConfigs = [
{
getEnv: (port) => {
return {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_GRPC: `localhost:${port}`,
};
},
},
{
getEnv: (port) => {
return {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_SAAS: `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbtesting.localhost:${port}`,
};
},
},
];

for (const testConfig of testConfigs) {
for (const { name, test } of tests) {
console.log(`[basic] ${name}`);
await test(testConfig.getEnv);
}
}
47 changes: 30 additions & 17 deletions test/agents/test-grpc-blocked-loop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const tests = [];

tests.push({
name: 'should work in the main thread',
test: async () => {
test: async (getEnv) => {
return new Promise((resolve) => {
const grpcServer = new GRPCServer();
grpcServer.start(mustSucceed(async (port) => {
Expand All @@ -159,12 +159,7 @@ tests.push({
resolve();
}));

const env = {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_GRPC: `localhost:${port}`,
NSOLID_BLOCKED_LOOP_THRESHOLD: 100,
};
const env = getEnv(port);

const opts = {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
Expand All @@ -180,7 +175,7 @@ tests.push({

tests.push({
name: 'should work for workers',
test: async () => {
test: async (getEnv) => {
return new Promise((resolve) => {
const grpcServer = new GRPCServer();
grpcServer.start(mustSucceed(async (port) => {
Expand All @@ -195,12 +190,7 @@ tests.push({
resolve();
}));

const env = {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_GRPC: `localhost:${port}`,
NSOLID_BLOCKED_LOOP_THRESHOLD: 100,
};
const env = getEnv(port);

const opts = {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
Expand All @@ -216,7 +206,30 @@ tests.push({
},
});

for (const { name, test } of tests) {
console.log(`blocked loop generation ${name}`);
await test();
const testConfigs = [
{
getEnv: (port) => {
return {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_GRPC: `localhost:${port}`,
};
},
},
{
getEnv: (port) => {
return {
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
NSOLID_GRPC_INSECURE: 1,
NSOLID_SAAS: `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbtesting.localhost:${port}`,
};
},
},
];

for (const testConfig of testConfigs) {
for (const { name, test } of tests) {
console.log(`blocked loop generation ${name}`);
await test(testConfig.getEnv);
}
}
Loading
Loading