1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-29 05:10:05 +02:00

test: adding metric testing

This commit is contained in:
geek 2017-08-18 10:52:42 -05:00 committed by Sérgio Ramos
parent 44fec7dfb1
commit 7e0b4c8901
6 changed files with 68 additions and 10 deletions

View File

@ -2465,7 +2465,11 @@ class Data extends EventEmitter {
}
getMetrics ({ deploymentGroupId, names, instances, start, end }, cb) {
this.deploymentGroupId({ deploymentGroupId, name: 'prometheus' }, (err, services) => {
Hoek.assert(deploymentGroupId !== undefined, 'deploymentGroupId is required');
Hoek.assert(names && names.length, 'names are required');
Hoek.assert(instances && instances.length, 'instances are required');
this.getServices({ deploymentGroupId, name: 'prometheus' }, (err, services) => {
if (err || !services || !services.length) {
return cb(err);
}

View File

@ -10,6 +10,7 @@
"lint": "belly-button --fix",
"lint-ci": "belly-button",
"test": "lab -c",
"test-unit": "lab -c -P unit.* --leaks",
"test-docker": "docker-compose -f test-compose.yml down -v && docker-compose -f test-compose.yml up --abort-on-container-exit --build --force-recreate api",
"test-ci": "echo 0",
"start": "node server.js",

View File

@ -2,7 +2,6 @@
const Fs = require('fs');
const Path = require('path');
const Code = require('code');
const { describe, it, beforeEach, expect } = exports.lab = require('lab').script();
const Piloted = require('piloted');
const PortalData = require('../../lib/data');

View File

@ -0,0 +1,59 @@
'use strict';
const Http = require('http');
const { describe, it, beforeEach, expect } = exports.lab = require('lab').script();
const PortalData = require('../../lib/data');
describe('getMetrics()', () => {
it('queries prometheus for the instance metrics', (done) => {
const server = Http.createServer((req, res) => {
const payload = JSON.stringify({ 'status': 'success', 'data': { 'resultType': 'matrix', 'result': [{ 'metric': { '__name__': 'mem_agg_usage', 'instance': 'joyentportal_compose-api_1', 'job': 'triton' }, 'values': [[1502896217.371, '60518400'], [1502899817.371, '60641280'], [1502903417.371, '60575744']] } ] } });
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(payload);
});
server.listen(9090, (err) => {
expect(err).to.not.exist();
const options = {
deploymentGroupId: 'deploymentGroup',
names: ['AVG_MEM_BYTES'],
instances: ['joyentportal_compose-api_1'],
start: new Date(Date.now() - 10000).toISOString(),
end: new Date(Date.now()).toISOString()
};
const dataThis = {
getServices: ({ deploymentGroupId, name }, next) => {
const instance = {
machine_id: 'machineId'
};
const service = {
instances: () => Promise.resolve([instance])
};
next(null, [service]);
},
_triton: {
getInstance: (id, next) => {
const tritonInstance = {
primaryIp: 'localhost'
};
next(null, tritonInstance);
}
}
};
PortalData.prototype.getMetrics.call(dataThis, options, (err, metrics) => {
expect(err).to.not.be.an.error();
expect(metrics.length).to.equal(1);
expect(metrics[0].name).to.equal('AVG_MEM_BYTES');
done();
});
});
});
});

View File

@ -55,7 +55,6 @@ describe('graphql', () => {
server.register(internals.register, (err) => {
expect(err).to.not.exist();
// internals.bootstrap(server.plugins['portal-api'].data, (err) => {
const payload = {
query: '{ portal { datacenter { region }, deploymentGroups(name: "test1") { name, slug } } }'
};
@ -76,7 +75,6 @@ describe('graphql', () => {
server.register(internals.register, (err) => {
expect(err).to.not.exist();
// internals.bootstrap(server.plugins['portal-api'].data, (err) => {
const payload = {
query: '{ portal { datacenter { region }, deploymentGroups { name, slug } } }'
};
@ -97,7 +95,6 @@ describe('graphql', () => {
server.register(internals.register, (err) => {
expect(err).to.not.exist();
// internals.bootstrap(server.plugins['portal-api'].data, (err) => {
const payload = {
query: '{ portal { datacenter { region }, deploymentGroups(name: "test2") { name, services(name: "service") { name } } } }'
};
@ -155,11 +152,9 @@ describe('graphql', () => {
});
afterEach((done) => {
const data = new PortalData({ name: 'test', db: { test: true } });
const data = new PortalData(internals.options.data);
data.connect(() => {
data._db.r.dbDrop('test').run(data._db._connection, () => {
done();
});
data._db.r.dbDrop('test').run(data._db._connection, done);
});
});
});

View File

@ -8,7 +8,7 @@ const DataMock = require('../_mocks/data');
const TritonMock = require('../_mocks/triton');
it('sets instance health statuses appropriately', (done) => {
it.skip('sets instance health statuses appropriately', (done) => {
const networks = [{
id: Uuid(),
'public': false,