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 union of strings instead of enum #62493

Merged
merged 3 commits into from
Apr 6, 2020

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Apr 3, 2020

Summary

Part of #62263
Prevents licensing plugin code leakage into plugin bundles.
Before:

find x-pack/  -type f -name "*[a-zA-Z].plugin.js" -exec du -ch {} + | grep total$
 36M	total

After:

find x-pack/  -type f -name "*[a-zA-Z].plugin.js" -exec du -ch {} + | grep total$
 33M	total

@mshustov mshustov added chore Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Apr 3, 2020
@mshustov mshustov requested review from a team as code owners April 3, 2020 17:47
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

Alerting changes LGTM

@spalger
Copy link
Contributor

spalger commented Apr 3, 2020

@elasticmachine merge upstream

@cjcenizal cjcenizal self-requested a review April 3, 2020 21:07
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.

ES UI apps look good but I have a question about DX.

Checked these apps:

  • Painless Lab
  • Remote Clusters
  • Search Profiler
  • Snapshot Restore
  • Watcher

In terms of DX, how are developers expected to discover the valid values of this string union? If I make a typo, the TS checker gives me this error:

      x-pack/plugins/painless_lab/server/services/license.ts:40:34 - error TS2367: This condition will always return 'false' since the types 'LicenseCheckState' and '"vaild"' have no overlap.

      40       const hasRequiredLicense = state === 'vaild';

What is the expected experience for a developer who is trying to fix this, or trying to compare against a different value?

@@ -37,7 +37,7 @@ export class License {
) {
licensing.license$.subscribe(license => {
const { state, message } = license.check(pluginId, minimumLicenseType);
const hasRequiredLicense = state === LICENSE_CHECK_STATE.Valid;
const hasRequiredLicense = state === 'valid';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -82,7 +81,7 @@ export class PainlessLabUIPlugin implements Plugin<void, void, PluginDependencie
PLUGIN.id,
PLUGIN.minimumLicenseType
);
const isValidLicense = state === LICENSE_CHECK_STATE.Valid;
const isValidLicense = state === 'valid';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -54,7 +53,7 @@ export class RemoteClustersServerPlugin implements Plugin<void, void, any, any>

licensing.license$.subscribe(license => {
const { state, message } = license.check(PLUGIN.getI18nName(), PLUGIN.minimumLicenseType);
const hasRequiredLicense = state === LICENSE_CHECK_STATE.Valid;
const hasRequiredLicense = state === 'valid';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -50,7 +49,7 @@ export class SearchProfilerUIPlugin implements Plugin<void, void, AppPublicPlugi
const license = await licensing.license$.pipe(first()).toPromise();
const { state, message } = license.check(PLUGIN.id, PLUGIN.minimumLicenseType);
const initialLicenseStatus =
state === LICENSE_CHECK_STATE.Valid ? { valid: true } : { valid: false, message };
state === 'valid' ? { valid: true } : { valid: false, message };
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -33,7 +31,7 @@ export class SearchProfilerServerPlugin implements Plugin {

licensing.license$.subscribe(license => {
const { state, message } = license.check(PLUGIN.id, PLUGIN.minimumLicenseType);
const hasRequiredLicense = state === LICENSE_CHECK_STATE.Valid;
const hasRequiredLicense = state === 'valid';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -38,7 +37,7 @@ export class License {
) {
licensing.license$.subscribe(license => {
const { state, message } = license.check(pluginId, minimumLicenseType);
const hasRequiredLicense = state === LICENSE_CHECK_STATE.Valid;
const hasRequiredLicense = state === 'valid';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

import { TimeBuckets } from './legacy';
import { PLUGIN } from '../common/constants';
import { Dependencies } from './types';

const licenseToLicenseStatus = (license: ILicense): LicenseStatus => {
const { state, message } = license.check(PLUGIN.ID, PLUGIN.MINIMUM_LICENSE_REQUIRED);
return {
valid: state === LICENSE_CHECK_STATE.Valid && license.getFeature(PLUGIN.ID).isAvailable,
valid: state === 'valid' && license.getFeature(PLUGIN.ID).isAvailable,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -73,7 +72,7 @@ export class WatcherServerPlugin implements Plugin<void, void, any, any> {

licensing.license$.subscribe(async license => {
const { state, message } = license.check(PLUGIN.ID, PLUGIN.MINIMUM_LICENSE_REQUIRED);
const hasMinimumLicense = state === LICENSE_CHECK_STATE.Valid;
const hasMinimumLicense = state === 'valid';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

ML/transform changes LGTM.

Copy link
Member

@legrego legrego left a comment

Choose a reason for hiding this comment

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

Security changes LGTM

Copy link
Contributor

@thomasneirynck thomasneirynck left a comment

Choose a reason for hiding this comment

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

maps/* lgtm, code review

@mshustov
Copy link
Contributor Author

mshustov commented Apr 6, 2020

What is the expected experience for a developer who is trying to fix this, or trying to compare against a different value?

@cjcenizal

  1. The error message contains a reference to the correct type LicenseCheckState.
  2. IDE handles a union of strings and provides autocomplete.
    2020-04-06_09-44-37
  3. Union of strings doesn't require from developer to know what enum to import.

@mshustov
Copy link
Contributor Author

mshustov commented Apr 6, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mshustov mshustov merged commit bdf628d into elastic:master Apr 6, 2020
@mshustov mshustov deleted the issue-62263-no-enum-licensing branch April 6, 2020 10:31
mshustov added a commit to mshustov/kibana that referenced this pull request Apr 6, 2020
mshustov added a commit to mshustov/kibana that referenced this pull request Apr 6, 2020
mshustov added a commit that referenced this pull request Apr 6, 2020
Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
mshustov added a commit that referenced this pull request Apr 6, 2020
Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.