-
Notifications
You must be signed in to change notification settings - Fork 8.5k
remove angular dependencies in SavedObjectClient #20384
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
Conversation
💔 Build Failed |
c087fe1 to
d086830
Compare
💔 Build Failed |
💔 Build Failed |
|
jenkins, test this |
💔 Build Failed |
💔 Build Failed |
💔 Build Failed |
💔 Build Failed |
💔 Build Failed |
💔 Build Failed |
💚 Build Succeeded |
spalger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! No major feedback but I've just looked at the code so far.
| } | ||
| export function isAutoCreateIndexError(error) { | ||
| return ( | ||
| error.statusCode === 503 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is error.statusCode defined here? It looks like err.res.status is being used instead in other places.
| @@ -0,0 +1,19 @@ | |||
| [ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was checked in by mistake. I will remove.
| await PageObjects.settings.clickKibanaSavedObjects(); | ||
| await PageObjects.settings.importFile(path.join(__dirname, 'exports', '_import_objects_saved_search.json')); | ||
| await PageObjects.header.waitUntilLoadingHasFinished(); | ||
| await PageObjects.settings.clickImportDone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these related to this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really. The test was passing locally but failing on CI. Closing the flyout allowed the test to pass locally and on CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, any idea how that's related to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea. I looked into to it for the better part of Monday afternoon and and Tuesday morning. Must be timing related since it runs fine locally and only had problems in CI.
| import { SavedObject } from '../saved_object'; | ||
|
|
||
| function stubKfetch() { | ||
| global.kfetchStub = sinon.stub(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge fan of this, much prefer switching to jest mocks when moving from mocha but that would be even more changes to this module so I understand why you didn't do it.
That said, you could avoid using global with something like:
import { kfetch as kFetchStub } from 'ui/kfetch'
jest.mock('ui/fetch', () => ({}));
beforeEach(() => {
// jest will trash the mock automatically no real need to cleanup in afterEach()
require('ui/fetch').kfetch = sinon.stub();
});There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the tip. I have been looking for a way to mock an import without global and could not think of anything. This is much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to run those changes gives. Any ideas?
Configuration error:
Could not locate module ui/fetch (mapped as /Users/nathanreese/projects/kibana/src/ui/public/fetch)
Please check:
"moduleNameMapper": {
"/^ui\/(.*)/": "/Users/nathanreese/projects/kibana/src/ui/public/$1"
},
"resolver": undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error was because the test was trying to mock the import of ui/fetch while the real path is ui/kfetch. Got it to work
…bal, add test to error_auto_create_index to ensure compatibility with kfetch errors
spalger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulled changes, created some objects, deleted some objects, used import/export, things seem to work well. Code looks good. I'm a little concerned about the functional testing change, but if you are able to explain why that fixes things I'd be more happy. Either way I think this is good to merge.
💚 Build Succeeded |
💚 Build Succeeded |
cjcenizal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM! I had one question. You might also want to rename the processBatchQueue and createSavedObject methods in saved_objects_client.js to _processBatchQueue and _createSavedObject which would make them consistent with how other private methods are named. It doesn't look like they're used externally.
| } | ||
| export function isAutoCreateIndexError(error) { | ||
| return ( | ||
| get(error, 'res.status') === 503 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the original code incorrect, in which we were comparing error.statusCode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code used the error produced in saved_object_client _request method. But kfetch creates its own error type. Just needed to update to handle the error thrown by kfetch.
💚 Build Succeeded |
* create saved object client that is native javascript * fix savedObjectClient unit tests * get saved object client from chrome when being used outside of angular * update error handlers to pull status code from FetchError * add some debug messages to failing functional test * revert changes to management/_objects * add clicks to import done in import objects test * take screenshots of test only failing in CI * remove functional test screenshot code since test is passing in CI now * remove unused file, clean up saved_objects_client test to not use global, add test to error_auto_create_index to ensure compatibility with kfetch errors * add body to kfetch error * update savedObjectClient.bulkCreate * add bulkCreate wrapper to SavedObjectsClientProvider * mark _createSavedObject and _processBatchQueue as private methods
* create saved object client that is native javascript * fix savedObjectClient unit tests * get saved object client from chrome when being used outside of angular * update error handlers to pull status code from FetchError * add some debug messages to failing functional test * revert changes to management/_objects * add clicks to import done in import objects test * take screenshots of test only failing in CI * remove functional test screenshot code since test is passing in CI now * remove unused file, clean up saved_objects_client test to not use global, add test to error_auto_create_index to ensure compatibility with kfetch errors * add body to kfetch error * update savedObjectClient.bulkCreate * add bulkCreate wrapper to SavedObjectsClientProvider * mark _createSavedObject and _processBatchQueue as private methods
| afterEach(() => fetchMock.restore()); | ||
|
|
||
| test('should return false', async () => { | ||
| let gotError = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nreese stumbled over this while updating kfetch. fyi expect.assertions(1) is very handy in this exact scenario (https://jest-bot.github.io/jest/docs/expect.html#expectassertionsnumber)
This PR removes all angular dependencies from the SavedObjectClient. Access to the savedObjectClient instance is provided in chrome by calling
chrome.getSavedObjectsClient().The existing
SavedObjectsClientProvideris now just a wrapper around the vanilla savedObjectClient that wraps everything in an Angular Promise.