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

Initial implementation of server licensing service #41026

Closed
wants to merge 2 commits into from

Conversation

eliperelman
Copy link
Contributor

@eliperelman eliperelman commented Jul 12, 2019

Summary

Licensing service. This is currently a work in progress:

  • Server implementation
  • Server tests

Fixes #18356.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@eliperelman eliperelman added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v8.0.0 v7.4.0 labels Jul 12, 2019
@eliperelman eliperelman self-assigned this Jul 12, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform

@eliperelman
Copy link
Contributor Author

eliperelman commented Jul 12, 2019

Right now the current return value of setting up the server licensing service returns a BehaviorSubject to allow consumers to subscribe to changes to the license over time and react accordingly.

type LicensingServiceSubject = BehaviorSubject<LicensingServiceSetup | null>;

const licensing: LicensingServiceSubject;
// ...

licensing.subscribe(license => {
  if (!license) {
    // Service is null until polled and started.
    return;
  }

  const { status, message } = license.check('discovery', LICENSE_TYPE.gold);
  // ...
});

from(this.fetchInfo(deps, clusterSource, pollingFrequency)).pipe(
tap(({ license, error, features }) => {
// If license is false, the license did not change and we don't need to push
// a new one
Copy link
Contributor

Choose a reason for hiding this comment

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

On line 91 it returns false if the license did change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@elasticmachine
Copy link
Contributor

💔 Build Failed

@joshdover
Copy link
Contributor

Overall, this is looking like how I would expect it to 👍

Per our discussion in the weekly, I would advise changing the interface exposed by the service to be a Observable of some interface rather than a class, and then you can implement that interface in the class. This makes testing and mocking easier for consumers. #39446 (comment)

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

I was curious so I had to look. 😄 Had some comments I thought worth sharing, feel free to disregard them.

private serializable: LicenseFeatureSerializer = service => ({
name: this.name,
isAvailable: this.isAvailable,
isEnabled: this.isEnabled,
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 difference between isAvailable and isEnabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a clue, I'll see what I can find out. 😄


private hasLicenseInfoChanged(newLicense: any) {
return (
newLicense.mode !== this.license.mode ||
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 mode? If this corresponds to the LICENSE_TYPE enum, then maybe type would make that clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was preexisting from x-pack legacy, so I'll see about making this clearer.

private clusterSource: string
) {
this._license = license;
this.license = license || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

I probably won't ever maintain this code, but if I did, I think I would be confused by the presence of this._license and this.license. I would be able to follow this code more easily if we only had one or the other. It looks like this._license is only used to assert whether there is a license or not. In that case, could we do this instead?

constructor(
  license: any,
  features: any,
  private error: Error | null,
  private clusterSource: string
) {
  this.hasLicense = Boolean(license);
  this.license = license || {};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree 💯

return this.objectified;
}

feature(name: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit, but I'd find this method easier to understand if there was a verb in the name, e.g. getFeature.

* @internal
*/
constructor(rawConfig: LicensingConfigType, env: Env) {
this.enabled = rawConfig.enabled;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see isEnabled used in some places and enabled in others. Should be standardize on one or the other? My preference would be isEnabled, because I'm used to seeing words like is used to identify booleans.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this comes from configuration that we control, this is a good idea. Will revise.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@joshdover joshdover added this to In progress in kibana-core [DEPRECATED] Jul 15, 2019
kibana-core [DEPRECATED] automation moved this from In progress to Done (this week) Aug 20, 2019
@eliperelman eliperelman removed Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v7.4.0 v8.0.0 labels Sep 4, 2019
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.

License plugin
4 participants