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 the fields that triggered update notifications #1364

Merged
merged 13 commits into from Aug 7, 2019

Conversation

Yoann-Abbes
Copy link
Contributor

@Yoann-Abbes Yoann-Abbes commented Jul 29, 2019

What does this PR do ?

See the PR title

https://jira.kaliop.net/browse/KZL-1127

How should this be manually tested?

Execute this script and see the notification:

const {
    Kuzzle,
    WebSocket
} = require('kuzzle-sdk');

const kuzzle = new Kuzzle(
    new WebSocket('localhost')
);

function callback (notification) {
    console.log(notification);
}

kuzzle.on('networkError', error => {
    console.error('Network Error:', error);
});

const run = async () => {
    try {
        await kuzzle.connect();
        await kuzzle.document.createOrReplace(
            'nyc-open-data',
            'yellow-taxi',
            'some-id',
            { capacity: 4, members: 5 },
        );
        const filters = { exists: 'capacity' };
        await kuzzle.realtime.subscribe('nyc-open-data', 'yellow-taxi', filters, callback);
        const response = await kuzzle.document.update(
            'nyc-open-data',
            'yellow-taxi',
            'some-id',
            { capacity: 100, members: 50 }
        );
        console.log(response);
    } catch (error) {
        console.error(error.message);
    } finally {
        kuzzle.disconnect();
    }
};
run();

@Yoann-Abbes Yoann-Abbes self-assigned this Jul 29, 2019
@codecov
Copy link

codecov bot commented Jul 29, 2019

Codecov Report

Merging #1364 into 1-dev will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##            1-dev    #1364      +/-   ##
==========================================
+ Coverage   93.89%   93.89%   +<.01%     
==========================================
  Files         106      106              
  Lines        7304     7306       +2     
==========================================
+ Hits         6858     6860       +2     
  Misses        446      446
Impacted Files Coverage Δ
lib/api/core/notifier.js 73.33% <100%> (+0.4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c37de8c...d4579ac. Read the comment docs.

@@ -65,7 +65,8 @@ describe('Test: notifier.notifyDocumentUpdate', () => {
{
_id,
_meta: {canIhas: 'cheezburgers?'},
_source: {foo: 'bar'}
_source: {foo: 'bar'},
_updatedField: '_kuzzle_info'
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't understand the test well I think, for me the field foo should be present in the _updatedField array no?
And here _updatedField is not an array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the request sent in this test :

request = new Request({
      controller: 'document',
      action: 'update',
      index: 'foo',
      collection: 'bar',
      _id: 'Sir Isaac Newton is the deadliest son-of-a-bitch in space',
      body: {
        _kuzzle_info: {
          'canIhas': 'cheezburgers?'
        },
        foo: 'bar'
      }
    });

The updated field is _kuzzle_info as you can see

In deed it's not an array, why should it be ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_source is the document, in the request it's updated by adding the field _kuzzle_info

Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot update the field _kuzzle_info, it's ignored by the Elasticsearch service.
I mean an array because an update request may modify several fields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right for the array
for the _kuzzle_info field :
Since Kuzzle update _kuzzle_info automatically, do I remove it from the resulted array or not ?
['foo', '_kuzzle_info'] or
['foo']

(for now, i removed it, let me know if its more relevant to keep it)

Copy link
Contributor

Choose a reason for hiding this comment

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

The updatedFields gives the following information: "the list of changed fields that triggered that real-time notification`.

_kuzzle_info is merely a side-effect, always updated alongside any update request, so it cannot be the cause of a real-time notification.

Ergo, _kuzzle_info should never appear in the updatedFIelds list.

@Yoann-Abbes Yoann-Abbes requested a review from Aschen July 31, 2019 09:12
@Aschen Aschen changed the title Add 'updatedField' in Update notifications Add the fields that triggered update notifications Jul 31, 2019
lib/api/core/notifier.js Outdated Show resolved Hide resolved
scottinet and others added 2 commits August 2, 2019 11:39
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
Copy link
Member

@alexandrebouthinon alexandrebouthinon left a comment

Choose a reason for hiding this comment

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

You should try with a document containing more than one field. I'm not sure but I think your code just return all document fields except _kuzzle_info 😅 And you should also update the functional tests with a updated fields check 😉

EDIT: I tested with a multiple fields document and it works. But you really should update functional tests to avoid regression.

} else {
console.log('Wrong notification received: ');
console.dir(this.api.responses, { colors: true, depth: null });
callback('The document was supposed to contain the member "' + member + '" with ' + n_elements + ' elements : Has '+ this.api.responses.result[member].length +'.');
Copy link
Contributor

Choose a reason for hiding this comment

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

(nitpicking) use string litterals

@scottinet scottinet merged commit 3a69c80 into 1-dev Aug 7, 2019
@scottinet scottinet deleted the KZL-1127-receive-field-updated-in-notification branch August 7, 2019 13:40
Yoann-Abbes added a commit that referenced this pull request Aug 20, 2019
## What does this PR do ?

See the PR title

https://jira.kaliop.net/browse/KZL-1127

### How should this be manually tested?

Execute this script and see the notification:

```
const {
    Kuzzle,
    WebSocket
} = require('kuzzle-sdk');

const kuzzle = new Kuzzle(
    new WebSocket('localhost')
);

function callback (notification) {
    console.log(notification);
}

kuzzle.on('networkError', error => {
    console.error('Network Error:', error);
});

const run = async () => {
    try {
        await kuzzle.connect();
        await kuzzle.document.createOrReplace(
            'nyc-open-data',
            'yellow-taxi',
            'some-id',
            { capacity: 4, members: 5 },
        );
        const filters = { exists: 'capacity' };
        await kuzzle.realtime.subscribe('nyc-open-data', 'yellow-taxi', filters, callback);
        const response = await kuzzle.document.update(
            'nyc-open-data',
            'yellow-taxi',
            'some-id',
            { capacity: 100, members: 50 }
        );
        console.log(response);
    } catch (error) {
        console.error(error.message);
    } finally {
        kuzzle.disconnect();
    }
};
run();
```
@Aschen Aschen mentioned this pull request Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants