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

migrate i18n mixin to KP #81799

Merged
merged 18 commits into from
Nov 10, 2020
Merged

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Oct 27, 2020

Summary

Fix #50647

Migrate i18n loading to core.

  • Create a new i18n service
  • Move the Localization usage collector to the kibana_usage_collection plugin

Checklist

@pgayvallet pgayvallet added Feature:Legacy Removal Issues related to removing legacy Kibana 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.11 chore labels Oct 27, 2020
@timroes timroes added v7.11.0 and removed v7.11 labels Oct 29, 2020
Comment on lines +38 to 39
// do not try to shorten the import to `./status`, it will break server test mocking
import { StatusService } from './status/status_service';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL, after loosing 1h on that...

Comment on lines -16 to 3
"type": "long"
}
}
}
}
"properties": {}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elastic/kibana-telemetry This PR removes the last legacy usage collector. I guess this file and the generation / usage around it could now be safely deleted I guess. Not sure if it is trivial enough to be done in current PR though. Would it be fine to let you handle that in a follow-up?

Copy link
Member

Choose a reason for hiding this comment

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

We'd have to update the .telemetryrc.json file and it will automatically be removed. We can push that change in another PR

Comment on lines 39 to 44
getLocale(): string;

/**
* Return the list of translation files currently in use.
*/
getTranslationFiles(): string[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need that to be accessible for the localization usage collector.

The getLocale is not really necessary as the collector could use i18n.getLocale() instead, but from an architectural point of view, I think it is better to have core be the entry point for that (and the contract is needed anyway for getTranslationFiles so it did not cost much to also add an additional API to it)

Copy link
Contributor

Choose a reason for hiding this comment

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

According to our classification, @kbn/i18n should be implemented as a service because it's a stateful package. IIRC we were discussing to deprecate direct access to @kbn/i18n in favour of i18n Platform service, so 👍

Comment on lines 29 to 32
getTranslationPaths({
cwd: fromRoot('.'),
glob: `*/${I18N_RC}`,
nested: true,
}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK, this is only used to get the x-pack/.i18nrc.json file. However to avoid any risk / breaking changes (User could have custom i18nrc files in another non-plugin folder eventually), I kept it as it was done in legacy.

Copy link
Member

Choose a reason for hiding this comment

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

@pgayvallet only in x-pack. I believe it is safe to change it as long as x-pack and kibana's root dir are discoverable.

Copy link
Contributor

Choose a reason for hiding this comment

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

does it mean that it traverses all the node_modules and other unnecessary folders?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. */something globbing is only scanning a single level (as opposed to **/something)

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 didn't check implementation. but nested: true traversing on a single level in-depth is confusing 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, you're right. I kinda wanted to rename it to includeSubFolders, but is was way longer, and not really more explicit that we are only scanning one level down. No issue renaming if you have a better idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

We will need something similar to maxScanDepth in discovery to support migration to Domain-based folder structure. But I'm okay to keep it as is for now.

Comment on lines 34 to 37
getTranslationPaths({
cwd: fromRoot('../kibana-extra'),
glob: `*/${I18N_RC}`,
nested: true,
}),
Copy link
Contributor Author

@pgayvallet pgayvallet Nov 2, 2020

Choose a reason for hiding this comment

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

Are we really still using kibana-extra? Kept that, but not sure if it is really necessary.

Copy link
Member

Choose a reason for hiding this comment

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

As long as we still support running plugins from that path then we should keep it. If not there is no need to.

Copy link
Contributor

Choose a reason for hiding this comment

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

We still search for a plugin in kibana-extra

resolve(rootDir, '..', 'kibana-extra'),
and kbn-pm supports it as well https://github.com/elastic/kibana/blob/0068c87d6fe7713351acbf42080faa09ff73ef15/packages/kbn-pm/README.md
But I haven't checked whether it works

Comment on lines -31 to +33
...(config.get('plugins.paths') as string[]).map((cwd) =>
getTranslationPaths({ cwd, glob: I18N_RC })
),
...(config.get('plugins.scanDirs') as string[]).map((cwd) =>
getTranslationPaths({ cwd, glob: `*/${I18N_RC}` })
),
...pluginPaths.map((pluginPath) => getTranslationPaths({ cwd: pluginPath, nested: false })),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a slight change of behavior here:

Legacy was just reading the plugin config and scanning the scanDirs (1 lvl deep) and paths (root lvl) for i18n rc files.

I chose to change that by retrieving the list of enabled plugins from the plugin service, and check if there is a i18n file at the root level of each plugin instead. This is basically the same, except that we are not loading translation files for disabled plugins (note that this only concerns 3rd parties plugin, as kibana translations are all defined from a single x-pack/.i18nrc.json file anyway). Overall, I think it should not really impact 3rd parties, and not loading translations for disabled plugins does make sense imho. (This is also way better at the code level in term of responsibilities per service. I was really awkward to load the plugins config from the i18n service)

@pgayvallet pgayvallet marked this pull request as ready for review November 2, 2020 10:15
@pgayvallet pgayvallet requested review from a team as code owners November 2, 2020 10:15
@elasticmachine
Copy link
Contributor

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

Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

Telemetry changes LGTM!

Copy link
Member

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks

Comment on lines 29 to 32
getTranslationPaths({
cwd: fromRoot('.'),
glob: `*/${I18N_RC}`,
nested: true,
}),
Copy link
Member

Choose a reason for hiding this comment

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

@pgayvallet only in x-pack. I believe it is safe to change it as long as x-pack and kibana's root dir are discoverable.

Comment on lines 34 to 37
getTranslationPaths({
cwd: fromRoot('../kibana-extra'),
glob: `*/${I18N_RC}`,
nested: true,
}),
Copy link
Member

Choose a reason for hiding this comment

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

As long as we still support running plugins from that path then we should keep it. If not there is no need to.

Comment on lines -16 to 3
"type": "long"
}
}
}
}
"properties": {}
}
Copy link
Member

