Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
add correct endpoint for spring and add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Toby Corbin <corbint@uk.ibm.com>
  • Loading branch information
tobespc committed May 13, 2020
1 parent 2114e69 commit 12ab0e4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/pfe/portal/modules/utils/metricsStatusChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const VALID_METRIC_ENDPOINT = {
hosting: METRICS_DASH_HOST.project,
},
javametricsDash: {
endpoint: '/javametrics-dash',
endpoint: '/javametrics-dash/',
hosting: METRICS_DASH_HOST.project,
},
swiftmetricsDash: {
Expand Down Expand Up @@ -248,7 +248,7 @@ function getMetricsDashboardHostAndPath(endpoints, projectID, projectLanguage) {

function getDashboardPath(metricsDashHost, projectMetricEndpoint, projectID, language, injectMetrics) {
if (metricsDashHost === METRICS_DASH_HOST.project && !injectMetrics) {
return `${projectMetricEndpoint}/?theme=dark`;
return path.join(projectMetricEndpoint, '?theme=dark');
}

// Currently we only support java and nodejs on the performance dashboard
Expand Down
12 changes: 12 additions & 0 deletions test/modules/project.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const path = require('path');
const zlib = require('zlib');
const klawSync = require('klaw-sync');
const globToRegExp = require('glob-to-regexp');
const replace = require('replace-in-file');

const { projectTypeToIgnoredPaths } = require('../../src/pfe/portal/modules/utils/ignoredPaths');
const { ADMIN_COOKIE, templateOptions } = require('../config');
Expand Down Expand Up @@ -440,6 +441,16 @@ async function cloneProject(giturl, dest) {
await git().clone(giturl, dest);
}

async function cloneProjectAndReplacePlaceholders(giturl, dest, projectName) {
await cloneProject(giturl, dest);
const options = {
files: `${dest}/*`,
from: /\[PROJ_NAME_PLACEHOLDER\]/g,
to: projectName,
};
await replace(options);
}

async function notifyPfeOfFileChangesAndAwaitMsg(array, projectID) {
const deflateAsync = promisify(zlib.deflate);
const str = JSON.stringify(array);
Expand Down Expand Up @@ -534,6 +545,7 @@ module.exports = {
removeProject,
buildProject,
cloneProject,
cloneProjectAndReplacePlaceholders,
notifyPfeOfFileChangesAndAwaitMsg,
getProjectLinks,
addProjectLink,
Expand Down
3 changes: 2 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"chai-as-promised": "^7.1.1",
"chai-files": "^1.4.0",
"chai-http": "^4.0.0",
"chai-openapi-response-validator": "^0.7.0",
"chai-openapi-response-validator": "^0.7.2",
"chai-subset": "^1.6.0",
"child-process-promise": "^2.2.1",
"compress-tag": "^1.2.2",
Expand All @@ -51,6 +51,7 @@
"path": "^0.12.7",
"proxyquire": "^2.1.3",
"read-each-line-sync": "^1.0.5",
"replace-in-file": "^6.0.0",
"rewire": "^4.0.1",
"rimraf": "^3.0.0",
"simple-git": "^1.110.0",
Expand Down
62 changes: 62 additions & 0 deletions test/src/API/projects/metricsStatus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,68 @@ describe('Metrics Status tests (/projects/{id}/metrics/status)', function() {
});
});

describe('Spring project with javametrics-dash', function() {
const projectName = `test-spring-project-metrics-java-dash-${Date.now()}`;
const pathToLocalProject = path.join(TEMP_TEST_DIR, projectName);
let projectID;

before('clone project and bind to PFE', async function() {
this.timeout(testTimeout.med);
await projectService.cloneProjectAndReplacePlaceholders(
templateOptions['spring'].url,
pathToLocalProject,
projectName,
);

const { body: project } = await projectService.bindProject({
name: projectName,
path: pathToLocalProject,
language: 'java',
projectType: 'spring',
creationTime: Date.now(),
});
projectID = project.projectID;
});

after(async function() {
this.timeout(testTimeout.med);
await projectService.removeProject(pathToLocalProject, projectID);
});

it('returns 200 and correct metrics information before the project is running', async function() {
this.timeout(testTimeout.med);
const res = await getMetricsStatus(projectID);
res.status.should.equal(200, res.text);
res.body.should.deep.equal({
liveMetricsAvailable: false,
metricsEndpoint: false,
appmetricsEndpoint: false,
microprofilePackageFoundInBuildFile: false,
appmetricsPackageFoundInBuildFile: true,
canMetricsBeInjected: true,
projectRunning: false,
hasTimedMetrics: false,
});
});

it('returns 200 and the correct metrics information when the project is running', async function() {
if (process.env.JENKINS_HOME) {
this.skip();
}
this.timeout(testTimeout.maxTravis);
await projectService.awaitProjectStartedHTTP(projectID);

const res = await getMetricsStatus(projectID);
res.status.should.equal(200, res.text);
res.body.should.containSubset({
liveMetricsAvailable: true,
metricsEndpoint: false,
appmetricsEndpoint: '/javametrics-dash',
projectRunning: true,
});
});
});

function getMetricsStatus(projectID) {
return reqService.chai
.get(`/api/v1/projects/${projectID}/metrics/status`)
Expand Down
14 changes: 7 additions & 7 deletions test/src/unit/modules/utils/metricsStatusChecker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('metricsStatusChecker.js', function() {
unsetGlobal();
});
[
{ language: 'java', fileContents: 'javametrics\n<artifactId>microprofile</artifactId>', mpPac: true, apEndpoint: '/javametrics-dash' },
{ language: 'java', fileContents: 'javametrics\n<artifactId>microprofile</artifactId>', mpPac: true, apEndpoint: '/javametrics-dash/' },
{ language: 'nodejs', fileContents: '{"dependencies":{"appmetrics-dash": "1.0.0"}}', apEndpoint: '/appmetrics-dash' },
{ language: 'javascript', fileContents: '{"dependencies":{"appmetrics-dash": "1.0.0"}}', apEndpoint: '/appmetrics-dash' },
{ language: 'swift', fileContents: 'SwiftMetrics.git', apEndpoint: '/swiftmetrics-dash' },
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('metricsStatusChecker.js', function() {
const mockedGetActiveMetricsURLs = sinon.stub().returns({
'/metrics': true,
'/appmetrics-dash': (language === 'nodejs' || language === 'javascript') ? true : false,
'/javametrics-dash': (language === 'java') ? true : false,
'/javametrics-dash/': (language === 'java') ? true : false,
'/swiftmetrics-dash': ((language === 'swift') ? true : false),
'/actuator/prometheus': true,
});
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('metricsStatusChecker.js', function() {
activeDashboardObject.should.deep.equal({
'/metrics': true,
'/appmetrics-dash': true,
'/javametrics-dash': true,
'/javametrics-dash/': true,
'/swiftmetrics-dash': true,
'/actuator/prometheus': true,
});
Expand Down Expand Up @@ -413,14 +413,14 @@ describe('metricsStatusChecker.js', function() {
const allActiveEndpoints = {
'/metrics': true,
'/appmetrics-dash': true,
'/javametrics-dash': true,
'/javametrics-dash/': true,
'/swiftmetrics-dash': true,
'/actuator/prometheus': true,
};
const allDisabledEndpoints = {
'/metrics': false,
'/appmetrics-dash': false,
'/javametrics-dash': false,
'/javametrics-dash/': false,
'/swiftmetrics-dash': false,
'/actuator/prometheus': false,
};
Expand All @@ -430,8 +430,8 @@ describe('metricsStatusChecker.js', function() {
hosting.should.equal('performanceContainer');
path.should.equal('/performance/monitor/dashboard/java?theme=dark&projectID=projectid');
});
it('returns hosting as the project as /metrics is disabled but /javametrics-dash is active', async function() {
const { hosting, path } = await getMetricsDashboardHostAndPath({ ...allDisabledEndpoints, '/javametrics-dash': true }, 'projectid', 'java');
it('returns hosting as the project as /metrics is disabled but /javametrics-dash/ is active', async function() {
const { hosting, path } = await getMetricsDashboardHostAndPath({ ...allDisabledEndpoints, '/javametrics-dash/': true }, 'projectid', 'java');
hosting.should.equal('project');
path.should.equal('/javametrics-dash/?theme=dark');
});
Expand Down

0 comments on commit 12ab0e4

Please sign in to comment.