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

Stats: Record against implicit (current) tag context #418

Merged

Conversation

mayurkale22
Copy link
Member

Specs are available here: https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/Record.md#recording-stats

This will allow users to set and get the current tag context, which can be used when recoding the stats if explicit tags are not provided.

// TODO(mayurkale): read tags current execution context
tags = new TagMap();
// Record against implicit (current) context
tags = getCurrentTagMap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Will users be able to have fine-grained control over which tags for a given metric come from the context and which should be explicitly specified? Or over which tags in the context are associated with which metric?

Copy link
Contributor

Choose a reason for hiding this comment

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

No we intentionally don't provide that level of control. Tags in the context are treated as "opaque" to prevent users accidentally leak confidential information. "Opaque" here means users can insert or upsert tags into context, but they cannot see what tags are in current context or iterate over them.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Is it possible to have a case where a metric does not have labels associated with all the tags in the context?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, thanks

@codecov-io
Copy link

codecov-io commented Mar 12, 2019

Codecov Report

Merging #418 into master will increase coverage by 0.09%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #418      +/-   ##
==========================================
+ Coverage    94.8%   94.89%   +0.09%     
==========================================
  Files         138      140       +2     
  Lines        9144     9251     +107     
  Branches      671      672       +1     
==========================================
+ Hits         8669     8779     +110     
+ Misses        475      472       -3
Impacted Files Coverage Δ
src/index.ts 100% <0%> (ø) ⬆️
src/tags/tag-map.ts 100% <0%> (ø) ⬆️
src/internal/cls-ah.ts 51.61% <0%> (ø) ⬆️
test/test-stats.ts 100% <0%> (ø) ⬆️
src/stats/stats.ts 98.07% <0%> (ø) ⬆️
test/test-tagger.ts 100% <0%> (ø)
src/tags/tagger.ts 100% <0%> (ø)
src/stackdriver-monitoring.ts 83.33% <0%> (+3.12%) ⬆️

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 95607d0...661e7f1. Read the comment docs.

assert.deepEqual(testExporter.recordedMeasurements[0], measurement);
aggregationData =
testExporter.registeredViews[0].getSnapshot(
[{value: 'value1'}, {value: 'value2'}]) as LastValueData;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the role of the as LastValueData, since it looks like aggregationData already has that type? Can that safely be removed here and below?

Copy link
Member Author

Choose a reason for hiding this comment

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

The return type of getSnapshot() method is AggregationData, which is combination of four types SumData|CountData|LastValueData|DistributionData. The conversion (as LastValueData) is added to get exact type of AggregationData.

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense, thanks!

Copy link
Contributor

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

LGTM overall

break;
}
}
if (existingKey) this.registeredTags.delete(existingKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, in Node if I want to update the value for a key in a map, I need to delete the original <key, value> first?

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 understanding, this is true if we use object as a key for map. The maps detect existence ( Map.prototype.has ( key )) of keys based on equality (===). Primitives like strings and numbers are compared by their value, while objects (arrays, plain objects) are compared by their reference. That comparison by reference basically checks to see if the objects given refer to the same location in memory.

Basically to check the objects' "value equality" we essentially have to iterate over every property in the objects to see whether they are equal.

A potential option is to use tagkey.name as a key which is a string type. This required lot more changes and would like to handle in separate PR if we really want to do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense, thanks for the explanation. I'd prefer to keep using the TagKey object as the map key.

packages/opencensus-core/test/test-tagger.ts Show resolved Hide resolved
@mayurkale22 mayurkale22 merged commit 8b80a65 into census-instrumentation:master Mar 15, 2019
@mayurkale22 mayurkale22 deleted the tags_current_context branch March 15, 2019 20:47
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.

5 participants