Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose metrics views in a slice #327

Merged
merged 2 commits into from
Apr 25, 2019
Merged

Expose metrics views in a slice #327

merged 2 commits into from
Apr 25, 2019

Conversation

anacrolix
Copy link
Contributor

Exposes all the views in a slice for convenience, and because they're self-describing.

Copy link
Member

@frrist frrist left a comment

Choose a reason for hiding this comment

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

Looks good! Left a non-blocking question.

// Views
var (
ReceivedMessagesView = &view.View{
var Views = []*view.View{
Copy link
Member

@frrist frrist Apr 23, 2019

Choose a reason for hiding this comment

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

This change means consumers of this package will no longer be able to register just some of the views, is that correct?

I liked the idea of having the ability to pick and choose which views my code registered, for example maybe I am only interested in ReceivedBytesView and SentBytesView. We could preserve this functionally by leaving the views assigned to exported variables while also adding them to an exported slice, as was done here. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems reasonable, but I think it binds the API to particular views that may not have relevance going forward. I'm not sure there's ever a circumstance where all the views would not be exported (now I think perhaps DefaultViews would be a better name). They can still be found in the slice, and are self-describing. Further, should users want to roll their own views, or modify them, they can do that, the measures are exported for doing so. I suspect in future, that with all the libp2p and other packages having various metrics and views exposed, we'll need to switch to some automatic registration anyway to avoid fatigue traversing all the packages of interest and selecting individual views.

If you feel strongly about it, I'll leave them exported for now, and provide the slice just for convenience.

Copy link
Member

Choose a reason for hiding this comment

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

No strong feelings, you make a good point about binding the API to views that may become irrelevant -- this lgtm as is.

Copy link
Member

@raulk raulk left a comment

Choose a reason for hiding this comment

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

This is ok for now, but I expect we'll adjust this API going forward.

Exporting views in a static var is the simple path now. But we are introducing the notion of a service-oriented Host.

If we put these views behind an interface (e.g. Measurable), the DI entrypoint could inspect all services and interrogate them for default views.

With the var-based construction, it's not possible to do so unless we use reflection.

Copy link
Contributor

@bigs bigs left a comment

Choose a reason for hiding this comment

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

lgtm

This communicates that these aren't the only views that are possible, or that they should be considered mandatory.
@anacrolix anacrolix merged commit 691b1e5 into master Apr 25, 2019
@ghost ghost removed the status/in-progress In progress label Apr 25, 2019
@lanzafame
Copy link
Contributor

@anacrolix I made a valid case against this when I put #317 up. So I would have appreciated a ping on this PR.

@lanzafame
Copy link
Contributor

lanzafame commented Apr 29, 2019

All you needed to do was put the views in a slice, i.e.

var DefaultViews = []*view.View{
    ReceivedMessagesView,
    ReceivedMessageErrorsView,
   ...
}

@anacrolix @raulk this is a breaking change from 0.0.9 so either it shouldn't be under 0.0.10 or should be reverted for a solution that is backwards compatible.

@raulk
Copy link
Member

raulk commented Apr 29, 2019

@lanzafame – sorry I missed your point in favour of exporting individual views in the cited comment :-(

All expressed points of view are reasonable. I wonder if we can engineer a best practice across IPFS [cluster], Filecoin and libp2p that:

  1. strikes the right balance between offering recommended views and composing them from scratch
  2. does so in a way that is flexible for the owning component to change which stats are collected, and how, under the hood.

Looking again at this PR, the rationale seems flawed. Omitting views from public exports, in order to enable the owning component to change those views, all the while we keep measurements exported, is incoherent. After all, any big enough change in stats collection will probably end up altering the measurements themselves (which are publicly exposed). So API breakage is inevitable.

Moreover, this particular approach is buggy because it leaks write access to internal state via the slice.

In general, I think API users should not refer to views and measurements statically. An alternative that springs to mind is a "metrics repository" abstraction, onto which components load their measurements and views. Getting inexistent measurements and views from this component would return an error, but would not introduce API breakage.

@raulk raulk deleted the metrics-views-slice branch May 8, 2019 17:39
aarshkshah1992 pushed a commit to aarshkshah1992/go-libp2p-kad-dht that referenced this pull request Aug 11, 2019
* Expose metrics views in a slice

* Rename Views to DefaultViews

This communicates that these aren't the only views that are possible, or that they should be considered mandatory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants