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

[Reporting] Use updated saved object resolver #113641

Merged
merged 5 commits into from
Oct 21, 2021

Conversation

dokmic
Copy link
Contributor

@dokmic dokmic commented Oct 1, 2021

Summary

Resolves #112565.

Checklist

@dokmic dokmic added review (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:AppServicesUx labels Oct 1, 2021
@dokmic dokmic force-pushed the feature/112565 branch 2 times, most recently from 3c8b2dc to 0763c9f Compare October 4, 2021 09:31
@dokmic dokmic marked this pull request as ready for review October 4, 2021 11:43
@dokmic dokmic requested review from a team as code owners October 4, 2021 11:43
@@ -21,10 +21,12 @@ export const createJobFnFactory: CreateJobFnFactory<
);

const savedObjectsClient = context.core.savedObjects.client;
const indexPatternSavedObject = (await savedObjectsClient.get(
const {
saved_object: { attributes: indexPatternSavedObject },
Copy link
Member

Choose a reason for hiding this comment

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

you should check if you got the object

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've checked the saved objects client implementation, and it matches the types they claim (server and public). The saved_object property is always an object.

Copy link
Member

Choose a reason for hiding this comment

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

what happens if you request an object which doesnt exist, or if you get into conflict scenario? https://www.elastic.co/guide/en/kibana/master/sharing-saved-objects.html#sharing-saved-objects-step-3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case, the save_object is still there. You can see that in the code (server and public).

@@ -21,10 +21,12 @@ export const createJobFnFactory: CreateJobFnFactory<
);

const savedObjectsClient = context.core.savedObjects.client;
Copy link
Member

Choose a reason for hiding this comment

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

actually, we shouldnt be using saved objects client here. we should use data.indexPatterns service. can you please update that ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that the context.core is a setup contract that doesn't have the data plugin instance. I can work that around, but this is a deprecated job type that should be removed in 8.0. And the issue is labeled as v8.0.0 only. Fixing that here will produce extra work with removing that later without any impact on the final result.

Copy link
Member

Choose a reason for hiding this comment

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

ok if we are removing this in 8.0 then its ok. (cc @tsullivan are we sure its gonna get removed in 8.0?)

the problem with this approach is that you need to know internals of data views (index patterns), like how are they stored etc. Any change on index patterns will break your logic and its hard to detect that. Saved objects should be loaded only by their owners and nobody else.

Copy link
Member

@tsullivan tsullivan Oct 7, 2021

Choose a reason for hiding this comment

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

export_types/csv is not being removed in 8.0. The code isn't accessible through the UI, but we know from telemetry data that users are still generating these exports using automation that was set up in an older version. So we don't want their automation to immediately break once they upgrade. Once the removal won't affect many users we will do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, then I guess we should use the data plugin here instead. And correct the warning saying that it will be removed in 8.0 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppisljar @tsullivan I've updated the factory to reuse the data plugin. Could you please take another look?


return {
isDeprecated: true,
indexPatternSavedObject,
indexPatternSavedObject: omitBy(
Copy link
Member

Choose a reason for hiding this comment

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

why not just pass dataView in ?

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 am afraid that's not going to work. We put it here to serialize and deserialize that later.

Copy link
Member

Choose a reason for hiding this comment

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

you should only store data view id then, and load it again later using data view apis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes total sense, thanks. I've fixed that.

const fieldFormatMap = JSON.parse(indexPatternSavedObject.attributes.fieldFormatMap);
Object.keys(fieldFormatMap).forEach((fieldName) => {
const formatConfig: FieldFormatConfig = fieldFormatMap[fieldName];
if (_.has(indexPatternSavedObject, 'fieldFormatMap')) {
Copy link
Member

Choose a reason for hiding this comment

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

this whole function is pretty much constructing what's already available on data views.
if you don't convert dataview to your indexPatternSavedObject (which you shouldn't) then you can just use
dataView.fieldFormatMap or even better use provided functions on the dataview:
dataview.getFormatterForField(field)

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 comes from the ES document as a plain object. In the job factory, I tried to gather all the data we used previously and store that in a similar way.

@dokmic
Copy link
Contributor Author

dokmic commented Oct 18, 2021

@elasticmachine merge upstream

@dokmic
Copy link
Contributor Author

dokmic commented Oct 20, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
reporting 134 136 +2
Unknown metric groups

API count

id before after diff
reporting 135 137 +2

History

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

@jportner
Copy link
Contributor

I just wanted to check on the status of this, it's blocking #114408

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

code LGTM

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

LGTM

@dokmic dokmic merged commit 6b64103 into elastic:master Oct 21, 2021
@dokmic dokmic deleted the feature/112565 branch October 21, 2021 14:14
shivindera pushed a commit to shivindera/kibana that referenced this pull request Oct 25, 2021
* Update deprecated PDF job factory to use updated saved object resolver
* Reuse data plugin service to gather index pattern attributes in the deprecated CSV export type
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 113641 or prevent reminders by adding the backport:skip label.

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Oct 25, 2021
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 113641 or prevent reminders by adding the backport:skip label.

@jportner jportner added the backport:skip This commit does not require backporting label Oct 26, 2021
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead release_note:skip Skip the PR/issue when compiling release notes review v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reporting needs to use savedObjectsClient.resolve when retrieving saved objects
5 participants