Choose a reason for hiding this comment

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

We'd have to update the .telemetryrc.json file and it will automatically be removed. We can push that change in another PR

Copy link
Contributor

@mshustov mshustov left a comment

Choose a reason for hiding this comment

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

I'd like to adjust #81799 (comment) if necessary. Otherwise looks good

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Distributable file count

id before after diff
default 42766 42768 +2
oss 22455 22457 +2

History

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

@pgayvallet pgayvallet merged commit f49ee06 into elastic:master Nov 10, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Nov 10, 2020
* migrate i18n mixin to KP

* directly load the config from i18n service

* add base tests

* update telemetry schema

* update legacy telemetry schema

* fix server tests

* use paths from config service instead of manually loading the plugin config

* add tests for get_translation_paths

* add tests for i18n service

* add plugin service test

* update generated doc

* improve tsdoc
pgayvallet added a commit that referenced this pull request Nov 10, 2020
* migrate i18n mixin to KP

* directly load the config from i18n service

* add base tests

* update telemetry schema

* update legacy telemetry schema

* fix server tests

* use paths from config service instead of manually loading the plugin config

* add tests for get_translation_paths

* add tests for i18n service

* add plugin service test

* update generated doc

* improve tsdoc
phillipb added a commit to phillipb/kibana that referenced this pull request Nov 10, 2020
…kibana into bootstrap-node-details-overlay

* 'bootstrap-node-details-overlay' of github.com:phillipb/kibana: (49 commits)
  [Security Solution] Fix DNS Network table query (elastic#82778)
  [Workplace Search] Consolidate groups routes (elastic#83015)
  Adds cloud links to user menu (elastic#82803)
  [Security Solution][Detections] - follow up cleanup on auto refresh rules (elastic#83023)
  [App Search] Added the log retention panel to the Settings page (elastic#82982)
  [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (elastic#83006)
  [DOCS] Consolidates drilldown pages (elastic#82081)
  [Maps] add on-prem EMS config (elastic#82525)
  migrate i18n mixin to KP (elastic#81799)
  [bundle optimization] fix imports of react-use lib (elastic#82847)
  [Discover] Add metric on adding filter (elastic#82961)
  [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (elastic#82829)
  skip flaky suite (elastic#82804)
  Fix SO query for searching across spaces (elastic#83025)
  renaming built-in alerts to Stack Alerts (elastic#82873)
  [TSVB] Disable using top_hits in pipeline aggregations (elastic#82278)
  [Visualizations] Remove kui usage (elastic#82810)
  [Visualizations] Make the icon buttons labels more descriptive (elastic#82585)
  [Lens] Do not reset formatting when switching between custom ranges and auto histogram (elastic#82694)
  Fix ilm navigation (elastic#81664)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 10, 2020
…na into alerts/stack-alerts-public

* 'alerts/stack-alerts-public' of github.com:gmmorris/kibana:
  [Security Solution] Fix DNS Network table query (elastic#82778)
  [Workplace Search] Consolidate groups routes (elastic#83015)
  Adds cloud links to user menu (elastic#82803)
  [Security Solution][Detections] - follow up cleanup on auto refresh rules (elastic#83023)
  [App Search] Added the log retention panel to the Settings page (elastic#82982)
  [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (elastic#83006)
  [DOCS] Consolidates drilldown pages (elastic#82081)
  [Maps] add on-prem EMS config (elastic#82525)
  migrate i18n mixin to KP (elastic#81799)
  [bundle optimization] fix imports of react-use lib (elastic#82847)
  [Discover] Add metric on adding filter (elastic#82961)
  [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (elastic#82829)
  skip flaky suite (elastic#82804)
  Fix SO query for searching across spaces (elastic#83025)
  renaming built-in alerts to Stack Alerts (elastic#82873)
  [TSVB] Disable using top_hits in pipeline aggregations (elastic#82278)
  [Visualizations] Remove kui usage (elastic#82810)
  [Visualizations] Make the icon buttons labels more descriptive (elastic#82585)
  [Lens] Do not reset formatting when switching between custom ranges and auto histogram (elastic#82694)
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:Legacy Removal Issues related to removing legacy Kibana 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.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate i18n server part
7 participants