Skip to content

Commit 701e6a5

Browse files
author
Chris Wiechmann
committed
Fixing an issue in Index-Rollover - Indices are rolled over too often
1 parent b718cd3 commit 701e6a5

4 files changed

Lines changed: 45 additions & 9 deletions

File tree

api-builder-plugin-fn-elasticsearch/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.0.19] 2021-02-03
8+
### Fixed
9+
- Index-Rollup method was rolling over indices too often depending on the number of existing indices
10+
711
## [1.0.18] 2021-01-11
812
### Fixed
913
- The API-Builder process will no longer die, if Elasticsearch is not available for search request

api-builder-plugin-fn-elasticsearch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@axway-api-builder-ext/api-builder-plugin-fn-elasticsearch",
3-
"version": "1.0.18",
3+
"version": "1.0.19",
44
"description": "Integrate Elasticsearch into your API-Builder flow to combine search data for instance with other data available in your flow.",
55
"author": "Chris Wiechmann <cwiechmann@axway.com> (http://www.axway.com)",
66
"license": "Apache-2.0",

api-builder-plugin-fn-elasticsearch/src/actions/indices.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,40 @@ async function indicesRollover(params, options) {
3333
} else {
3434
aliasesToRollover.push(alias);
3535
}
36-
// Is the given alias is a wildcard, search for other indicies starting with this alias
36+
/* Is the given alias is a wildcard (e.g. apigw-traffic-summary-*), search for other aliases starting with this alias
37+
* This the result we may get
38+
* alias index filter routing.index routing.search is_write_index
39+
* apigw-trace-messages-us apigw-trace-messages-us-000002 - - - true
40+
* apigw-trace-messages-us apigw-trace-messages-us-000001 - - - false
41+
* apigw-trace-messages-eu apigw-trace-messages-us-000001 - - - false
42+
* apigw-trace-messages-eu apigw-trace-messages-us-000002 - - - false
43+
* apigw-trace-messages-eu apigw-trace-messages-us-000003 - - - true
44+
*
45+
* For each found alias it must be rolled once, hence it must be the write index
46+
*/
3747
if(wildcardAlias) {
3848
aliasesToRollover = [];
3949
logger.debug(`Rolling over all indicies starting with alias: ${alias}`);
40-
var indicesFound = await client.indices.getAlias({name: `${alias}*`}, { ignore: [404], maxRetries: 3 });
41-
for (const index of Object.values(indicesFound.body)) {
42-
var indexAlias = Object.keys(index.aliases)[0];
43-
aliasesToRollover.push(indexAlias);
44-
}
50+
var foundAliases = await client.indices.getAlias({name: `${alias}*`}, { ignore: [404], maxRetries: 3 });
51+
// Based on the alias name we get all indicies
52+
for (const [key, value] of Object.entries(foundAliases.body)) {
53+
for (const [aliasName, aliasSettings] of Object.entries(value.aliases)) {
54+
// Each can have only one write index, which we use to perform the rollover
55+
if(aliasSettings.is_write_index) {
56+
logger.debug(`Adding is write alias: ${aliasName} to the list of aliases to rollover`);
57+
aliasesToRollover.push(aliasName);
58+
break;
59+
}
60+
}
61+
}
4562
}
4663
if(aliasesToRollover.length == 0) {
4764
throw new Error(`No index found to rollover for alias: ${JSON.stringify(alias)}`);
4865
}
4966
try {
5067
var result = [];
5168
for(alias of aliasesToRollover) {
69+
logger.debug(`Rolling over index: ${alias}`);
5270
var rolloverResult = await client.indices.rollover( { alias: alias }, { ignore: [404], maxRetries: 3 });
5371
result.push(rolloverResult);
5472
}

api-builder-plugin-fn-elasticsearch/test/mock/indices/twoIndicesForAliasFoundResponse.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@
33
"apigw-traffic-summary-000002": {
44
"aliases": {
55
"apigw-traffic-summary": {
6-
6+
"is_write_index": true
7+
}
8+
}
9+
},
10+
"apigw-traffic-summary-000001": {
11+
"aliases": {
12+
"apigw-traffic-summary": {
13+
"is_write_index": false
714
}
815
}
916
},
1017
"apigw-traffic-summary-us-dc1-000001": {
1118
"aliases": {
1219
"apigw-traffic-summary-us-dc1": {
13-
20+
"is_write_index": false
21+
}
22+
}
23+
},
24+
"apigw-traffic-summary-us-dc1-000002": {
25+
"aliases": {
26+
"apigw-traffic-summary-us-dc1": {
27+
"is_write_index": true
1428
}
1529
}
1630
}

0 commit comments

Comments
 (0)