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

[CCR] Add endpoints for fetching and creating follower indices #27646

Merged
merged 3 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
116 changes: 116 additions & 0 deletions x-pack/plugins/cross_cluster_replication/fixtures/follower_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

const Chance = require('chance'); // eslint-disable-line import/no-extraneous-dependencies
const chance = new Chance();

export const getFollowerIndexMock = (
name = chance.string(),
shards = [{
id: chance.string(),
remoteCluster: chance.string(),
leaderIndex: chance.string(),
leaderGlobalCheckpoint: chance.integer(),
leaderMaxSequenceNum: chance.integer(),
followerGlobalCheckpoint: chance.integer(),
followerMaxSequenceNum: chance.integer(),
lastRequestedSequenceNum: chance.integer(),
outstandingReadRequestsCount: chance.integer(),
outstandingWriteRequestsCount: chance.integer(),
writeBufferOperationsCount: chance.integer(),
writeBufferSizeBytes: chance.integer(),
followerMappingVersion: chance.integer(),
followerSettingsVersion: chance.integer(),
totalReadTimeMs: chance.integer(),
totalReadRemoteExecTimeMs: chance.integer(),
successfulReadRequestCount: chance.integer(),
failedReadRequestsCount: chance.integer(),
operationsReadCount: chance.integer(),
bytesReadCount: chance.integer(),
totalWriteTimeMs: chance.integer(),
successfulWriteRequestsCount: chance.integer(),
failedWriteRequestsCount: chance.integer(),
operationsWrittenCount: chance.integer(),
readExceptions: [ chance.string() ],
timeSinceLastReadMs: chance.integer(),
}]
) => {
const serializeShard = ({
id,
remoteCluster,
leaderIndex,
leaderGlobalCheckpoint,
leaderMaxSequenceNum,
followerGlobalCheckpoint,
followerMaxSequenceNum,
lastRequestedSequenceNum,
outstandingReadRequestsCount,
outstandingWriteRequestsCount,
writeBufferOperationsCount,
writeBufferSizeBytes,
followerMappingVersion,
followerSettingsVersion,
totalReadTimeMs,
totalReadRemoteExecTimeMs,
successfulReadRequestCount,
failedReadRequestsCount,
operationsReadCount,
bytesReadCount,
totalWriteTimeMs,
successfulWriteRequestsCount,
failedWriteRequestsCount,
operationsWrittenCount,
readExceptions,
timeSinceLastReadMs,
}) => ({
shard_id: id,
remote_cluster: remoteCluster,
leader_index: leaderIndex,
leader_global_checkpoint: leaderGlobalCheckpoint,
leader_max_seq_no: leaderMaxSequenceNum,
follower_global_checkpoint: followerGlobalCheckpoint,
follower_max_seq_no: followerMaxSequenceNum,
last_requested_seq_no: lastRequestedSequenceNum,
outstanding_read_requests: outstandingReadRequestsCount,
outstanding_write_requests: outstandingWriteRequestsCount,
write_buffer_operation_count: writeBufferOperationsCount,
write_buffer_size_in_bytes: writeBufferSizeBytes,
follower_mapping_version: followerMappingVersion,
follower_settings_version: followerSettingsVersion,
total_read_time_millis: totalReadTimeMs,
total_read_remote_exec_time_millis: totalReadRemoteExecTimeMs,
successful_read_requests: successfulReadRequestCount,
failed_read_requests: failedReadRequestsCount,
operations_read: operationsReadCount,
bytes_read: bytesReadCount,
total_write_time_millis: totalWriteTimeMs,
successful_write_requests: successfulWriteRequestsCount,
failed_write_requests: failedWriteRequestsCount,
operations_written: operationsWrittenCount,
read_exceptions: readExceptions,
time_since_last_read_millis: timeSinceLastReadMs,
});

return {
index: name,
shards: shards.map(serializeShard),
};
};

export const getFollowerIndexListMock = (total = 3) => {
const list = {
follow_stats: {
indices: [],
},
};

let i = total;
while(i--) {
list.follow_stats.indices.push(getFollowerIndexMock());
}

return list;
};
5 changes: 5 additions & 0 deletions x-pack/plugins/cross_cluster_replication/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ export {
} from './auto_follow_pattern';

export { esErrors } from './es_errors';

export {
getFollowerIndexMock,
getFollowerIndexListMock,
} from './follower_index';
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,28 @@ export const elasticsearchJsPlugin = (Client, config, components) => {
needBody: true,
method: 'DELETE'
});

ccr.followerIndices = ca({
Copy link
Contributor

Choose a reason for hiding this comment

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

For the bug I am currently working on, I have implemented the /_ccr/stats API call as part of a generic ccr.stats client as we might need it for several server APIs. Let's leave it here for now but we will need to remove it once I merge it. (Note for myself)

urls: [
{
fmt: '/_ccr/stats',
}
],
method: 'GET'
});

ccr.saveFollowerIndex = ca({
urls: [
{
fmt: '/<%=name%>/_ccr/follow',
req: {
name: {
type: 'string'
}
}
}
],
needBody: true,
method: 'PUT'
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/* eslint-disable camelcase */
export const deserializeShard = ({
remote_cluster,
leader_index,
shard_id,
leader_global_checkpoint,
leader_max_seq_no,
follower_global_checkpoint,
follower_max_seq_no,
last_requested_seq_no,
outstanding_read_requests,
outstanding_write_requests,
write_buffer_operation_count,
write_buffer_size_in_bytes,
follower_mapping_version,
follower_settings_version,
total_read_time_millis,
total_read_remote_exec_time_millis,
successful_read_requests,
failed_read_requests,
operations_read,
bytes_read,
total_write_time_millis,
successful_write_requests,
failed_write_requests,
operations_written,
read_exceptions,
time_since_last_read_millis,
}) => ({
id: shard_id,
remoteCluster: remote_cluster,
leaderIndex: leader_index,
leaderGlobalCheckpoint: leader_global_checkpoint,
leaderMaxSequenceNum: leader_max_seq_no,
followerGlobalCheckpoint: follower_global_checkpoint,
followerMaxSequenceNum: follower_max_seq_no,
lastRequestedSequenceNum: last_requested_seq_no,
outstandingReadRequestsCount: outstanding_read_requests,
outstandingWriteRequestsCount: outstanding_write_requests,
writeBufferOperationsCount: write_buffer_operation_count,
writeBufferSizeBytes: write_buffer_size_in_bytes,
followerMappingVersion: follower_mapping_version,
followerSettingsVersion: follower_settings_version,
totalReadTimeMs: total_read_time_millis,
totalReadRemoteExecTimeMs: total_read_remote_exec_time_millis,
successfulReadRequestCount: successful_read_requests,
failedReadRequestsCount: failed_read_requests,
operationsReadCount: operations_read,
bytesReadCount: bytes_read,
totalWriteTimeMs: total_write_time_millis,
successfulWriteRequestsCount: successful_write_requests,
failedWriteRequestsCount: failed_write_requests,
operationsWrittenCount: operations_written,
// This is an array of exception objects
readExceptions: read_exceptions,
timeSinceLastReadMs: time_since_last_read_millis,
});
/* eslint-enable camelcase */

export const deserializeFollowerIndex = ({ index, shards }) => ({
name: index,
shards: shards.map(deserializeShard),
});

export const deserializeListFollowerIndices = followerIndices =>
followerIndices.map(deserializeFollowerIndex);

export const serializeFollowerIndex = ({ remoteCluster, leaderIndex }) => ({
remote_cluster: remoteCluster,
leader_index: leaderIndex,
});
Loading