Skip to content

Commit

Permalink
Merge pull request #479 from oceanprotocol/feature/proper_handle_of_b…
Browse files Browse the repository at this point in the history
…ool_envs

Proper handle of boolean envs
  • Loading branch information
alexcos20 authored May 29, 2024
2 parents 5db9f9f + c94d8b3 commit 6287c21
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 7 deletions.
59 changes: 59 additions & 0 deletions src/test/performance/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
// A number specifying the number of VUs to run concurrently.
vus: 10,
// A string specifying the total duration of the test run.
duration: '30s',

// The following section contains configuration options for execution of this
// test script in Grafana Cloud.
//
// See https://grafana.com/docs/grafana-cloud/k6/get-started/run-cloud-tests-from-the-cli/
// to learn about authoring and running k6 test scripts in Grafana k6 Cloud.
//
// cloud: {
// // The ID of the project to which the test is assigned in the k6 Cloud UI.
// // By default tests are executed in default project.
// projectID: "",
// // The name of the test in the k6 Cloud UI.
// // Test runs with the same name will be grouped.
// name: "script.js"
// },

// Uncomment this section to enable the use of Browser API in your tests.
//
// See https://grafana.com/docs/k6/latest/using-k6-browser/running-browser-tests/ to learn more
// about using Browser API in your test scripts.
//
// scenarios: {
// // The scenario name appears in the result summary, tags, and so on.
// // You can give the scenario any name, as long as each name in the script is unique.
// ui: {
// // Executor is a mandatory parameter for browser-based tests.
// // Shared iterations in this case tells k6 to reuse VUs to execute iterations.
// //
// // See https://grafana.com/docs/k6/latest/using-k6/scenarios/executors/ for other executor types.
// executor: 'shared-iterations',
// options: {
// browser: {
// // This is a mandatory parameter that instructs k6 to launch and
// // connect to a chromium-based browser, and use it to run UI-based
// // tests.
// type: 'chromium',
// },
// },
// },
// }
};

// The function that defines VU logic.
//
// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more
// about authoring k6 scripts.
//
export default function() {
http.get('https://test.k6.io');
sleep(1);
}
28 changes: 21 additions & 7 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ function getIntEnvValue(env: any, defaultValue: number) {
return isNaN(num) ? defaultValue : num
}

function getBoolEnvValue(envName: string, defaultValue: boolean): boolean {
if (!(envName in process.env)) {
return defaultValue
}
if (
process.env[envName] === 'true' ||
process.env[envName] === '1' ||
process.env[envName].toLowerCase() === 'yes'
) {
return true
}
return false
}

function getSupportedChains(): RPCS | null {
const logError = function (): null {
// missing or invalid RPC list
Expand Down Expand Up @@ -444,8 +458,8 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
'/ip4/34.107.3.14/tcp/8000/p2p/16Uiu2HAm4DWmX56ZX2bKjvARJQZPMUZ9xsdtAfrMmd7P8czcN4UT', // maria
'/dnsaddr/ocean-node3.oceanprotocol.io/tcp/8000/p2p/16Uiu2HAm96Sx6o8XCEifPL9MtJiZCSzKqiBQApnZ6JWd7be4zwNK' // bogdan
],
enableIPV4: process.env.P2P_ENABLE_IPV4 !== 'false',
enableIPV6: process.env.P2P_ENABLE_IPV6 !== 'false',
enableIPV4: getBoolEnvValue('P2P_ENABLE_IPV4', true),
enableIPV6: getBoolEnvValue('P2P_ENABLE_IPV6', true),
ipV4BindAddress: getEnvValue(process.env.P2P_ipV4BindAddress, '0.0.0.0'),
ipV4BindTcpPort: getIntEnvValue(process.env.P2P_ipV4BindTcpPort, 0),
ipV4BindWsPort: getIntEnvValue(process.env.P2P_ipV4BindWsPort, 0),
Expand All @@ -468,11 +482,11 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
process.env.P2P_connectionsDialTimeout,
30e3
), // 10 seconds
upnp: process.env.P2P_ENABLE_UPNP !== 'false',
autoNat: process.env.P2P_ENABLE_AUTONAT !== 'false',
enableCircuitRelayServer: process.env.P2P_ENABLE_CIRCUIT_RELAY_SERVER !== 'false',
enableCircuitRelayClient: process.env.P2P_ENABLE_CIRCUIT_RELAY_CLIENT !== 'false',
announcePrivateIp: process.env.P2P_ANNOUNCE_PRIVATE !== 'false'
upnp: getBoolEnvValue('P2P_ENABLE_UPNP', true),
autoNat: getBoolEnvValue('P2P_ENABLE_AUTONAT', true),
enableCircuitRelayServer: getBoolEnvValue('P2P_ENABLE_CIRCUIT_RELAY_SERVER', false),
enableCircuitRelayClient: getBoolEnvValue('P2P_ENABLE_CIRCUIT_RELAY_CLIENT', false),
announcePrivateIp: getBoolEnvValue('P2P_ANNOUNCE_PRIVATE', false)
},
// Only enable provider if we have a DB_URL
hasProvider: !!getEnvValue(process.env.DB_URL, ''),
Expand Down

0 comments on commit 6287c21

Please sign in to comment.