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

feat: add stats view implementation #89

Merged
merged 4 commits into from
Aug 10, 2018

Conversation

eduardoemery
Copy link
Contributor

@eduardoemery eduardoemery commented Aug 2, 2018

Add stats view implementation and its tests.

@eduardoemery eduardoemery force-pushed the stats_view branch 2 times, most recently from 56dcb28 to a443f62 Compare August 3, 2018 10:03
constructor(
name: string, measure: Measure, aggregation: AggregationType,
tagKeys: string[], description?: string) {
throw new Error('Not Implemented');
tagsKeys: string[], description?: string, bucketBoudaries?: number[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

bucketBoundaries (you can do a global replace)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Updated here and all occurrences.

recordMeasurement(measurement: Measurement) {
// Checks if measurements has all tags in views
for (const tagKey of this.columns) {
if (!Object.keys(measurement.tags).find((key) => key === tagKey)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer some over find here, as the return result could be an empty string. Of course any empty string key is not a real tag, but this will at least "work" if some is used instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion. Updated.

*/
private encodeTags(tags: Tags): string {
const encodedTags = Object.keys(tags).sort().reduce((strTags, tagKey) => {
return strTags + `${tagKey}:${tags[tagKey]},`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is : a reasonable delineator here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I used : since that's what is used in a JSON. So I separated the key from value with a : and the key:value pairs with a ,. But I'm up for suggestions.

Copy link
Contributor

@kjin kjin Aug 7, 2018

Choose a reason for hiding this comment

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

I see. It would be safer to take advantage of the restrictions on tag keys/values. For example, we can use non-printable characters as delineators, since both keys and values must use printable characters. That way there is guaranteed to be no name collision in weird cases where the value contains : or ,.

Also, map + join might be clearer than reduce.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point. I added a verification for the tags keys and values before recording. Also, changed to map + join, it's better 😄

@eduardoemery
Copy link
Contributor Author

Made two small changes as we discussed:

  • Makes view description mandatory
  • Adds a method to get the view's columns

@eduardoemery eduardoemery force-pushed the stats_view branch 2 times, most recently from 58a4d71 to 923a9f2 Compare August 9, 2018 15:49
kjin
kjin previously approved these changes Aug 9, 2018
* @param str The string to be checked
*/
private invalidString(str: string): boolean {
return RegExp(`[${LOW_LIMIT_CHAR}-${HIGH_LIMIT_CHAR}]`).test(str) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would suggest creating this RegExp in the file scope or as a static field so it doesn't have to get constructed on every call to invalidString. Its value is static anyway. (Same for next line.)

Also, would /[^\u0020-\u007e]/ work as a regex to encompass both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted for RegExp() for readability when passing LOW_LIMIT_CHAR and HIGH_LIMIT_CHAR but hadn't considered the performance issue. I think it is way better with /[^\u0020-\u007e]/. Thanks again for the tips!

Copy link
Contributor

@kjin kjin left a comment

Choose a reason for hiding this comment

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

Whoops, pre-mature approval. After this change it will LGTM though

@kjin kjin merged commit 4c4ce0f into census-instrumentation:master Aug 10, 2018
kjin pushed a commit to kjin/opencensus-node that referenced this pull request Aug 24, 2018
* feat: add stats view implementation

* refactor(fix): changes to address review comments

* feat: add method to access view's columns

* feat: add tag format verification
kjin pushed a commit to kjin/opencensus-node that referenced this pull request Aug 24, 2018
* feat: add stats view implementation

* refactor(fix): changes to address review comments

* feat: add method to access view's columns

* feat: add tag format verification
kjin pushed a commit to kjin/opencensus-node that referenced this pull request Aug 24, 2018
* feat: add stats view implementation

* refactor(fix): changes to address review comments

* feat: add method to access view's columns

* feat: add tag format verification
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

3 participants