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

Extend HTTP request node to log detailed timing information #3116

Merged
merged 2 commits into from
Sep 27, 2021

Conversation

k-toumura
Copy link
Contributor

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

The current HTTP request node output the time spent on HTTP requests as a metric log(node.http request.duration.mills), but it does not provide a breakdown of the time spent on HTTP request, such as DNS resolution, and TCP connection establishment, which hinders failure analysis.

The got package, used in HTTP request node, can obtain these detailed timing information as a result of HTTP requests. This PR use this feature to add a function to output the detailed timing information as a metric log.

An example of metric log is shown below:

    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.duration.millis","msgid":"11c38881d7cf926f","value":"215.305","timestamp":1629687147857}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.size.bytes","msgid":"11c38881d7cf926f","value":15079,"timestamp":1629687147857}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.timings.start","msgid":"11c38881d7cf926f","value":1629687147645,"timestamp":1629687147857}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.timings.socket","msgid":"11c38881d7cf926f","value":1629687147712,"timestamp":1629687147857}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.timings.lookup","msgid":"11c38881d7cf926f","value":1629687147712,"timestamp":1629687147857}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.timings.connect","msgid":"11c38881d7cf926f","value":1629687147712,"timestamp":1629687147857}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.timings.secureConnect","msgid":"11c38881d7cf926f","value":1629687147762,"timestamp":1629687147857}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.timings.upload","msgid":"11c38881d7cf926f","value":1629687147762,"timestamp":1629687147857}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.timings.response","msgid":"11c38881d7cf926f","value":1629687147846,"timestamp":1629687147858}
    23 Aug 11:52:27 - [metric] {"level":99,"nodeid":"15576e5393f5cb94","event":"node.http request.timings.end","msgid":"11c38881d7cf926f","value":1629687147856,"timestamp":1629687147858}

Related discussion in PR#2952

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run grunt to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@coveralls
Copy link

coveralls commented Aug 23, 2021

Coverage Status

Coverage decreased (-0.06%) to 67.596% when pulling 490547c on node-red-hitachi:dev-httpreqlog into f1e7ec0 on node-red:dev.

@k-toumura k-toumura changed the base branch from master to dev August 23, 2021 07:05
@knolleary
Copy link
Member

Thanks for linking to the previous discussion about this. In that discussion I shared a concern about doing this work:

I'm also not keen in exposing things the module gives us directly - because if we ever have to move off the got module, then it's even more work to reproduce the same behaviour.

But there was no further discussion about those concerns - so before we merge this, we need to complete that discussion.

Emitting all of these extra metrics for every single request is going to generate a lot of extra metrics messages. Do we have absolute confidence that these metrics are required? Should they be more 'trace' level messages that can be used when debugging an issue?

Should there be an option setting to either turn on or off this extra level of message?

@k-toumura
Copy link
Contributor Author

Thanks for linking to the previous discussion about this. In that discussion I shared a concern about doing this work:

I'm also not keen in exposing things the module gives us directly - because if we ever have to move off the got module, then it's even more work to reproduce the same behaviour.

But there was no further discussion about those concerns - so before we merge this, we need to complete that discussion.

got is using http-timer package to measure the timing of HTTP request. To reproduce the same behaviour on another package, we need to choose a package that can use http-timer package (i.e., one that can get an instance of http.ClientRequest class). For example, axios doesn't provide such APIs, unfortunately...

Emitting all of these extra metrics for every single request is going to generate a lot of extra metrics messages. Do we have absolute confidence that these metrics are required? Should they be more 'trace' level messages that can be used when debugging an issue?
Should there be an option setting to either turn on or off this extra level of message?

Detailed timing information is mostly used for debugging purposes.
I'm going to update this PR, what do you think is the best policy?

  • Add a configuration item to the each HTTP request node to output timing information to metric log.
  • Add a configuration item to settings.js to output timing information to metric log.
  • Output timing information to trace log

@k-toumura
Copy link
Contributor Author

Commit 490547c adds an option setting httpRequestTimingLog in settings.js.

Copy link
Member

@dceejay dceejay left a comment

Choose a reason for hiding this comment

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

In order to keep the settings.js file in some sort of structure - would it make sense for this property to be under the existing logging property section ?

@k-toumura
Copy link
Contributor Author

In this case, I put this property at the top level as one of the Node Settings since it is a setting for a single node type (just like debugUseColors is not in logging property section). However, I'm also not sure whether to put the property in logging property section or node settings section...

@knolleary
Copy link
Member

We have no precedent for adding node-specific properties under the logging section.

I'm happy to go with this as proposed. Thanks @k-toumura

@knolleary
Copy link
Member

As all commits in this PR were made under the JS CLA and we have the green-tick from that bot, we can merge this as-is.

@knolleary knolleary merged commit 3eb438c into node-red:dev Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants