Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
- Upgrade express dep from 4.21.2 to 4.22.1
<<<<<<< task/add_health_middleware
- Add to endpoint /about info about status of CB, IotaM, Mongo and MQTT broker (#1763)
=======
- Upgrade express dep from 4.21.2 to 4.22.1
>>>>>>> master
17 changes: 17 additions & 0 deletions doc/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,20 @@ values are:

Have a look to [this document](devel/northboundinteractions.md) for more detail on how this modes work.

#### `healthCheckInterval`

Time interval (in milliseconds) between consecutive health checks. Default: 20000 (20 seconds)

#### `healthCheckTimeout`

Maximum time (in milliseconds) to wait for a single health check operation (HTTP request, MongoDB ping, MQTT connect)
before considering it failed. Default: 1500 (1.5 seconds)

#### `healthCheckDownAfterFails`

Number of consecutive failed checks required before marking a connection as DOWN (ok: false). Until this threshold is
reached, transient failures are tolerated. Default: 3

### Configuration using environment variables

Some of the configuration parameters can be overriden with environment variables, to ease the use of those parameters
Expand Down Expand Up @@ -514,6 +528,9 @@ overrides.
| IOTA_STORE_LAST_MEASURE | `storeLastMeasure` |
| IOTA_CB_FLOW_CONTROL | `useCBflowControl` |
| IOTA_CMD_MODE | `cmdMode` |
| IOTA_HEALTH_CHECK_INTERVAL | `healthCheckInterval` |
| IOTA_HEALTH_CHECK_TIMEOUT | `healthCheckTimeout` |
| IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS | `healthCheckDownAfterFails` |

Note:

Expand Down
124 changes: 75 additions & 49 deletions doc/api.md

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ function processEnvironmentVariables() {
'IOTA_EXPRESS_LIMIT',
'IOTA_USE_CB_FLOW_CONTROL',
'IOTA_STORE_LAST_MEASURE',
'IOTA_CMD_MODE'
'IOTA_CMD_MODE',
'IOTA_HEALTH_CHECK_INTERVAL',
'IOTA_HEALTH_CHECK_TIMEOUT',
'IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS'
];
const iotamVariables = [
'IOTA_IOTAM_URL',
Expand Down Expand Up @@ -517,6 +520,22 @@ function processEnvironmentVariables() {
if (process.env.IOTA_CMD_MODE) {
config.cmdMode = process.env.IOTA_CMD_MODE;
}

if (process.env.IOTA_HEALTH_CHECK_INTERVAL) {
config.healthCheckInterval = process.env.IOTA_HEALTH_CHECK_INTERVAL;
} else {
config.healthCheckInterval = config.healthCheckInterval ? config.healthCheckInterval : 20000;
}
if (process.env.IOTA_HEALTH_CHECK_TIMEOUT) {
config.healthCheckTimeout = process.env.IOTA_HEALTH_CHECK_TIMEOUT;
} else {
config.healthCheckTimeout = config.healthCheckTimeout ? config.healthCheckTimeout : 1500;
}
if (process.env.IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS) {
config.healthCheckDownAfterFails = process.env.IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS;
} else {
config.healthCheckDownAfterFails = config.healthCheckDownAfterFails ? config.healthCheckDownAfterFails : 3;
}
}

function setConfig(newConfig) {
Expand Down
3 changes: 2 additions & 1 deletion lib/request-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function getOptions(options) {
headers: options.headers,
throwHttpErrors: options.throwHttpErrors || false,
retry: options.retry || 0,
responseType: options.responseType || 'json'
responseType: options.responseType || 'json',
timeout: options.timeout || undefined
};

// got library is not properly documented, so it is not clear which takes precedence
Expand Down
6 changes: 5 additions & 1 deletion lib/services/common/genericMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let iotaInformation;
let context = {
op: 'IoTAgentNGSI.GenericMiddlewares'
};
const { getHealthState } = require('./health');

/**
* Express middleware for handling errors in the IoTAs. It extracts the code information to return from the error itself
Expand Down Expand Up @@ -156,7 +157,10 @@ function validateJson(template) {

/* eslint-disable-next-line no-unused-vars */
function retrieveVersion(req, res, next) {
res.status(200).json(iotaInformation);
res.status(200).json({
...iotaInformation,
connections: getHealthState()
});
}

/**
Expand Down
Loading