-
Notifications
You must be signed in to change notification settings - Fork 2
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
Pass through logs if already in JSON format #3
base: main
Are you sure you want to change the base?
Pass through logs if already in JSON format #3
Conversation
aa0cc4d
to
cfee6c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We made some suggestions to simplify the code. I have have some design questions below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good but it could be simplified per my comments and spacing could be improved to be more in line with what is standard for Javascript.
I will freely admit that my knowledge of Javascript formatting and styling is sadly lacking. If you have some time tomorrow to talk me through that, I'll happily correct it. If there were other code comments here besides the comment about what to do or not do based on the presence of the message key, or if you want to discuss that one further, I'm also game for that. Let's plan to talk through the rest of these, and I'll make any other commits, trivial or otherwise, so we can wrap this up. Thank you. |
I'm not particularly enthused about supporting a module in Javascript, a language that neither I nor anyone in SDG is remotely fluent with. I thought we were to going to replace this with Python if any significant changes were made. |
@JonRoma Yes. We need to plan a Python re-write for this, since getting this kind of update means it's coming out of semi-retirement. But we won't delay these changes behind a rewrite. I would like to see how @kwessel 's planned testing pans out so we know what we need when we're ready to rewrite in Python. |
I should talk with @kwessel to better understand this use case, because I've been flitting from one thing to another, and have been a bit inattentive to this PR (because I have so many other things going on). Also, I simply haven't talked with @kwessel in a long time, so we should catch up. :-) This is Javascript simply because Splunk had a sample lambda function already written, and we decided to use it rather than reinvent the wheel. He knew enough JS to get us through this. When we do this, we should aim for making the python replacement be a minimum viable product, but also bear in mind what other service owners might need. The whole build and test framework for this module should be replaced with something better too.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks great. Please tell us how testing goes. It would be nice if the SSM param splunk_json
was treated as optional and defaulting to false.
44ebeaf
to
968cfc8
Compare
This is done. I'd welcome any suggestions for more efficient or readable code on lines 117-118 and a sanity check of my turnary operator usage on line 162. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code on 116-120 looks good but it is hard to tell if it is correct without testing it since I don't know the SSM API well. I'm a little confused why you are checking for != -1
then setting to 1
. I would have expected you to set to -1
instead. Can you explain in a comment how the logic works? A link to relevant documentation would be great.
I don't understand the intention for the ternary operator on 162. Are you also trying to make sourcetype
optional or allow empty values? Some context would be appreciated.
968cfc8
to
3e46306
Compare
I'm not setting it to -1 or 1. I'm checking for the return value of indexOf. In NodeJS, indexOf returns -1 if it doesn't find the given balue in the array. So, my code tests to see if InvalidParameters is a list and, if it is, if it contains 'splunk_json'. If it does, it then uses the splice method on the array to remove that particular item from the array. Splice takes the index where it should start splicing as the first paramenter and the number of elements to remove as the second. So, it starts at the index where splunk_json lives and removes one item. I was afraid those lines might not be clear. I welcome suggestions to make them more readable.
The context is I'm half asleep. That was supposed to be on line 163. The operator should have been on splunkJSON, not sourceType. 162has been restored, and the change has been applied to 163. Please review and comment or approve as appropriate. Thank you, all! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kwessel Thank you for the clarification. I strongly suggest adding a better comment on line 116:
// Remove optional splunk_json from InvalidParameters if it exists
My JS foo is not strong enough to suggest a refactor but I'm fine with the code as is as long as you improve the comment. I have asked @mpitcel to take a look and see if she can suggest a refactor.
If you could also remove the blank line on 216 that would be great.
Otherwise everything looks good. Please test the code with both splunk_json present and absent in an AWS account to be sure everything works as expected.
@@ -112,6 +113,11 @@ const getSplunkLogger = (parsed, context, callback) => { | |||
|
|||
console.log('Data retrieved from SSM:', JSON.stringify(ssmData, null, 2)); | |||
|
|||
// Make splunk_json optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update comment for folks who are not JS coders:
// Make splunk_json optional | |
// Remove optional splunk_json from InvalidParameters if it exists |
if (InvalidParameters in ssmData && ssmData.InvalidParameters.indexOf('splunk_json') != -1) { | ||
ssmData.InvalidParameters.splice(ssmData.InvalidParameters.indexOf('splunk_json'), 1); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpitcel any refactor suggestions to make this code clearer for folks who are not JS coders?
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary blank line:
} | |
} |
No description provided.