Skip to content

Commit e316cc0

Browse files
cjcenizalsebelga
authored andcommitted
[CCR] Add endpoints for fetching and creating follower indices (#27646)
* Add GET /follower_indices endpoint with deserialization logic and tests. * Add POST /follower_indices endpoint with serialization logic and tests.
1 parent 43f769c commit e316cc0

File tree

9 files changed

+613
-4
lines changed

9 files changed

+613
-4
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
const Chance = require('chance'); // eslint-disable-line import/no-extraneous-dependencies
8+
const chance = new Chance();
9+
10+
export const getFollowerIndexMock = (
11+
name = chance.string(),
12+
shards = [{
13+
id: chance.string(),
14+
remoteCluster: chance.string(),
15+
leaderIndex: chance.string(),
16+
leaderGlobalCheckpoint: chance.integer(),
17+
leaderMaxSequenceNum: chance.integer(),
18+
followerGlobalCheckpoint: chance.integer(),
19+
followerMaxSequenceNum: chance.integer(),
20+
lastRequestedSequenceNum: chance.integer(),
21+
outstandingReadRequestsCount: chance.integer(),
22+
outstandingWriteRequestsCount: chance.integer(),
23+
writeBufferOperationsCount: chance.integer(),
24+
writeBufferSizeBytes: chance.integer(),
25+
followerMappingVersion: chance.integer(),
26+
followerSettingsVersion: chance.integer(),
27+
totalReadTimeMs: chance.integer(),
28+
totalReadRemoteExecTimeMs: chance.integer(),
29+
successfulReadRequestCount: chance.integer(),
30+
failedReadRequestsCount: chance.integer(),
31+
operationsReadCount: chance.integer(),
32+
bytesReadCount: chance.integer(),
33+
totalWriteTimeMs: chance.integer(),
34+
successfulWriteRequestsCount: chance.integer(),
35+
failedWriteRequestsCount: chance.integer(),
36+
operationsWrittenCount: chance.integer(),
37+
readExceptions: [ chance.string() ],
38+
timeSinceLastReadMs: chance.integer(),
39+
}]
40+
) => {
41+
const serializeShard = ({
42+
id,
43+
remoteCluster,
44+
leaderIndex,
45+
leaderGlobalCheckpoint,
46+
leaderMaxSequenceNum,
47+
followerGlobalCheckpoint,
48+
followerMaxSequenceNum,
49+
lastRequestedSequenceNum,
50+
outstandingReadRequestsCount,
51+
outstandingWriteRequestsCount,
52+
writeBufferOperationsCount,
53+
writeBufferSizeBytes,
54+
followerMappingVersion,
55+
followerSettingsVersion,
56+
totalReadTimeMs,
57+
totalReadRemoteExecTimeMs,
58+
successfulReadRequestCount,
59+
failedReadRequestsCount,
60+
operationsReadCount,
61+
bytesReadCount,
62+
totalWriteTimeMs,
63+
successfulWriteRequestsCount,
64+
failedWriteRequestsCount,
65+
operationsWrittenCount,
66+
readExceptions,
67+
timeSinceLastReadMs,
68+
}) => ({
69+
shard_id: id,
70+
remote_cluster: remoteCluster,
71+
leader_index: leaderIndex,
72+
leader_global_checkpoint: leaderGlobalCheckpoint,
73+
leader_max_seq_no: leaderMaxSequenceNum,
74+
follower_global_checkpoint: followerGlobalCheckpoint,
75+
follower_max_seq_no: followerMaxSequenceNum,
76+
last_requested_seq_no: lastRequestedSequenceNum,
77+
outstanding_read_requests: outstandingReadRequestsCount,
78+
outstanding_write_requests: outstandingWriteRequestsCount,
79+
write_buffer_operation_count: writeBufferOperationsCount,
80+
write_buffer_size_in_bytes: writeBufferSizeBytes,
81+
follower_mapping_version: followerMappingVersion,
82+
follower_settings_version: followerSettingsVersion,
83+
total_read_time_millis: totalReadTimeMs,
84+
total_read_remote_exec_time_millis: totalReadRemoteExecTimeMs,
85+
successful_read_requests: successfulReadRequestCount,
86+
failed_read_requests: failedReadRequestsCount,
87+
operations_read: operationsReadCount,
88+
bytes_read: bytesReadCount,
89+
total_write_time_millis: totalWriteTimeMs,
90+
successful_write_requests: successfulWriteRequestsCount,
91+
failed_write_requests: failedWriteRequestsCount,
92+
operations_written: operationsWrittenCount,
93+
read_exceptions: readExceptions,
94+
time_since_last_read_millis: timeSinceLastReadMs,
95+
});
96+
97+
return {
98+
index: name,
99+
shards: shards.map(serializeShard),
100+
};
101+
};
102+
103+
export const getFollowerIndexListMock = (total = 3) => {
104+
const list = {
105+
follow_stats: {
106+
indices: [],
107+
},
108+
};
109+
110+
let i = total;
111+
while(i--) {
112+
list.follow_stats.indices.push(getFollowerIndexMock());
113+
}
114+
115+
return list;
116+
};

x-pack/plugins/cross_cluster_replication/fixtures/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ export {
1010
} from './auto_follow_pattern';
1111

1212
export { esErrors } from './es_errors';
13+
14+
export {
15+
getFollowerIndexMock,
16+
getFollowerIndexListMock,
17+
} from './follower_index';

x-pack/plugins/cross_cluster_replication/server/client/elasticsearch_ccr.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,28 @@ export const elasticsearchJsPlugin = (Client, config, components) => {
6262
needBody: true,
6363
method: 'DELETE'
6464
});
65+
66+
ccr.followerIndices = ca({
67+
urls: [
68+
{
69+
fmt: '/_ccr/stats',
70+
}
71+
],
72+
method: 'GET'
73+
});
74+
75+
ccr.saveFollowerIndex = ca({
76+
urls: [
77+
{
78+
fmt: '/<%=name%>/_ccr/follow',
79+
req: {
80+
name: {
81+
type: 'string'
82+
}
83+
}
84+
}
85+
],
86+
needBody: true,
87+
method: 'PUT'
88+
});
6589
};
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
/* eslint-disable camelcase */
8+
export const deserializeShard = ({
9+
remote_cluster,
10+
leader_index,
11+
shard_id,
12+
leader_global_checkpoint,
13+
leader_max_seq_no,
14+
follower_global_checkpoint,
15+
follower_max_seq_no,
16+
last_requested_seq_no,
17+
outstanding_read_requests,
18+
outstanding_write_requests,
19+
write_buffer_operation_count,
20+
write_buffer_size_in_bytes,
21+
follower_mapping_version,
22+
follower_settings_version,
23+
total_read_time_millis,
24+
total_read_remote_exec_time_millis,
25+
successful_read_requests,
26+
failed_read_requests,
27+
operations_read,
28+
bytes_read,
29+
total_write_time_millis,
30+
successful_write_requests,
31+
failed_write_requests,
32+
operations_written,
33+
read_exceptions,
34+
time_since_last_read_millis,
35+
}) => ({
36+
id: shard_id,
37+
remoteCluster: remote_cluster,
38+
leaderIndex: leader_index,
39+
leaderGlobalCheckpoint: leader_global_checkpoint,
40+
leaderMaxSequenceNum: leader_max_seq_no,
41+
followerGlobalCheckpoint: follower_global_checkpoint,
42+
followerMaxSequenceNum: follower_max_seq_no,
43+
lastRequestedSequenceNum: last_requested_seq_no,
44+
outstandingReadRequestsCount: outstanding_read_requests,
45+
outstandingWriteRequestsCount: outstanding_write_requests,
46+
writeBufferOperationsCount: write_buffer_operation_count,
47+
writeBufferSizeBytes: write_buffer_size_in_bytes,
48+
followerMappingVersion: follower_mapping_version,
49+
followerSettingsVersion: follower_settings_version,
50+
totalReadTimeMs: total_read_time_millis,
51+
totalReadRemoteExecTimeMs: total_read_remote_exec_time_millis,
52+
successfulReadRequestCount: successful_read_requests,
53+
failedReadRequestsCount: failed_read_requests,
54+
operationsReadCount: operations_read,
55+
bytesReadCount: bytes_read,
56+
totalWriteTimeMs: total_write_time_millis,
57+
successfulWriteRequestsCount: successful_write_requests,
58+
failedWriteRequestsCount: failed_write_requests,
59+
operationsWrittenCount: operations_written,
60+
// This is an array of exception objects
61+
readExceptions: read_exceptions,
62+
timeSinceLastReadMs: time_since_last_read_millis,
63+
});
64+
/* eslint-enable camelcase */
65+
66+
export const deserializeFollowerIndex = ({ index, shards }) => ({
67+
name: index,
68+
shards: shards.map(deserializeShard),
69+
});
70+
71+
export const deserializeListFollowerIndices = followerIndices =>
72+
followerIndices.map(deserializeFollowerIndex);
73+
74+
export const serializeFollowerIndex = ({ remoteCluster, leaderIndex }) => ({
75+
remote_cluster: remoteCluster,
76+
leader_index: leaderIndex,
77+
});

0 commit comments

Comments
 (0)