Skip to content

Commit 8e5e22a

Browse files
authored
update event hub forwarder and template (#1024)
* Reapply "update event hub forwarder and template" This reverts commit 98b23bc. * reduce return paths and rename function * update zip with reduced return paths * rename to parseProperties * return after setting properties * use let * regen the deploy zip * add the dash back for event hub name * regen the deploy zip * let -> const
1 parent 98b23bc commit 8e5e22a

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed
717 KB
Binary file not shown.

azure/activity_logs_monitoring/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const { app, InvocationContext } = require('@azure/functions');
77

8-
const VERSION = '2.1.1';
8+
const VERSION = '2.2.0';
99

1010
const STRING = 'string'; // example: 'some message'
1111
const STRING_ARRAY = 'string-array'; // example: ['one message', 'two message', ...]
@@ -383,30 +383,28 @@ class EventhubLogHandler {
383383
this.records.push(originalRecord);
384384
}
385385
} else {
386-
this.records.push(this.fixPropertiesJsonString(originalRecord));
386+
this.records.push(this.parseProperties(originalRecord));
387387
}
388388
} else {
389389
record = this.addTagsToStringLog(record);
390390
this.records.push(record);
391391
}
392392
}
393393

394-
fixPropertiesJsonString(record) {
394+
parseProperties(record) {
395395
// Check if properties field is a malformed JSON String
396396
if (Object.hasOwn(record, 'properties') && (typeof record.properties === 'string') && (record.properties.includes("':'"))) {
397397
try {
398398
// If the check is true, find and replace single quotes
399399
// with double quotes, to make a proper JSON
400400
// which is then converted into a JSON Object
401-
record.properties = JSON.parse(record.properties.replace(/'/g, '"'));
402-
return record;
401+
const parsedProperties = JSON.parse(record.properties.replace(/'/g, '"'));
402+
record.properties = parsedProperties;
403403
} catch {
404404
this.context.error('Unable to fix properties field to JSON Object');
405-
return record;
406405
}
407-
} else {
408-
return record;
409406
}
407+
return record;
410408
}
411409

412410
handleLogs(logs) {

azure/activity_logs_monitoring/package-lock.json

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure/activity_logs_monitoring/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"author": "Datadog",
66
"license": "Apache-2.0",
77
"dependencies": {
8-
"@azure/functions": "^4.8.0"
8+
"@azure/functions": "^4.9.0"
99
}
1010
}

azure/test/activity_logs_monitoring.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -818,15 +818,15 @@ describe('Log Splitting', function() {
818818
});
819819
});
820820
});
821-
describe('EventhubLogHandler Fix Properties Json String', function() {
821+
describe('EventhubLogHandler Parse Properties', function() {
822822

823823
beforeEach(function() {
824824
this.forwarder = setUp();
825825
});
826826

827827
it('parses properties string with single quotes into object', function() {
828828
const record = { properties: "{'key':'value'}" };
829-
const result = this.forwarder.fixPropertiesJsonString(record);
829+
const result = this.forwarder.parseProperties(record);
830830

831831
const expectedProperties = { properties: { key: "value" } };
832832

@@ -842,7 +842,7 @@ describe('EventhubLogHandler Fix Properties Json String', function() {
842842

843843
it('parses object that doesnt have properties', function() {
844844
const record = { hostname: "server_name", subObject: { key:"value"} };
845-
const result = this.forwarder.fixPropertiesJsonString(record);
845+
const result = this.forwarder.parseProperties(record);
846846

847847
assert.deepEqual(
848848
record,
@@ -856,7 +856,7 @@ describe('EventhubLogHandler Fix Properties Json String', function() {
856856

857857
it('parses properties string with nested objects', function() {
858858
const record = { properties: "{'key':'value','subObj':{ 'subKey' : 'subValue' }}" };
859-
const result = this.forwarder.fixPropertiesJsonString(record);
859+
const result = this.forwarder.parseProperties(record);
860860

861861
const expectedProperties = { properties: { key: "value", subObj: { subKey: "subValue"} } };
862862

@@ -872,7 +872,7 @@ describe('EventhubLogHandler Fix Properties Json String', function() {
872872

873873
it("leaves properties string unchanged when it doesn't match the malformed pattern", function() {
874874
const record = { properties: 'some plain string without colons' };
875-
const result = this.forwarder.fixPropertiesJsonString(record);
875+
const result = this.forwarder.parseProperties(record);
876876

877877
assert.deepEqual(
878878
record,
@@ -887,7 +887,7 @@ describe('EventhubLogHandler Fix Properties Json String', function() {
887887
it('logs an error and returns original record when replacement results in invalid JSON', function() {
888888
// includes the "':'" marker so the function attempts replacement, but JSON remains invalid
889889
const badRecord = { properties: "Look i know i shouldn't but, i will do this ':' " };
890-
const result = this.forwarder.fixPropertiesJsonString(badRecord);
890+
const result = this.forwarder.parseProperties(badRecord);
891891

892892
assert.deepEqual(
893893
badRecord,

0 commit comments

Comments
 (0)