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

Commit

Permalink
Fix update monitor from moniotr list (#64)
Browse files Browse the repository at this point in the history
Pass seqNo and PrimaryTerm for updateMonitor API.
  • Loading branch information
mihirsoni committed Jun 26, 2019
1 parent 691343c commit 666b070
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
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;
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

0 comments on commit 666b070

Please sign in to comment.