|
| 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 | +}; |
0 commit comments