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

Task/ensure srv subsrvc log error process message #762

Merged
merged 6 commits into from
Oct 4, 2023
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
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fix: ensure service and subservice from device in logs about error proccesing message
- Remove: legacy code about unused parsedMessageError flag
28 changes: 14 additions & 14 deletions lib/commonBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const transportSelector = require('./transportSelector');
const async = require('async');
const iotaUtils = require('./iotaUtils');
const constants = require('./constants');
const context = {
let context = {
op: 'IoTAgentJSON.commonBinding'
};
const config = require('./configService');
Expand All @@ -50,7 +50,7 @@ const config = require('./configService');
function parseMessage(message) {
let parsedMessage;
let messageArray;

context = fillService(context, { service: 'n/a', subservice: 'n/a' });
const stringMessage = message.toString();
try {
parsedMessage = JSON.parse(stringMessage);
Expand Down Expand Up @@ -126,6 +126,7 @@ function sendConfigurationToDevice(device, apiKey, deviceId, results, callback)
* @param {Object} objMessage Array of JSON object received.
*/
function manageConfigurationRequest(apiKey, deviceId, device, objMessage) {
const ctxt = fillService(context, device);
for (let i = 0; i < objMessage.length; i++) {
iotaUtils.manageConfiguration(
apiKey,
Expand All @@ -141,7 +142,7 @@ function manageConfigurationRequest(apiKey, deviceId, device, objMessage) {
config
.getLogger()
.debug(
context,
ctxt,
'Configuration request finished for APIKey [%s] and Device [%s]',
apiKey,
deviceId
Expand All @@ -164,6 +165,7 @@ function manageConfigurationRequest(apiKey, deviceId, device, objMessage) {
* @param {Object} parsedMessage ParsedMessage (JSON or string) message coming from the client.
*/
function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) {
context = fillService(context, device);
config.getLogger().debug(context, 'Processing single measure for device [%s] with apiKey [%s]', deviceId, apiKey);

const values = [
Expand All @@ -175,8 +177,6 @@ function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) {
];
config.getLogger().debug(context, 'values updates [%s]', JSON.stringify(values));
iotAgentLib.update(device.name, device.type, '', values, device, function (error) {
context.service = device.service;
context.subservice = device.subservice;
if (error) {
config.getLogger().error(
context,
Expand Down Expand Up @@ -210,6 +210,7 @@ function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) {
*/
function multipleMeasures(apiKey, deviceId, device, messageObj) {
let measure;
const ctxt = fillService(context, device);
config
.getLogger()
.debug(context, 'Processing multiple measures for device [%s] with apiKey [%s]', deviceId, apiKey);
Expand All @@ -228,11 +229,9 @@ function multipleMeasures(apiKey, deviceId, device, messageObj) {
}

iotAgentLib.update(device.name, device.type, '', values, device, function (error) {
context.service = device.service;
context.subservice = device.subservice;
if (error) {
config.getLogger().error(
context,
ctxt,
/*jshint quotmark: double */
"MEASURES-002: Couldn't send the updated values to the Context Broker due to an error: %j",
/*jshint quotmark: single */
Expand All @@ -242,7 +241,7 @@ function multipleMeasures(apiKey, deviceId, device, messageObj) {
config
.getLogger()
.info(
context,
ctxt,
'Multiple measures for device [%s] with apiKey [%s] successfully updated',
deviceId,
apiKey
Expand Down Expand Up @@ -285,21 +284,22 @@ function messageHandler(topic, message, protocol) {
// it must be an array of object
multipleMeasures(apiKey, deviceId, device, parsedMessage);
} else {
context = fillService(context, device);
config.getLogger().error(
context,
/*jshint quotmark: double */
"Couldn't process message [%s] due to format issues.",
"Couldn't process message [%s] for device [%j] due to format issues.",
/*jshint quotmark: single */
message
message,
device
);
}
}

function processDeviceMeasure(error, device) {
if (error) {
let ctx = context;
ctx = fillService(ctx, { service: 'n/a', subservice: 'n/a' });
config.getLogger().warn(ctx, 'MEASURES-004: Device not found for topic [%s]', topic);
context = fillService(context, { service: 'n/a', subservice: 'n/a' });
config.getLogger().warn(context, 'MEASURES-004: Device not found for topic [%s]', topic);
} else {
const localContext = _.clone(context);

Expand Down