Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Add support for recording HTTP stats #370

Merged

Conversation

mayurkale22
Copy link
Member

This PR provides instrumentation for HTTP Client and Server to record HTTP stats. Part of #269

These changes have all been tested locally against prometheus exporter and been confirmed to be working.

screen shot 2019-02-27 at 11 11 41 pm

I will work on recording stats for send/received bytes in seperate PR.

@codecov-io
Copy link

codecov-io commented Feb 28, 2019

Codecov Report

Merging #370 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #370      +/-   ##
==========================================
- Coverage   95.22%   95.21%   -0.02%     
==========================================
  Files         128      129       +1     
  Lines        8487     8593     +106     
  Branches      627      633       +6     
==========================================
+ Hits         8082     8182     +100     
- Misses        405      411       +6
Impacted Files Coverage Δ
src/stackdriver-monitoring.ts 81.05% <0%> (-3.16%) ⬇️
src/http.ts 91.21% <0%> (-0.26%) ⬇️
src/index.ts 100% <0%> (ø) ⬆️
src/http-stats.ts 100% <0%> (ø)
test/test-http.ts 98.74% <0%> (+0.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a887a57...790284a. Read the comment docs.


export type HttpGetCallback = (res: httpModule.IncomingMessage) => void;
export type HttpModule = typeof httpModule;
export type RequestFunction = typeof httpModule.request;

// tslint:disable-next-line:no-any
function isOpenCensusRequest(options: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What would you think about making a simple interface for this rather than passing in any here? Seems like it just has an optional headers attribute that is a map of string to string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to RequestOptions, instead of any.

request: httpModule.ClientRequest, options: httpModule.RequestOptions,
plugin: HttpPlugin): Func<httpModule.ClientRequest> {
return (span: Span): httpModule.ClientRequest => {
const startTime = Date.now();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be a high-accuracy timestamp? I believe some Node versions support performance.now(), which would be an easy swap in, or else you could use process.hrtime and do some conversion / use a utility.

Copy link
Member Author

Choose a reason for hiding this comment

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

For stats recoding, we want to record ms level granularity. Looks like Date.now() gives us that. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's fine. Didn't realize the stats were only at ms granularity.

@@ -15,3 +15,6 @@
*/

export * from './http';
import {registerAllClientViews, registerAllServerViews, registerAllViews} from './http-stats';

export {registerAllClientViews, registerAllServerViews, registerAllViews};
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just be export {registerAllClientViews, registerAllServerViews, registerAllViews} from './http-stats';?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, Done.

@mayurkale22 mayurkale22 force-pushed the http_stats_recording branch from 276c15d to ae0c276 Compare March 1, 2019 00:22
@mayurkale22 mayurkale22 merged commit a5c2971 into census-instrumentation:master Mar 1, 2019
@mayurkale22 mayurkale22 deleted the http_stats_recording branch March 1, 2019 18:56
@mayurkale22 mayurkale22 added this to the Release 0.0.10 milestone Mar 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants