Skip to content

Commit

Permalink
Merge branch 'romy-hackathon' of https://github.com/romayalon/noobaa-…
Browse files Browse the repository at this point in the history
…core into romy-hackathon
  • Loading branch information
jackyalbo committed Dec 10, 2024
2 parents d3881b7 + 012bb34 commit 92ea63d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 27 deletions.
13 changes: 9 additions & 4 deletions src/manage_nsfs/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -677,30 +677,35 @@ 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<Number[]>}
*/
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}`);
}
}
});
return worker_ids;
}
}

exports.make_endpoint_health_request = make_endpoint_health_request;
exports.call_forks = call_forks;
exports.get_health_status = get_health_status;
exports.NSFSHealth = NSFSHealth;
66 changes: 43 additions & 23 deletions src/tools/diagnostics/analyze_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>}
*/
async function get_network_status(argv, config_fs) {
const deployment_type = argv.deployment_type;
const is_nc_deployment = deployment_type === 'nc';
Expand All @@ -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<Object>}
*/
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 };
}

/**
Expand Down Expand Up @@ -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<Object>}
*/
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
Expand Down

0 comments on commit 92ea63d

Please sign in to comment.