Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Romy <[email protected]>
  • Loading branch information
romayalon committed Dec 10, 2024
1 parent d3082bf commit 1e45765
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions src/tools/diagnostics/analyze_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const { throw_cli_error, write_stdout_response } = require('../../manage_nsfs/ma
const { call_forks } = require('../../manage_nsfs/health');
const os_utils = require('../../util/os_utils');

// ❌
// ✅

const ANALYZE_FUNCTION_BY_SERVICE_TYPE = {
S3_HTTP: analyze_s3,
S3_HTTPS: analyze_s3_secure,
Expand All @@ -22,6 +25,9 @@ const ANALYZE_FUNCTION_BY_SERVICE_TYPE = {
METRICS: analyze_metrics
};

const OK = 'OK';
const NOT_OK = 'NOT_OK';

/**
* get_network_status runs network tests and returns/prints the analyzed network information
* @param {*} [argv]
Expand All @@ -38,7 +44,7 @@ async function get_network_status(argv, config_fs) {
write_stdout_response(ManageCLIResponse.HealthStatus, nc_network_status);
} else {
const network_status = await test_network();
console.log('network_status', network_status);
dbg.log0('network_status', network_status);
}
} catch (err) {
dbg.error('Health: exit on error', err.stack || err);
Expand All @@ -54,10 +60,7 @@ async function get_network_status(argv, config_fs) {
*/
async function test_nc_network(config_fs) {
const services_info = await nc_prepare_services_info(config_fs);
console.log('ROMY services info', services_info);
const forks_info = await analyze_forks(services_info);
console.log('ROMY services info', services_info);

const analyze_network_res = [];
for (const service of services_info) {
const analyze_service_res = await analyze_service(service.service, service);
Expand All @@ -70,16 +73,26 @@ async function test_nc_network(config_fs) {
*
*/
async function test_network(services_info) {
const analyze_network_res = [];
const services = await os_utils.discover_k8s_services();
const [external_services, internal_services] = _.partition(services, s => s.kind === 'EXTERNAL');
for (const service_info of internal_services) {
const service_type = get_service_type(service_info);
if (service_type !== '') await analyze_service(service_type, service_info);
if (service_type !== '') {
const analyze_service_res = await analyze_service(service_type, service_info);
analyze_network_res.push({ service_type, analyze_service_res });
}
}
for (const service_info of external_services) {
const service_type = get_service_type(service_info);
if (service_type !== '') await analyze_service(service_type, service_info);
if (service_type !== '') {
const analyze_service_res = await analyze_service(service_type, service_info);
analyze_network_res.push({ service_type, analyze_service_res });
}
}

return { analyze_network_res };

}

function get_service_type(info) {
Expand All @@ -98,58 +111,58 @@ function get_service_type(info) {
* analyze_service
*/
async function analyze_service(service_type, service_info) {
await nslookup_service(service_info);
await ping_service(service_info); // ping DNS
await ping_service(service_info); // ping IP
await curl_service(service_info);
const analyze_service_closure = ANALYZE_FUNCTION_BY_SERVICE_TYPE[service_type];
await analyze_service_closure(service_info);
const nslookup_status = await nslookup_service(service_info);
const ping_dns_status = await ping_service(service_info); // ping DNS
const ping_ip_status = await ping_service(service_info); // ping IP
const curl_status = await curl_service(service_info);
const analyze_service_func = ANALYZE_FUNCTION_BY_SERVICE_TYPE[service_type];
const analyze_service_func_status = await analyze_service_func(service_info);
return { nslookup_status, ping_dns_status, ping_ip_status, curl_status, analyze_service_func_status};
}


///////////////////////////////////
// GENERAL HELPERS //
///////////////////////////////////


async function ping_service(service_info) {

return { status: 'OK' };
}

async function nslookup_service(service_info) {

return { status: OK };
}

async function curl_service(service_info) {

return { status: OK };
}

async function analyze_s3(service_info) {

return { status: OK };
}

async function analyze_s3_secure(service_info) {

return { status: OK };
}

async function analyze_sts(service_info) {

return { status: OK };
}

async function analyze_iam(service_info) {
// nice to have
}

async function analyze_db(service_info) {

return { status: OK };
}

async function analyze_mgmt(service_info) {

return { status: OK };
}

async function analyze_metrics(service_info) {

return { status: OK };
}

/////////////////////////////////
Expand Down Expand Up @@ -185,18 +198,14 @@ async function analyze_forks(services_info) {
*/
async function nc_prepare_services_info(config_fs) {
const system_data = await config_fs.get_system_config_file({ silent_if_missing: true });
console.log('ROMY system_data', system_data);

const nc_services_info = [];
for (const hostname of Object.keys(system_data)) {
console.log('ROMY hostname', hostname, is_fqdn(hostname));

if (!is_fqdn(hostname)) continue;
// TODO:
// 1. need to take the port from config.json per host and not from the general config
// 2. add other service in the future
const s3_info = { service: 'S3-HTTP', hostname, port: config.ENDPOINT_PORT, secure: false };
const s3_ssl_info = { service: 'S3', hostname, port: config.ENDPOINT_SSL_PORT, secure: true };
const s3_info = { service: 'S3_HTTP', hostname, port: config.ENDPOINT_PORT, secure: false };
const s3_ssl_info = { service: 'S3_HTTPS', hostname, port: config.ENDPOINT_SSL_PORT, secure: true };
const metrics_info = { service: 'METRICS', hostname, port: config.EP_METRICS_SERVER_PORT, secure: false };
nc_services_info.push(s3_info);
nc_services_info.push(s3_ssl_info);
Expand Down

0 comments on commit 1e45765

Please sign in to comment.