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

Enforce attribute limit #330

Conversation

mayurkale22
Copy link
Member

This PR will address the first part of #316

@mayurkale22
Copy link
Member Author

+@vigneshtdev for review.

@codecov-io
Copy link

codecov-io commented Feb 6, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #330      +/-   ##
==========================================
- Coverage      95%   94.92%   -0.08%     
==========================================
  Files         120      120              
  Lines        8202     8213      +11     
  Branches      730      732       +2     
==========================================
+ Hits         7792     7796       +4     
- Misses        410      417       +7
Impacted Files Coverage Δ
src/trace/model/span-base.ts 95% <0%> (-5%) ⬇️
src/stackdriver-monitoring.ts 81.05% <0%> (-3.16%) ⬇️
src/trace/model/tracer.ts 85.32% <0%> (-0.27%) ⬇️
src/trace/model/span.ts 100% <0%> (ø) ⬆️
test/test-tracer.ts 100% <0%> (ø) ⬆️
src/adapters.ts 96.87% <0%> (ø) ⬆️
src/trace/model/root-span.ts 100% <0%> (ø) ⬆️
test/test-ocagent.ts 93.78% <0%> (+0.15%) ⬆️

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 57b1da5...72f8b55. Read the comment docs.

this.activeTraceParams.numberOfAttributesPerSpan) {
const attributeKeyToDelete =
Object.keys(this.attributes.attributeMap).shift();
delete this.attributes.attributeMap[attributeKeyToDelete];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why delete an existing attribute rather than just dropping the new attribute? Is that the specified way to do it?

Copy link
Member Author

Choose a reason for hiding this comment

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

This implementation is based on the spec here: https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/TraceConfig.md#limits

When limits are exceeded, implementations should by default preserve the most recently added values and drop the oldest values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, makes sense.

Copy link

Choose a reason for hiding this comment

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

does shift() guarantee that it returns the oldest?

Copy link
Member Author

Choose a reason for hiding this comment

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

As per my knowledge, integer properties are sorted, others (non-integer) are listed in the creation order. shift -> Removes the first element from an array. @draffensperger correct me, if I am wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

I checked on the order by running the following JS in a node console:

x = {}
x.b = 2
x.a = 1
Object.keys(x)  // gives ['b', 'a'] as expected

y = {}
y.a = 1
y.b = 2
Object.keys(y)  // gives ['a', 'b'] as expected

That said, what would you think about adding a unit test to validate this "removes the last attribute" behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do have unit test to cover this -> https://github.com/census-instrumentation/opencensus-node/pull/330/files#diff-0ab7878c00c0a6393dd66fd59e796156R337. Just wanted to make sure this is not passing by fluke.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, sweet!

}

this.attributes.attributeMap[key] = value;
this.attributes.droppedAttributesCount = this.totalRecordedAttributes -
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it work to just increment this.attributes.droppedAttributesCount in the above if block?

Copy link
Member Author

Choose a reason for hiding this comment

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

Make Sense, Done. 👍

/** Trace Parameters */
activeTraceParams: configTypes.TraceParams;

private totalRecordedAttributes = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we increment droppedAttributeCount do we need this field?

this.activeTraceParams.numberOfAttributesPerSpan) {
const attributeKeyToDelete =
Object.keys(this.attributes.attributeMap).shift();
delete this.attributes.attributeMap[attributeKeyToDelete];
Copy link

Choose a reason for hiding this comment

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

does shift() guarantee that it returns the oldest?

@@ -331,13 +334,16 @@ describe('OpenCensus Agent Exporter', () => {
rootSpan.setStatus(CanonicalCode.OK);

// Attribute
rootSpan.addAttribute('my_first_attribute', 'foo');
rootSpan.addAttribute('my_second_attribute', 'foo2');
rootSpan.addAttribute('my_attribute_string', 'bar2');
rootSpan.addAttribute('my_attribute_number', 456);
rootSpan.addAttribute('my_attribute_boolean', false);
Copy link

Choose a reason for hiding this comment

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

Change the test to add same key again such that it is no longer oldest and hence should not be deleted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, PTAL

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.

Makes sense to limit breaking changes where we can, so 👍 to keeping dropped attributes on Span.

@mayurkale22 mayurkale22 merged commit 923148a into census-instrumentation:master Feb 6, 2019
@mayurkale22 mayurkale22 deleted the enforce_attributes_limit branch February 6, 2019 23:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants