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

Add method to make managed saved objects unmanaged #1565

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

jsoriano
Copy link
Member

Managed dashboards cannot be edited starting on Kibana 8.11.

Add method to the Kibana client to toggle the managed attribute, so we can
add a command to make dashboards editable for package developers.

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

cc @jsoriano

Copy link
Member

@kpollich kpollich 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 for iterating on the original proposal 🚀

)

func TestSetManagedSavedObject(t *testing.T) {
// TODO: Use kibana test client when we support recording POST requests.
Copy link
Member Author

@jsoriano jsoriano Nov 27, 2023

Choose a reason for hiding this comment

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

Giving a try to https://gopkg.in/dnaeon/go-vcr.v3 in #1566, but I would update this test in a follow up.

Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

LGTM. Added a comment about a possible change closing a writer variable (multipartWriter)

return nil, fmt.Errorf("failed to encode object as json: %w", err)
}
}
multipartWriter.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to move this line just after 213? To ensure that it is always closed even if creating filteWriter fails

	var body bytes.Buffer
	multipartWriter := multipart.NewWriter(&body)
    defer multipartWriter.Close()
	fileWriter, err := multipartWriter.CreateFormFile("file", "file.ndjson")
	if err != nil {
		return nil, fmt.Errorf("failed to create multipart form file: %w", err)
	}

Copy link
Member Author

Choose a reason for hiding this comment

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

This Close is used to write the trailing boundary of the multipart message (see docs). So we want it to be done after writing all the objects, and before doing the request.

It doesn't need to be called in case of error.

Copy link
Member Author

Choose a reason for hiding this comment

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

But I am thinking now that I should have handled the error, just in case. PR open for this #1569.

return nil, fmt.Errorf("failed to encode request: %w", err)
}

path := SavedObjectsAPI + "/_export"
Copy link
Contributor

Choose a reason for hiding this comment

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

If this API is used, I remember that it was needed to be used starting at some Kibana version (related to this PR: #1357)

Should this be added here too ? or add maybe a comment in this method to just be used in recent Kibana versions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. In #1357 we used the new API only with newer versions of Kibana to avoid possible regressions.

But I have checked and this API is available in all the versions of Kibana we support. And this is a new feature, so there is no risk to introduce regressions, and better to use the most recent API, even if it is in preview.

Note: The used API is in preview, but the other possible APIs are deprecated, so better to use the new one so the old ones can be removed at some point.

Copy link
Contributor

@jillguyonnet jillguyonnet left a comment

Choose a reason for hiding this comment

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

🎉

@jsoriano jsoriano merged commit a0f350f into elastic:main Nov 27, 2023
4 checks passed
@jsoriano jsoriano deleted the kibana-set-managed branch November 27, 2023 18:33
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.

5 participants