diff --git a/src/manage_nsfs/health.js b/src/manage_nsfs/health.js index c601d8781d..cb67bf03ed 100644 --- a/src/manage_nsfs/health.js +++ b/src/manage_nsfs/health.js @@ -251,7 +251,7 @@ class NSFSHealth { } total_fork_count = fork_count_response.fork_count; if (total_fork_count > 0) { - worker_ids = await call_forks(total_fork_count, this.https_port); + worker_ids = await call_forks(total_fork_count, '', this.https_port); if (worker_ids.length === total_fork_count) { response = fork_response_code.RUNNING; } else { @@ -677,23 +677,27 @@ async function make_endpoint_health_request(url_path, https_port) { * call_forks executes http request to the endpoint and adds the worker_id to an array * throws an error as long as the worker ids count is smaller than fork_count * TODO: consider removing the forks check from here and have it on the network analyzer/both + * // TODO: move to forks util * @param {Number} fork_count + * @param {String} hostname * @param {Number} https_port * @returns {Promise} */ -async function call_forks(fork_count, https_port) { +async function call_forks(fork_count, hostname, https_port) { if (fork_count > 0) { const worker_ids = []; await P.retry({ attempts: fork_count * 2, delay_ms: 1, func: async () => { - const fork_id_response = await make_endpoint_health_request('/endpoint_fork_id', https_port); + const fork_id_response = await make_endpoint_health_request(`${hostname || ''}/endpoint_fork_id`, https_port); if (fork_id_response.worker_id && !worker_ids.includes(fork_id_response.worker_id)) { worker_ids.push(fork_id_response.worker_id); } + // TODO: we should have a more concise information about which forks didn't respond instead of just failing on + // unequal worker ids amount and fork_count if (worker_ids.length < fork_count) { - throw new Error('Number of running forks is less than the expected fork count.'); + throw new Error(`Number of running forks ${worker_ids.length} is less than the expected fork count ${fork_count}`); } } }); @@ -701,6 +705,7 @@ async function call_forks(fork_count, https_port) { } } +exports.make_endpoint_health_request = make_endpoint_health_request; exports.call_forks = call_forks; exports.get_health_status = get_health_status; exports.NSFSHealth = NSFSHealth; diff --git a/src/tools/diagnostics/analyze_network.js b/src/tools/diagnostics/analyze_network.js index c9c3ca1d47..a357f9a3b0 100644 --- a/src/tools/diagnostics/analyze_network.js +++ b/src/tools/diagnostics/analyze_network.js @@ -8,8 +8,23 @@ const config = require('../../../config'); const { ManageCLIError } = require('../../manage_nsfs/manage_nsfs_cli_errors'); const { ManageCLIResponse } = require('../../manage_nsfs/manage_nsfs_cli_responses'); const { throw_cli_error, write_stdout_response } = require('../../manage_nsfs/manage_nsfs_cli_utils'); +const { call_forks } = require('../../manage_nsfs/health'); +const ANALYZE_FUNCTION_BY_SERVICE_TYPE = { + S3: analyze_s3, + STS: analyze_sts, + IAM: analyze_iam, + DB: analyze_db, + MGMT: analyze_mgmt, + METRICS: analyze_metrics +}; +/** + * get_network_status runs network tests and returns/prints the analyzed network information + * @param {*} [argv] + * @param {import('../../sdk/config_fs').ConfigFS} [config_fs] + * @returns {Promise} + */ async function get_network_status(argv, config_fs) { const deployment_type = argv.deployment_type; const is_nc_deployment = deployment_type === 'nc'; @@ -29,25 +44,21 @@ async function get_network_status(argv, config_fs) { process.exit(0); } -const ANALYZE_FUNCTION_BY_SERVICE_TYPE = { - S3: analyze_s3, - STS: analyze_sts, - IAM: analyze_iam, - DB: analyze_db, - MGMT: analyze_mgmt, - METRICS: analyze_metrics -}; - /** - * + * @param {import('../../sdk/config_fs').ConfigFS} config_fs + * TODO: In the future add IAM, STS + * @returns {Promise} */ async function test_nc_network(config_fs) { - await analyze_forks(); const services_info = await nc_prepare_services_info(config_fs); - const nc_enabled_services = ['S3', 'METRICS']; // IAM, STS + const forks_info = await analyze_forks(services_info); + const nc_enabled_services = ['S3', 'METRICS']; + const analyze_network_res = []; for (const service of nc_enabled_services) { - await analyze_service(service, services_info[service]); + const analyze_service_res = await analyze_service(service, services_info[service]); + analyze_network_res.push({ service, analyze_service_res }); } + return { ...forks_info, analyze_network_res }; } /** @@ -118,19 +129,28 @@ async function analyze_metrics(service_info) { /// NC // ///////////////////////////////// -async function analyze_forks() { - try { - const url_path = '/total_fork_count'; - const fork_count_response = await make_endpoint_health_request(url_path, this.https_port); - const num_of_forks = fork_count_response.fork_count; - - const responsive_forks = await call_forks(num_of_forks, ); - } catch (err) { - +/** + * analyze_forks iterates the services finds S3 secure hostname and port and calls every fork exists + * @param {Object} services_info + * @returns {Promise} + */ +async function analyze_forks(services_info) { + const res = {}; + for (const service_info of services_info) { + const num_of_forks = config.ENDPOINT_FORKS; + if (service_info.service !== 's3' || service_info.secure === false) continue; + try { + // TODO - check if doing calls to the running host with full hostname works + const responsive_fork_ids = await call_forks(num_of_forks, service_info.hostname, service_info.port); + res[service_info.hostname] = { total_fork_count: num_of_forks, responsive_fork_ids }; + } catch (err) { + res[service_info.hostname] = { total_fork_count: num_of_forks, responsive_forks: [], error: err }; + } } - return { responsive_forks: } + return res; } + /** * nc_prepare_services_info creates services info object * @param {import('../../sdk/config_fs').ConfigFS} config_fs