Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/srv subsrv logs #212

Merged
merged 9 commits into from
Sep 15, 2020
Merged
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
2 changes: 2 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Fix: set service subservice in logs of redirector and configurations
- Fix: set new trans and corr or use it if provided in logs
Comment on lines +1 to +2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#211 should be mentioned in one of these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about 211 will be fixed with this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I missinterpret the "related #211" in this PR 👍

NTC

- Overall update of dev package dependencies
- Add extra fields to configuration (timestamp, languageExpression, explicitAttrs)
- Update codebase to use ES6
Expand Down
13 changes: 13 additions & 0 deletions lib/iotagent-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ function startServer(newConfig, callback) {

logger.format = logger.formatters.pipe;

logger.getContext = function domainContext() {
var domainObj = require('domain').active || {};
return {
corr: domainObj.corr,
trans: domainObj.trans,
op: domainObj.op,
srv: domainObj.service,
subsrv: domainObj.subservice,
msg: domainObj.msg,
comp: config.componentName || 'IoTAgentManager'
};
};

northboundServer = {
server: null,
app: express(),
Expand Down
2 changes: 1 addition & 1 deletion lib/services/configurationData.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function createGetWithFields(fields) {

const callback = arguments[i];

logger.debug('Looking for configuration with params %j and query %j', fields, queryObj);
logger.debug(context, 'Looking for configuration with params %j and query %j', fields, queryObj);

const query = Configuration.model.find(queryObj);

Expand Down
11 changes: 10 additions & 1 deletion lib/services/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
const errors = require('../errors');
const configurationData = require('./configurationData');
const logger = require('logops');
const domain = require('../utils/domain');
const fillService = domain.fillService;
var context = {
op: 'IoTAManager.Configurations'
};
const retrievingAPITranslation = {
subservice: 'service_path',
type: 'entity_type',
Expand All @@ -34,6 +39,8 @@ const retrievingAPITranslation = {
explicitAttrs: 'explicitAttrs'
};



function isInvalidParameter(param) {
const value = parseInt(param);

Expand Down Expand Up @@ -85,7 +92,7 @@ function translateToApi(configurations) {
service[retrievingAPITranslation[attributeList[i]] || attributeList[i]] =
configurations.services[j][attributeList[i]];
}
logger.debug('configurations %j translated to %j', configurations, service);
logger.debug(context, 'configurations %j translated to %j', configurations, service);
services.push(service);
}

Expand All @@ -96,6 +103,8 @@ function translateToApi(configurations) {
}

function handleListRequest(req, res, next) {
context = fillService(context, { service: req.headers['fiware-service'],
subservice: req.headers['fiware-servicepath']});
configurationData.list(
req.headers['fiware-service'],
req.headers['fiware-servicepath'],
Expand Down
6 changes: 5 additions & 1 deletion lib/services/iotaRedirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const logger = require('logops');
const errors = require('../errors');
const _ = require('underscore');
const async = require('async');
const context = {
const domain = require('../utils/domain');
const fillService = domain.fillService;
var context = {
op: 'IoTAManager.Redirector'
};

Expand Down Expand Up @@ -234,6 +236,8 @@ function createRequest(req, protocol, body) {
delete options.headers['content-length'];
options.headers.connection = 'close';

context = fillService(context, { service: options.headers['fiware-service'],
subservice: options.headers['fiware-servicepath']});
logger.debug(context, 'Forwarding request:\n\n%j\n', options);

return options;
Expand Down
1 change: 1 addition & 0 deletions lib/services/protocolData.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function cleanConfigurations(protocol, iotagent, resource, callback) {
callback(new errors.InternalDbError(error));
} else {
logger.debug(
context,
'Configurations for Protocol [%s][%s][%s] successfully removed.',
protocol,
iotagent,
Expand Down
46 changes: 46 additions & 0 deletions lib/utils/domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
*
* This file is part of fiware-pep-steelskin
*
* fiware-pep-steelskin is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* fiware-pep-steelskin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with fiware-pep-steelskin.
* If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by the GNU Affero General Public License
* please contact with::[[email protected]]
*/

'use strict';


/**
* Fills service and subservice information in a context object for logging matters.
*
* @param {Object} context Context object that will be used to add the service and subservice information.
* @param {Object} data Data object (configuration or device) containing service information.
* @return {Object} New context containing service information.
*/
function fillService(context, data) {
if (data.service) {
context.srv = data.service;
}

if (data.subservice) {
context.subsrv = data.subservice;
}

return context;
}

exports.fillService = fillService;