From 59c600e7ded402cfd6d67329e8f364ef14920cc1 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Wed, 7 Aug 2019 11:22:46 +0300 Subject: [PATCH] Cucumber test suite for the monitoring --- features/lib/osrm_loader.js | 6 ++-- features/step_definitions/monitoring.js | 47 +++++++++++++++++++++++++ features/support/env.js | 2 ++ features/support/route.js | 18 ++++++++++ features/testbot/monitoring.feature | 21 +++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 features/step_definitions/monitoring.js create mode 100644 features/testbot/monitoring.feature diff --git a/features/lib/osrm_loader.js b/features/lib/osrm_loader.js index a29d53b8e..adf936902 100644 --- a/features/lib/osrm_loader.js +++ b/features/lib/osrm_loader.js @@ -77,7 +77,7 @@ class OSRMDirectLoader extends OSRMBaseLoader { osrmUp (callback) { 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) => { if (err && err.signal !== 'SIGINT') { this.child = null; @@ -110,7 +110,7 @@ class OSRMmmapLoader extends OSRMBaseLoader { osrmUp (callback) { 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) => { if (err && err.signal !== 'SIGINT') { this.child = null; @@ -157,7 +157,7 @@ class OSRMDatastoreLoader extends OSRMBaseLoader { osrmUp (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) => { if (err && err.signal !== 'SIGINT') { this.child = null; diff --git a/features/step_definitions/monitoring.js b/features/step_definitions/monitoring.js new file mode 100644 index 000000000..fe05d43da --- /dev/null +++ b/features/step_definitions/monitoring.js @@ -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); + }); + }); +}; diff --git a/features/support/env.js b/features/support/env.js index 9b4c5acc9..bf1583033 100644 --- a/features/support/env.js +++ b/features/support/env.js @@ -39,8 +39,10 @@ module.exports = function () { this.TIMEZONE_NAMES = this.PLATFORM_WINDOWS ? 'win' : 'iana'; 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.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; diff --git a/features/support/route.js b/features/support/route.js index cd713372d..8e8a33dc7 100644 --- a/features/support/route.js +++ b/features/support/route.js @@ -16,6 +16,24 @@ module.exports = function () { 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) => { var uri = this.query = [this.HOST, path].join('/'), limit = Timeout(this.TIMEOUT, { err: { statusCode: 408 } }); diff --git a/features/testbot/monitoring.feature b/features/testbot/monitoring.feature new file mode 100644 index 000000000..9dbe3c7bf --- /dev/null +++ b/features/testbot/monitoring.feature @@ -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 |