Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix update monitor from moniotr list #64

Merged
merged 1 commit into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions public/pages/Monitors/containers/Monitors/Monitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ export default class Monitors extends Component {

updateMonitor(item, update) {
const { httpClient } = this.props;
const { id, version, monitor } = item;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's call them seqNo and primaryTerm, the ifSeqNo/ifPrimaryTerm is just for the API query term. The actual values represent seqNo and primaryTerm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will fix it part of next PR. This is how currently it is being used rest of the place. Will change it together.

const { id, ifSeqNo, ifPrimaryTerm, monitor } = item;
return httpClient
.put(`../api/alerting/monitors/${id}?version=${version}`, { ...monitor, ...update })
.put(`../api/alerting/monitors/${id}?ifSeqNo=${ifSeqNo}&ifPrimaryTerm=${ifPrimaryTerm}`, {
...monitor,
...update,
})
.then(resp => resp)
.catch(err => err);
}
Expand Down
12 changes: 9 additions & 3 deletions public/pages/Monitors/containers/Monitors/Monitors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,25 @@ describe('Monitors', () => {
const monitor = alertingFakes.randomMonitor();
const response = await mountWrapper
.instance()
.updateMonitor({ id: 'random_id', version: 17, monitor }, { name: 'UNIQUE_NAME' });
.updateMonitor(
{ id: 'random_id', ifSeqNo: 17, ifPrimaryTerm: 20, monitor },
{ name: 'UNIQUE_NAME' }
);
mountWrapper.update();

expect(updateMonitor).toHaveBeenCalled();
expect(httpClientMock.put).toHaveBeenCalled();
expect(httpClientMock.put).toHaveBeenCalledWith(
`../api/alerting/monitors/random_id?version=17`,
`../api/alerting/monitors/random_id?ifSeqNo=17&ifPrimaryTerm=20`,
{ ...monitor, name: 'UNIQUE_NAME' }
);
expect(response).toEqual({ data: { ok: true } });
const error = await mountWrapper
.instance()
.updateMonitor({ id: 'random_id', version: 17, monitor }, { name: 'UNIQUE_NAME' });
.updateMonitor(
{ id: 'random_id', ifSeqNo: 17, ifPrimaryTerm: 20, monitor },
{ name: 'UNIQUE_NAME' }
);
expect(httpClientMock.put).toHaveBeenCalledTimes(2);
expect(error.message).toBe('random error');
});
Expand Down
5 changes: 3 additions & 2 deletions server/services/MonitorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export default class MonitorService {

const params = {
body: JSON.stringify({
seq_no_primary_term: true,
version: true,
...monitorSortPageData,
query: {
Expand All @@ -174,9 +175,9 @@ export default class MonitorService {

const totalMonitors = _.get(getResponse, 'hits.total.value', 0);
const monitorKeyValueTuples = _.get(getResponse, 'hits.hits', []).map(result => {
const { _id: id, _version: version, _source: monitor } = result;
const { _id: id, _version: version, _seq_no: ifSeqNo, _primary_term: ifPrimaryTerm, _source: monitor } = result;
const { name, enabled } = monitor;
return [id, { id, version, name, enabled, monitor }];
return [id, { id, version, ifSeqNo, ifPrimaryTerm, name, enabled, monitor }];
}, {});
const monitorMap = new Map(monitorKeyValueTuples);
const monitorIds = [...monitorMap.keys()];
Expand Down