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 API actions to prune payloads collection #49

Merged
merged 10 commits into from
Apr 2, 2021

Conversation

Yoann-Abbes
Copy link
Contributor

Add an API action to clean the payloads collection by days and/or valid payloads and/or deviceModel

Closes #27

@Yoann-Abbes Yoann-Abbes self-assigned this Mar 23, 2021
@Yoann-Abbes Yoann-Abbes linked an issue Mar 23, 2021 that may be closed by this pull request
### HTTP

```http
URL: http://kuzzle:7512/_/device-manager/devices/_clean_
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
URL: http://kuzzle:7512/_/device-manager/devices/_clean_
URL: http://kuzzle:7512/_/device-manager/devices/_clean


# clean

Cleans the payload collection.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add more info about the option available to clean the collection?

### Kourou

```bash
kourou device-manager/device:clean '{"days": <days>, "valid": "true|false", "deviceModel": "<deviceModel>"}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you transform the object in a multiline object for more readability?
Also it's not JSON so you don't need " for properties name

## Arguments

- `days`: Specify on which period of time you want keep payloads (`default: 7`).
- `valid`: Specify which payloads are to be deleted (`default: true`).
Copy link
Contributor

Choose a reason for hiding this comment

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

Also this should not be a boolean so people can choose between valid, invalid or both

Suggested change
- `valid`: Specify which payloads are to be deleted (`default: true`).
- `valid`: Specify if valid, invalid or both payload should be deleted (`default: true`).


## Response

Returns an array with the deleted payloads ids.
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO this is useless. Just the number of deleted payload is enough I think

@@ -27,3 +27,20 @@ Then(/I (successfully )?receive a "(.*?)" payload with:/, async function (expect
this.props.error = error;
}
});

Then(/I clean the payloads collection with args:/, async function (dataTable) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Useless step

@@ -50,7 +50,7 @@ export class CRUDController extends NativeController {
*
* @param request
*/
async delete (request: KuzzleRequest) {
delete (request: KuzzleRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should stay async since handler function should always return a promise.

Here if anything goes wrong the method will throw an exception and not return a rejected promise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why only delete ? The others are not async

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm they all should be async then

const filter = []
filter.push({
range: {
"_kuzzle_info.createdAt": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking: you should use single quote

@Yoann-Abbes Yoann-Abbes requested a review from Aschen March 23, 2021 14:17
Copy link
Contributor

@Aschen Aschen left a comment

Choose a reason for hiding this comment

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

The action name should be more explicite since it's in the device controller, something like cleanPayloads

@Yoann-Abbes Yoann-Abbes requested a review from Aschen March 23, 2021 14:52
@Aschen
Copy link
Contributor

Aschen commented Mar 23, 2021

Changelog label is missing

description: Cleans the payload collection
---

# cleanPayloads

Choose a reason for hiding this comment

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

(nitpicking) usually the associated term for that kind of operation is "prune": prunePayloads

Copy link
Contributor Author

@Yoann-Abbes Yoann-Abbes Mar 24, 2021

Choose a reason for hiding this comment

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

I thought prune is used when everything is erased?

Copy link

@scottinet scottinet Mar 24, 2021

Choose a reason for hiding this comment

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


verb (used with object), pruned, prun·ing.

* to cut or lop off (twigs, branches, or roots).
* to cut or lop superfluous or undesired twigs, branches, or roots from; trim.
* to rid or clear of (anything superfluous or undesirable).

This seems adequate to me, since this action seems to allow the removal of superfluous payloads.

doc/1/controllers/device/clean/index.md Outdated Show resolved Hide resolved
## Arguments

- `days`: Specify on which period of time you want keep payloads (`default: 7`).
- `valid`: Specify if valid, invalid or both payload should be deleted (`default: true`).

Choose a reason for hiding this comment

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

How can we keep both valid and invalid payloads with a boolean option? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm it's a mistake, we can't

@Yoann-Abbes Yoann-Abbes requested a review from scottinet March 24, 2021 16:37
doc/1/controllers/device/prune-payloads/index.md Outdated Show resolved Hide resolved
features/DeviceController.feature Outdated Show resolved Hide resolved
## Arguments

- `days`: The maximum age of a payload, in days (`default: 7`).
- `valid`: Specify if valid or invalid payloads should be deleted (`default: true`).
Copy link

@scottinet scottinet Mar 26, 2021

Choose a reason for hiding this comment

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

Hm. This is unclear to me: if set to true, does that mean that valid payloads are removed, and invalid ones are kept? If so, then that's a weird choice of a default value.

Otherwise, we could also understand that if set to true, then valid payloads are kept, and invalid ones are removed. But then, the documentation is wrong (or at least misleading): this option sets the kind of payloads to keep, not the ones to be removed.

In any case, that sentence suggests that this option allows to choose which kind of payload to keep (on or the other), but I don't think that this is how it's supposed to work.

Also, what is an "invalid payload"? This might be explained somewhere else in this documentation, but it seems weird that we keep those if they are invalid 🤔

I have a proposal to make things clearer, but we might need to modify it depending on what's the definition of an "invalid payload":

Suggested change
- `valid`: Specify if valid or invalid payloads should be deleted (`default: true`).
- `consolidate`: if set to true, ensure that only still-valid payloads are kept (`default: true`).

Copy link
Contributor

@Aschen Aschen Mar 26, 2021

Choose a reason for hiding this comment

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

Invalid payload are the most interesting one because they are payload that couldn't be decoded properly by the associated decoder.
Developers can replay those payloads and try to understand how to decode them.
Maybe we can have an option keepInvalid so by default they are all deleted but we can choose to keep to invalid one for further analysis.

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 agree with @Aschen on this one
Wdyt @scottinet ?

Choose a reason for hiding this comment

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

I'm ok with that.

@Yoann-Abbes Yoann-Abbes requested a review from scottinet March 31, 2021 08:40
@Aschen Aschen changed the title Clean payloads collection API action Add API actions to prune payloads collection Apr 2, 2021
@Aschen Aschen merged commit 62ff5a8 into 1-dev Apr 2, 2021
@Aschen Aschen deleted the clean-payloads-api-actions branch April 2, 2021 12:38
@Yoann-Abbes Yoann-Abbes mentioned this pull request May 4, 2021
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.

Add API action to clean the payloads collection
4 participants