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

handling references for kibana_context and get_index_pattern expression functions #95224

Merged
merged 10 commits into from
Mar 25, 2021

Conversation

ppisljar
Copy link
Member

@ppisljar ppisljar commented Mar 23, 2021

Summary

Handling reference injection and extraction for kibana_context and getIndexPattern expression functions

  • kibana_context function was refactored so it no longer depends on getSavedObject handler
  • getSavedObject handler was removed from expression handlers
  • kibana_context function now extracts and injects reference to the saved search from its savedSearchId parameter
  • getIndexPattern function now extracts and injects reference to the saved index pattern from its id parameter
  • expression executor was updated to correctly call extract and inject on functions

resolves #59960

Checklist

Delete any items that are not applicable to this PR.

@ppisljar ppisljar added WIP Work in progress Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) v8.0.0 Team:AppServices release_note:skip Skip the PR/issue when compiling release notes v7.13.0 labels Mar 23, 2021
@ppisljar ppisljar requested a review from a team as a code owner March 23, 2021 18:53
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

@ppisljar ppisljar force-pushed the expressions/extract_inject branch from 3e2d11f to b7b86cb Compare March 24, 2021 12:00
@ppisljar ppisljar removed the WIP Work in progress label Mar 24, 2021
id: state.id[0] as string,
},
];
state.id[0] = refName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that okay that the state object is mutable? Wouldn't it cause any side effects?

Copy link
Member Author

Choose a reason for hiding this comment

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

i'll update it to not mutate


extract(state) {
const references: SavedObjectReference[] = [];
if (state.savedSearchId.length && typeof state.savedeSearchId[0] === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

The first clause is redundant because the typeof will return undefined for an unexisting item.

Suggested change
if (state.savedSearchId.length && typeof state.savedeSearchId[0] === 'string') {
if (typeof state.savedeSearchId[0] === 'string') {

getStartServices: StartServicesAccessor<DataPluginStartDependencies, DataPluginStart>;
}) {
return getKibanaContextFn(async (getKibanaRequest) => {
if (!getKibanaRequest || !getKibanaRequest()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!getKibanaRequest || !getKibanaRequest()) {
if (!getKibanaRequest?.()) {

Copy link
Contributor

@dokmic dokmic left a comment

Choose a reason for hiding this comment

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

I just left a few minor suggestions, but the code looks good to me.

@streamich streamich assigned streamich and unassigned streamich Mar 24, 2021
@streamich streamich self-requested a review March 24, 2021 14:35
Copy link
Contributor

@streamich streamich left a comment

Choose a reason for hiding this comment

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

Checked on Chrome/Mac, LGTM, except the savedSearchId property check, see below.

const timeRange = args.timeRange || input?.timeRange;
let queries = mergeQueries(input?.query, args?.q || []);
let filters = [...(input?.filters || []), ...(args?.filters?.map(unboxExpressionValue) || [])];
async fn(input, args, { getKibanaRequest }) {
Copy link
Contributor

@streamich streamich Mar 24, 2021

Choose a reason for hiding this comment

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

I'm a bit confused about what does getKibanaRequest resolve to, as KibanaRequest is the server-side type and makes sense only on the server.

Not specific to this PR:

Also, I'm skeptical about using KibanaRequest type in expressions plugin. Maybe there is a way to create our own wrapper around it, call it ExpressionUserContext.

The problem I see with it is that it assumes that you can authenticate only using KibanaRequest. Also, it exports KibanaRequest in ExecutionContext interface from expressions plugin, making it our public API, but when Core will want to change something in KibanaRequest, they might need to do changes to expressions plugin and it might be breaking change in expressions plugin. Just some thoughts.

Copy link
Member Author

Choose a reason for hiding this comment

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

getKibanaRequest on the client will be undefined, but the getStartServices function on the client doesn't expect it. this is just so we can keep the same code in common.

i agree the whole kibana request thing is a bit weird and we should probably do somethin about it in the future

return getKibanaContextFn(async (getKibanaRequest) => {
if (!getKibanaRequest || !getKibanaRequest()) {
throw new Error(
i18n.translate('data.search.kibana_context.error.kibanaRequest', {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like an error message for Kibana developers, and this error should never happen, it looks like a check just in case a developer made a mistake. In that case, shall we skip translation here, especially considering that this code executes on the server.

If we still want to translate it, maybe better throw an error code, like

throw new Error('KIBANA_REQUEST_MISSING');

and then translate the error on the client-side.

ppisljar and others added 5 commits March 24, 2021 19:39
Co-authored-by: Vadim Dalecky <streamich@gmail.com>
Co-authored-by: Michael Dokolin <dokmic@gmail.com>
# Conflicts:
#	src/plugins/data/server/search/search_service.ts
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
data 625 626 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 788.1KB 789.0KB +851.0B
expressions 193.3KB 193.4KB +57.0B
total +908.0B

History

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

@ppisljar ppisljar merged commit 1e87cef into elastic:master Mar 25, 2021
ppisljar added a commit to ppisljar/kibana that referenced this pull request Mar 25, 2021
…on functions (elastic#95224)

# Conflicts:
#	src/plugins/data/server/search/search_service.ts
ppisljar added a commit that referenced this pull request Mar 25, 2021
…on functions (#95224) (#95401)

# Conflicts:
#	src/plugins/data/server/search/search_service.ts
@ppisljar ppisljar deleted the expressions/extract_inject branch March 29, 2021 08:45
ppisljar added a commit that referenced this pull request Oct 13, 2021
…on functions (#95224) (#114447)

# Conflicts:
#	src/plugins/data/server/search/search_service.ts

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) release_note:skip Skip the PR/issue when compiling release notes v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling saved object references in expressions
5 participants