Cucumber test suite for the monitoring

This commit is contained in:
Lev Dragunov 2019-08-07 11:22:46 +03:00 committed by Lev Dragunov
parent 8845b7133c
commit 59c600e7de
5 changed files with 91 additions and 3 deletions

View File

@ -77,7 +77,7 @@ class OSRMDirectLoader extends OSRMBaseLoader {
osrmUp (callback) { osrmUp (callback) {
if (this.osrmIsRunning()) return callback(new Error("osrm-routed already running!")); if (this.osrmIsRunning()) return callback(new Error("osrm-routed already running!"));
const command_arguments = util.format('%s -p %d -i %s -a %s', this.inputFile, this.scope.OSRM_PORT, this.scope.OSRM_IP, this.scope.ROUTING_ALGORITHM); const command_arguments = util.format('%s -p %d -i %s -a %s -P %d', this.inputFile, this.scope.OSRM_PORT, this.scope.OSRM_IP, this.scope.ROUTING_ALGORITHM, this.scope.OSRM_MONITORING_PORT);
this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => { this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => {
if (err && err.signal !== 'SIGINT') { if (err && err.signal !== 'SIGINT') {
this.child = null; this.child = null;
@ -110,7 +110,7 @@ class OSRMmmapLoader extends OSRMBaseLoader {
osrmUp (callback) { osrmUp (callback) {
if (this.osrmIsRunning()) return callback(new Error("osrm-routed already running!")); if (this.osrmIsRunning()) return callback(new Error("osrm-routed already running!"));
const command_arguments = util.format('%s -p %d -i %s -a %s --mmap', this.inputFile, this.scope.OSRM_PORT, this.scope.OSRM_IP, this.scope.ROUTING_ALGORITHM); const command_arguments = util.format('%s -p %d -i %s -a %s -P %d --mmap', this.inputFile, this.scope.OSRM_PORT, this.scope.OSRM_IP, this.scope.ROUTING_ALGORITHM, this.scope.OSRM_MONITORING_PORT);
this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => { this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => {
if (err && err.signal !== 'SIGINT') { if (err && err.signal !== 'SIGINT') {
this.child = null; this.child = null;
@ -157,7 +157,7 @@ class OSRMDatastoreLoader extends OSRMBaseLoader {
osrmUp (callback) { osrmUp (callback) {
if (this.osrmIsRunning()) return callback(); if (this.osrmIsRunning()) return callback();
const command_arguments = util.format('--dataset-name=%s -s -i %s -p %d -a %s', this.scope.DATASET_NAME, this.scope.OSRM_IP, this.scope.OSRM_PORT, this.scope.ROUTING_ALGORITHM); const command_arguments = util.format('--dataset-name=%s -s -i %s -p %d -a %s -P %d', this.scope.DATASET_NAME, this.scope.OSRM_IP, this.scope.OSRM_PORT, this.scope.ROUTING_ALGORITHM, this.scope.OSRM_MONITORING_PORT);
this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => { this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => {
if (err && err.signal !== 'SIGINT') { if (err && err.signal !== 'SIGINT') {
this.child = null; this.child = null;

View File

@ -0,0 +1,47 @@
'use strict';
var util = require('util');
module.exports = function () {
this.When(/^I monitor I should get$/, (table, callback) => {
var got = {};
this.reprocessAndLoadData((e) => {
if (e) return callback(e);
var testRow = (row, ri, cb) => {
var afterRequest = (err, res) => {
if (err) return cb(err);
var rows = res.body.split('\n');
var metrics = {};
rows.forEach((r) => {
if (r.includes('{')) {
var k = r.split('{')[0],
v = r.split('}')[1].split(' ')[1];
metrics[k] = v;
} else {
var kv = r.split(' ');
metrics[kv[0]] = kv[1];
}
});
var headers = new Set(table.raw()[0]);
if (headers.has('key'))
{
got.key=row['key'];
got.value=metrics[row['key']];
}
if (!metrics.hasOwnProperty("osrm_routed_instance_info")) {
throw new Error("Have no instance information inside the monitoring!");
}
cb(null, got);
};
this.requestMonitoring(afterRequest);
}
this.processRowsAndDiff(table, testRow, callback);
});
});
};

View File

@ -39,8 +39,10 @@ module.exports = function () {
this.TIMEZONE_NAMES = this.PLATFORM_WINDOWS ? 'win' : 'iana'; this.TIMEZONE_NAMES = this.PLATFORM_WINDOWS ? 'win' : 'iana';
this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000; this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000;
this.OSRM_MONITORING_PORT = process.env.OSRM_MONITORING_PORT && parseInt(process.env.OSRM_MONITORING_PORT) || 5001;
this.OSRM_IP = process.env.OSRM_IP || '127.0.0.1'; this.OSRM_IP = process.env.OSRM_IP || '127.0.0.1';
this.HOST = `http://${this.OSRM_IP}:${this.OSRM_PORT}`; this.HOST = `http://${this.OSRM_IP}:${this.OSRM_PORT}`;
this.MONITORING_HOST = `http://${this.OSRM_IP}:${this.OSRM_MONITORING_PORT}`;
this.OSRM_PROFILE = process.env.OSRM_PROFILE; this.OSRM_PROFILE = process.env.OSRM_PROFILE;

View File

@ -16,6 +16,24 @@ module.exports = function () {
return this.sendRequest(uri, params, callback); return this.sendRequest(uri, params, callback);
}; };
this.requestMonitoring = (callback) => {
var uri = this.query = this.MONITORING_HOST,
limit = Timeout(this.TIMEOUT, { err: { statusCode: 408 } });
function runRequest (cb) {
request(uri, cb);
}
runRequest(limit((err, res, body) => {
if (err) {
if (err.statusCode === 408) throw new Error('*** osrm monitoring endpoint did not respond');
else if (err.code === 'ECONNREFUSED')
throw new Error('*** osrm monitoring endpoint is not running', uri);
} else
return callback(err, res, body);
}));
};
this.requestUrl = (path, callback) => { this.requestUrl = (path, callback) => {
var uri = this.query = [this.HOST, path].join('/'), var uri = this.query = [this.HOST, path].join('/'),
limit = Timeout(this.TIMEOUT, { err: { statusCode: 408 } }); limit = Timeout(this.TIMEOUT, { err: { statusCode: 408 } });

View File

@ -0,0 +1,21 @@
@routing
Feature: Basic Prometheus monitoring
Background:
Given the profile "testbot"
Given a grid size of 100 meters
@smallest
Scenario: Monitoring fog test
Given the node map
"""
a b
"""
And the ways
| nodes |
| ab |
When I monitor I should get
| key | value |
| workers_busy | 0 |