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

Use registration pattern for dashboard tabs #611

Merged
merged 3 commits into from
Oct 4, 2017

Conversation

jart
Copy link
Contributor

@jart jart commented Oct 4, 2017

The plugin list no longer needs to be specified at all. The HTML imports
themselves are now the plugin list. Special properties, e.g. custom tab names,
are now defined as properties on the Polymer components themselves.

The tradeoff is that each plugin's dashboard must call a registration function,
providing the plugin name and the name of the custom element.

See also: #459

@jart jart requested review from nfelt and chihuahua October 4, 2017 01:27
@chihuahua
Copy link
Member

After thinking about this refactoring, I'm not sure of the benefits. I'm not adamantly opposed (more indifferent) - I just don't see the win here of moving where information is stored.

Previously, plugin info (name, element, title) were stored in 1 place (a JSON list). To register a plugin, a developer would just add an entry (JSON object) to a list and import its dashboard.

Now, that same info is stored across individual dashboards. Because polymer lacks interfaces, it's hard to document + enforce properties each dashboard must provide. And each dashboard has to call registerDashboard, which is a non-trivial function. And we maintain this complex registry ...

The previous system seems more systematic and understandable (and concise enough).

@chihuahua
Copy link
Member

To be clear, I think we want to at least prevent constructing all the dashboards if we're to go forward. At the same time, a stronger justification for what we get out of this refactoring would be nice.

@jart
Copy link
Contributor Author

jart commented Oct 4, 2017

The advantage is that lines 38 through 55 in https://github.com/tensorflow/tensorboard-plugin-example/blob/b095516b8070fe3001d428f957990719560d869c/greeter_tensorboard/index.html can be deleted. This is preferable to needing to copy the big central const data structure introduced by #459 into that repository.

@chihuahua
Copy link
Member

Ah k. Despite being big, the const data structure did offer type/property-checking and clarity that I think we want to try and preserve with this change.

Could we

  1. Somehow avoid creating every dashboard (even inactive ones) on this line: https://github.com/tensorflow/tensorboard/pull/611/files#diff-4401f5045c6476b17ecdc75b1605b3fbR62
    For instance, can we make tabName static? Or just an optional argument to registerDashboard?

  2. Could we briefly add some docs to
    https://github.com/tensorflow/tensorboard-plugin-example/blob/master/README.md
    to clarify how to use registerDashboard? For instance, if the tab name is not provided, we default to using the plugin name? Otherwise, I'm not sure if developers would naturally look at registry.ts.

@jart
Copy link
Contributor Author

jart commented Oct 4, 2017

I preserved the benefits of your previous change. We still have type checking and all that goodness. The only difference now is that the definitions themselves are localized (rather than centralized.)

  1. I loaded TensorBoard and ran document.createElement('vz-projector-dashboard') and it took 2ms. Chrome seems to do a reasonable job making this cheap, so there shouldn't be much downside to doing this on load for each plugin.

  2. The plugin example repository would need to be updated after this change is merged.

@chihuahua
Copy link
Member

Could we avoid placing the property on the dashboard component (which lacks type-checking)? Just add an argument to registerDashboard?

@nfelt
Copy link
Contributor

nfelt commented Oct 4, 2017

A few questions:

  • It looks like the current mechanism for plugin registration in the tensorboard repo diverges from the TENSORBOARD_PLUGINS approach described in the tensorboard-plugin-example repo (at least, I don't see any code within tensorboard master that would read that constant dict). Is that the case right now? Does that mean the plugin-example instructions are currently out of date?

  • Is there any use case for giving a plugin a different dashboard display name than one that's hardcoded within the plugin component itself? E.g. say that someone writes their own scalars plugin, and they want to name it "scalars" and the existing default scalars one something like "legacy scalars" or "default scalars"? It seems like this approach limits the ability to do that without doing something like adding your own plugin that wraps the existing one (not sure if that is actually possible/easy either?).

  • Same question but for the backend plugin-identifier string. Any use case for a user making that something other than hardcoded? E.g. if someone wanted to run two copies of a plugin on the backend with slightly different data but use the same frontend for both?

  • It looks like the reason we couldn't do something like include a tiny bit of javascript that crawls the link rel=import tags and auto-detects the plugins there (without any changes to plugin code) is that everything gets vulcanized and those link tags disappear. Is that correct?

@jart
Copy link
Contributor Author

jart commented Oct 4, 2017

  1. The divergence happened a month ago in Modify dashboard mapping to take object values #459, which caused problems when updating the example repo. This change is meant to take the good stuff from Modify dashboard mapping to take object values #459 and make separate-repo TB builds even easier to do than they were before.

  2. I can't think of a use case for a third party to want to rename first party plugins. That might cause confusion for users.

  3. Not sure.

  4. Yes. HTML imports get compiled away by vulcanize.

@jart
Copy link
Contributor Author

jart commented Oct 4, 2017

@chihuahua You're going to love love love what I just did. Not only did I take tabName off the Polymer objects, but I also took isReloadDisabled off them too. Now the definitions for these things are all in one central place.

The plugin list no longer needs to be specified at all. The HTML imports
themselves are now the plugin list. Special properties, e.g. custom tab names,
are now defined as properties on the Polymer components themselves.

The tradeoff is that each plugin's dashboard must call a registration function,
providing the plugin name and the name of the custom element.

See also: tensorflow#459
Copy link
Member

@chihuahua chihuahua left a comment

Choose a reason for hiding this comment

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

This seems like something that works nicely. We have a Dashboard type that specifies properties. Lets try it out both internally and with greeter plugin.

@nfelt, we indeed should update greeter plugin. I don't think we have a need to differentiate between plugins with the same name at the moment.

@@ -324,6 +326,10 @@
import {fetchRuns} from "../tf-backend/runsStore.js";
import * as paginatedViewStore from "../tf-paginated-view/paginatedViewStore.js";

if (Object.keys(dashboardRegistry).length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Since we imported lodash, we could optionally use _.isEmpty(dashboardRegistry)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

throw new Error(`Plugin already registered: ${dashboard.plugin}`);
}
if (!dashboard.tabName) {
dashboard.tabName = capitalize(dashboard.plugin);
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to capitalize in JS because we do so using CSS:

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's true but I wasn't quite sure how comfortable I felt making assumptions about the CSS design here. Done.

@chihuahua
Copy link
Member

The main subsequent challenge is to smoothly update other logic that had depended on our previous API for registering plugins.

@jart jart merged commit bb57d4c into tensorflow:master Oct 4, 2017
@jart jart deleted the index-shell branch October 4, 2017 21:47
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.

3 participants