Skip to content

Commit

Permalink
BACKLOG-22448 Added a better check for the presence of graalvm (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fgerthoffert authored Jul 11, 2024
1 parent 3247d41 commit b19ff50
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@ public ProbeStatus getStatus() {

String vmVendor = System.getProperty("java.vm.vendor", "Unknown");
Version jvmVersion = new Version(System.getProperty("java.version", "Unknown"));
Version graalVMVersion = new Version(System.getProperty("org.graalvm.version", "Unknown"));

// This probe is only relevant for Jahia 8.2.0.0+ in which npm-modules-engine is available.
// Not testing Jahia version since it is not to be backported to older versions of SAM.
ProbeStatus status = new ProbeStatus("No issues to report", ProbeStatus.Health.GREEN);
if (!isNpmModulesEngineStarted) {
status = ProbeStatusUtils.aggregateStatus(status, "The environment is not running JS modules (npm-modules-engine stopped or not present)", ProbeStatus.Health.GREEN);
} else {
if (!vmVendor.contains("GraalVM")) {
status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM not detected on the environment (detected vendor: %s), after switching to GraalVM make sure to enable the Javascript extension", vmVendor), ProbeStatus.Health.RED);
} else if (System.getProperty("org.graalvm.version") == null) {
status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM not detected on the environment (detected vendor: %s with JVM version: %s), after switching to GraalVM 22.3.3+ with JVM version 17+, make sure to enable the Javascript extension", vmVendor, jvmVersion), ProbeStatus.Health.RED);
} else {
if (graalVMVersion.compareTo(new Version("22.3")) <= 0) {
status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM version 22.3.3 or newer required (detected GraalVM version: %s)", graalVMVersion), ProbeStatus.Health.RED);
}
if (jvmVersion.compareTo(new Version("17")) <= 0) {
status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM with JVM version 17 or newer required (detected: %s)", jvmVersion), ProbeStatus.Health.RED);
status = ProbeStatusUtils.aggregateStatus(status, String.format("GraalVM with JVM version 17 or newer required (detected JVM version: %s)", jvmVersion), ProbeStatus.Health.RED);
}
if (vmVendor.contains("GraalVM") && !isJavaScriptModuleInstalled()) {
if (!isJavaScriptModuleInstalled()) {
status = ProbeStatusUtils.aggregateStatus(status, "GraalVM is detected but the JavaScript extension is not installed", ProbeStatus.Health.RED);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineConfig({
},
excludeSpecPattern: '*.ignore.ts',
specPattern: [
'cypress/e2e/api/testStart.spec.begin.ts',
'cypress/e2e/api/*.spec.begin.ts',
'cypress/e2e/api/*.spec.ts',
'cypress/e2e/api/shutdown.spec.final.ts'
Expand Down
26 changes: 26 additions & 0 deletions tests/cypress/e2e/api/firstCheck.spec.begin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {waitUntilSAMStatusGreen} from '@jahia/cypress';
import {healthCheck} from '../../support/gql';

// This suite is there to ensure we get wait for SAM to return GREEN before starting the tests
// The goal is to wait for any provisioning activities that might be happening, in particular in cluster
// Failure of this suite highlights a potential issue with Jahia itself

describe('Absence of errors in SAM at startup', () => {
it('Wait until SAM returns GREEN for medium severity', () => {
// The timeout of 3mn (180) is there to allow for the cluster (if present) to finish its synchronization
waitUntilSAMStatusGreen('MEDIUM', 180000);
cy.executeGroovy('groovy/logProvisioningDone.groovy');
});

it('Check that SAM overall status is green for MEDIUM severity', () => {
healthCheck({severity: 'DEBUG'}).then(r => {
cy.log('Probes not GREEN with severity DEBUG: ' + JSON.stringify(r.probes.filter(probe => probe.status.health !== 'GREEN')));
});

healthCheck({severity: 'MEDIUM'}).then(r => {
cy.then(() => {
expect(r.status.health).to.eq('GREEN');
});
});
});
});
47 changes: 26 additions & 21 deletions tests/cypress/e2e/api/jahiaErrors.spec.begin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,45 @@ import {healthCheck} from '../../support/gql';
describe('Jahia errors probe test', () => {
it('Checks that JahiaErrors probe is functional', () => {
healthCheck({severity: 'DEBUG'}).then(r => {
cy.log(JSON.stringify(r));
const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors');
expect(jahiaErrorsProbe.description).to.contain('Count the number of errors faced by Jahia');
expect(jahiaErrorsProbe.severity).to.eq('DEBUG');
cy.then(() => {
const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors');
expect(jahiaErrorsProbe.description).to.contain('Count the number of errors faced by Jahia');
expect(jahiaErrorsProbe.severity).to.eq('DEBUG');

if (jahiaErrorsProbe.status.health === 'YELLOW') {
expect(jahiaErrorsProbe.status.message).to.contain('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.');
} else {
expect(jahiaErrorsProbe.status.message).to.contain('No errors are present on the platform');
}
if (jahiaErrorsProbe.status.health === 'YELLOW') {
expect(jahiaErrorsProbe.status.message).to.contain('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.');
} else {
expect(jahiaErrorsProbe.status.message).to.contain('No errors are present on the platform');
}
});
});
});

it('Check that Jahia errors probe is YELLOW when there is an error log', () => {
cy.executeGroovy('groovy/simpleErrorLog.groovy');
healthCheck({severity: 'DEBUG'}).then(r => {
expect(r.status.health).to.eq('YELLOW');
const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors');
expect(jahiaErrorsProbe.status.health).to.eq('YELLOW');
expect(jahiaErrorsProbe.severity).to.eq('DEBUG');
// Hard to predict exact number of errors
expect(jahiaErrorsProbe.status.message).to.contain('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.');
cy.then(() => {
expect(r.status.health).to.eq('YELLOW');
const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors');
expect(jahiaErrorsProbe.status.health).to.eq('YELLOW');
expect(jahiaErrorsProbe.severity).to.eq('DEBUG');
// Hard to predict exact number of errors
expect(jahiaErrorsProbe.status.message).to.contain('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.');
});
});
});

it('Check that Jahia errors probe is YELLOW when there is a fatal log', () => {
cy.executeGroovy('groovy/simpleFatalLog.groovy');
healthCheck({severity: 'DEBUG'}).then(r => {
expect(r.status.health).to.eq('YELLOW');
const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors');
expect(jahiaErrorsProbe.status.health).to.eq('YELLOW');
expect(jahiaErrorsProbe.severity).to.eq('DEBUG');
// Hard to predict exact number of errors
expect(jahiaErrorsProbe.status.message).to.contains('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.');
cy.then(() => {
expect(r.status.health).to.eq('YELLOW');
const jahiaErrorsProbe = r.probes.find(probe => probe.name === 'JahiaErrors');
expect(jahiaErrorsProbe.status.health).to.eq('YELLOW');
expect(jahiaErrorsProbe.severity).to.eq('DEBUG');
// Hard to predict exact number of errors
expect(jahiaErrorsProbe.status.message).to.contains('errors are present on the platform, errors are not expected in a production environment and we recommend reviewing these.');
});
});
});

Expand Down
1 change: 1 addition & 0 deletions tests/cypress/fixtures/groovy/logProvisioningDone.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
log.info("Jahia startup and provisioning is now complete, starting the Cypress tests")
2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@jahia/cypress": "^3.18.1",
"@jahia/cypress": "3.20.1",
"@jahia/eslint-config": "^1.1.0",
"@jahia/jahia-reporter": "^1.1.16",
"@typescript-eslint/eslint-plugin": "^5.48.1",
Expand Down
8 changes: 4 additions & 4 deletions tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==

"@jahia/cypress@^3.18.1":
version "3.18.1"
resolved "https://registry.yarnpkg.com/@jahia/cypress/-/cypress-3.18.1.tgz#b7445bce781b1c4603ecdcb8b6c33795933d6796"
integrity sha512-QnPAONPHiVzk9RknjFAdBDNUuQtqln0dceNogXJ/rLdXYNlul4/wQiVsOYN+PueZ7+dVM8hKd1mTF3zt1Sxr1Q==
"@jahia/cypress@3.20.1":
version "3.20.1"
resolved "https://registry.yarnpkg.com/@jahia/cypress/-/cypress-3.20.1.tgz#1897d752bc7beae3362e1d85d0f1b69cac5f5e41"
integrity sha512-f3hvwXSzSPCU42z34sJ+BjZFXvmkqRq7k3cJfac/HNLrM33y7oWYpp2Nvape1W111y9WFREWLMN8iRZB+y7l0Q==
dependencies:
"@apollo/client" "^3.4.9"
cypress-real-events "^1.11.0"
Expand Down

0 comments on commit b19ff50

Please sign in to comment.