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

Add support for recording gRPC stats #357

Merged
merged 3 commits into from
Feb 28, 2019

Conversation

mayurkale22
Copy link
Member

@mayurkale22 mayurkale22 commented Feb 23, 2019

This PR is to get the ball rolling, Unit tests are still pending. Reviews are welcome at this moment.
Fixes #270

client-metrics.ts and server-metrics.ts are updated with minor nits.

Update: Tests are included now.

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

Looks pretty good overall! Interesting that spans are used to increment metrics. Had a few nit-picky comments and it also looks like it may need gts fix.

Also, could you add a unit test to ensure that metrics are incremented as expected by recordStats?

import * as clientMetrics from './grpc-stats/client-metrics';
import * as serverMetrics from './grpc-stats/server-metrics';

const sizeof = require('object-sizeof');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this possible to do as a TypeScript import?

Copy link
Member Author

Choose a reason for hiding this comment

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

object-sizeof package is missing typings. I tried to use https://github.com/miktam/sizeof/blob/master/index.d.ts but didn;t work.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, makes sense.

status: Status
status: Status;
// tslint:disable-next-line:no-any
request?: any
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 unknown or the empty object type {} instead?

/** Method to record stats for client and server. */
static recordStats(
// tslint:disable-next-line:no-any
kind: SpanKind, tags: TagMap, argsOrValue: any, reqOrRes: any,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use the empty object type {} in place of any here? (That should work because you are not actually referencing anything about the type, just transparently passing it into sizeof)

Copy link
Member Author

Choose a reason for hiding this comment

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

SGTM, done


// record stats
const tags = new TagMap();
tags.set(serverMetrics.GRPC_SERVER_METHOD, {value: rootSpan.name});
Copy link
Contributor

Choose a reason for hiding this comment

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

As an aside: I think this use case is a good reason to not add Sent. or Recv. to the gRPC span names until they are ready to be exported.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, makes sense. Looks like need to revise the Java's implementation.

@codecov-io
Copy link

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #357      +/-   ##
==========================================
- Coverage    95.3%   95.24%   -0.06%     
==========================================
  Files         124      128       +4     
  Lines        8412     8497      +85     
  Branches      624      628       +4     
==========================================
+ Hits         8017     8093      +76     
- Misses        395      404       +9
Impacted Files Coverage Δ
src/trace/instrumentation/base-plugin.ts 8.82% <0%> (-0.27%) ⬇️
src/index.ts 100% <0%> (ø) ⬆️
src/grpc-stats/server-metrics.ts 100% <0%> (ø)
src/grpc-stats/common-distributions.ts 100% <0%> (ø)
src/grpc-stats/client-metrics.ts 100% <0%> (ø)
src/grpc-stats/stats-common.ts 45.45% <0%> (ø)
src/grpc.ts 94.09% <0%> (ø) ⬆️

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 622cc75...ec07cc4. Read the comment docs.


const PROTO_PATH = __dirname + '/fixtures/grpc-instrumentation-test.proto';
const grpcPort = 50051;
const MAX_ERROR_STATUS = grpcModule.status.UNAUTHENTICATED;
const log = logger.logger();


Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: is this extra blank line intentional?

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

LGTM pending whitespace nit and use of unknown (or empty object {} type) rather than any if possible above

@mayurkale22 mayurkale22 merged commit 0f76085 into census-instrumentation:master Feb 28, 2019
@mayurkale22 mayurkale22 deleted the grpc-metrics branch February 28, 2019 02:09
@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.

None yet

4 participants