diff --git a/src/test/performance/script.js b/src/test/performance/script.js new file mode 100644 index 000000000..f79babd79 --- /dev/null +++ b/src/test/performance/script.js @@ -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); +} diff --git a/src/utils/config.ts b/src/utils/config.ts index a5457765d..d2a29c386 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -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 @@ -444,8 +458,8 @@ async function getEnvConfig(isStartup?: boolean): Promise { '/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), @@ -468,11 +482,11 @@ async function getEnvConfig(isStartup?: boolean): Promise { 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, ''),