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

Make Stats singleton (globalStats), separate registerView from createView #291

Merged
merged 3 commits into from
Jan 22, 2019

Conversation

mayurkale22
Copy link
Member

@mayurkale22 mayurkale22 commented Jan 17, 2019

This PR is based on #276.

This PR contains two breaking changes:

  1. The new Stats() has been deprecated on Stats class. The global singleton globalStats object should be used instead.
  2. registerView() hook has been removed from createView() API. This is related to No need to stats.registerView(view) #287.

Fixes #290 #276

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.

What's the general motivation for the breaking change?

// Stats singleton instance
import {BaseStats} from './stats/stats';
import {Stats} from './stats/types';
const globalStats: Stats = BaseStats.instance;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the : Stats type specifier needed here?

Those are useful for enforcing the type assignment to a structural type like const x: Y = {...}, but since BaseStats.instance already has a type I would think it isn't needed.

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 is added to avoid compiler error -> Exported variable 'globalStats' has or is using name 'Stats' from external module "/opencensus-core/src/stats/types" but cannot be named.

Copy link
Member Author

Choose a reason for hiding this comment

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

@draffensperger Are you ok with my comment or you have better approach to handle this?

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 makes sense, thanks for clarifying.

// Create a new MetricProducerForStats and register it to
// MetricProducerManager when Stats is initialized.
// const metricProducer: MetricProducer = new MetricProducerForStats(this);
// Metrics.getMetricProducerManager().add(metricProducer);
const metricProducer: MetricProducer = new MetricProducerForStats(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar here on not needing the : MetricProducer type annotation since it's implied.

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.

}

/**
* Registers a view to listen to new measurements in its measure. Prefer using
* the method createView() that creates an already registered view.
* @param view The view to be registered
*/
registerView(view: View) {
registerView(view: View): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: do we need to include : void here? (Same comment applies to the other methods 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.

This not really required, but we are already using the same notion in other classes. I was trying to make things consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I think that's fine.


/**
* Registers a view to listen to new measurements in its measure. Prefer using
* the method createView() that creates an already registered view.
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 comment about creating an already registered view still true given the change above to remove the registerView call in the createView implementation above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, removed obsolete comment.

* the method createView() that creates an already registered view.
* @param view The view to be registered
*/
registerView(view: View): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need : void here? (Same comment applies to registerExporter below).

@mayurkale22
Copy link
Member Author

What's the general motivation for the breaking change?

  1. To make things consistent across all libraries before GA release.
  2. globalStats follows the pattern of Tracing.
  3. registerView should not be part of createView, currently this is not a big problem. But we planned to add default stats support for HTTP (Add instrumentation for HTTP on propagating tags and recording HTTP stats #269) and gRPC (Add instrumentation for gRPC on propagating tags and recording gRPC stats  #270) plugin. At that time, if you don't have separate API for createView and registerView, library will start capturing and recording data without users attention.

@draffensperger
Copy link
Contributor

Thanks for the explanation. Is the plan to go directly to GA or will there be an intermediate Beta release?

@mayurkale22
Copy link
Member Author

Thanks for the explanation. Is the plan to go directly to GA or will there be an intermediate Beta release?

I am not 100% sure about this. All the work related to GA Release / Feature Parity work effort available here : https://github.com/census-instrumentation/opencensus-node/issues?q=is%3Aopen+is%3Aissue+label%3AGA-Effort

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.

3 participants