Skip to content

Conversation

@nreese
Copy link
Contributor

@nreese nreese commented Jul 2, 2018

This PR removes all angular dependencies from the SavedObjectClient. Access to the savedObjectClient instance is provided in chrome by calling chrome.getSavedObjectsClient().

The existing SavedObjectsClientProvider is now just a wrapper around the vanilla savedObjectClient that wraps everything in an Angular Promise.

@nreese nreese changed the title remove angular dependencies on SavedObjectClient remove angular dependencies in SavedObjectClient Jul 2, 2018
@nreese nreese added chore Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v7.0.0 v6.4.0 labels Jul 2, 2018
@elasticmachine
Copy link
Contributor

💔 Build Failed

@nreese nreese force-pushed the saved_objects_client branch from c087fe1 to d086830 Compare July 2, 2018 18:51
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@nreese
Copy link
Contributor Author

nreese commented Jul 2, 2018

jenkins, test this

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese requested review from rhoboat and spalger July 3, 2018 23:52
Copy link
Contributor

@spalger spalger left a 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 &&
Copy link
Contributor

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 @@
[
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this used?

Copy link
Contributor Author

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

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 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();
Copy link
Contributor

@spalger spalger Jul 4, 2018

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();
});

Copy link
Contributor Author

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

Copy link
Contributor Author

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

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 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

nreese added 2 commits July 5, 2018 09:47
…bal, add test to error_auto_create_index to ensure compatibility with kfetch errors
Copy link
Contributor

@spalger spalger left a 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.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese requested review from cjcenizal and removed request for rhoboat July 11, 2018 14:12
Copy link
Contributor

@cjcenizal cjcenizal 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! 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 &&
Copy link
Contributor

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?

Copy link
Contributor Author

@nreese nreese Jul 11, 2018

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.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@nreese nreese merged commit 572f8bb into elastic:master Jul 11, 2018
nreese added a commit to nreese/kibana that referenced this pull request Jul 11, 2018
* 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
nreese added a commit that referenced this pull request Jul 12, 2018
* 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;
Copy link
Member

@sorenlouv sorenlouv Aug 19, 2018

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v6.4.0 v7.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants