Skip to content

Commit

Permalink
Merge pull request #624 from swisspost/develop
Browse files Browse the repository at this point in the history
PR for release
  • Loading branch information
mcweba authored Jan 6, 2025
2 parents 99cc369 + dc6591d commit 9bc4263
Show file tree
Hide file tree
Showing 43 changed files with 747 additions and 129 deletions.
2 changes: 1 addition & 1 deletion gateleen-cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-cache</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ public void releaseLock(Lock lockImpl, String lock, String token, Logger log){
}
});
}

/**
* Calculate the lock expiry time. This is a simple helper to work with the lock expiry time.
*
* @param taskInterval the interval of the task
* @return the calculated lock expiry time
*/
public static long calcLockExpiry(long taskInterval) {
return taskInterval <= 1 ? 1 : taskInterval / 2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ public void setUp(){
lockUtil = new LockUtil(newGateleenWastefulExceptionFactory());
}

@Test
public void testCalculateLockExpiry(TestContext context) {
context.assertEquals(1L, LockUtil.calcLockExpiry(1));
context.assertEquals(1L, LockUtil.calcLockExpiry(0));
context.assertEquals(1L, LockUtil.calcLockExpiry(-20));
context.assertEquals(1L, LockUtil.calcLockExpiry(2));
context.assertEquals(1L, LockUtil.calcLockExpiry(3));
context.assertEquals(2L, LockUtil.calcLockExpiry(4));
context.assertEquals(4L, LockUtil.calcLockExpiry(8));
context.assertEquals(32L, LockUtil.calcLockExpiry(64));
context.assertEquals(750L, LockUtil.calcLockExpiry(1500));
context.assertEquals(5000L, LockUtil.calcLockExpiry(10001));
}

@Test
public void testAcquireLockWithoutLockImplementationDefined(TestContext context) {
Async async = context.async();
Expand Down
2 changes: 1 addition & 1 deletion gateleen-delegate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-delegate</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-delta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-delta</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-expansion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-expansion</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-hook-js/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>
<artifactId>gateleen-hook-js</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-hook/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-hook</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-kafka</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-logging</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-merge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-merge</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-monitoring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-monitoring</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-packing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-packing</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-player/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-player</artifactId>
Expand Down
17 changes: 16 additions & 1 deletion gateleen-playground/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-playground</artifactId>
Expand Down Expand Up @@ -103,6 +103,21 @@
<artifactId>gateleen-kafka</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-micrometer-metrics</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>org.swisspush</groupId>
<artifactId>redisques</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-qos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-qos</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions gateleen-queue/README_queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ The result will be a json object with the circuit information like the example b
"status": "closed",
"info": {
"failRatio": 15,
"metric": "server-tests",
"circuit": "/playground/server/tests/(.*)"
}
}
Expand All @@ -323,6 +324,7 @@ The result will be a json object with the information of all circuits like the e
"myCircuitHash": {
"infos": {
"failRatio": 15,
"metric": "server-tests",
"circuit": "/playground/server/tests/(.*)"
},
"status": "closed"
Expand Down
2 changes: 1 addition & 1 deletion gateleen-queue/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>2.1.13-SNAPSHOT</version>
<version>2.1.14-SNAPSHOT</version>
</parent>

<artifactId>gateleen-queue</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private void handleGetCircuitStatus(Message<JsonObject> message) {

private void handleCloseCircuit(Message<JsonObject> message) {
String circuitHash = message.body().getJsonObject(PAYLOAD).getString(CIRCUIT_HASH);
PatternAndCircuitHash patternAndCircuitHash = new PatternAndCircuitHash(null, circuitHash);
PatternAndCircuitHash patternAndCircuitHash = new PatternAndCircuitHash(null, circuitHash, null);
storage.closeCircuit(patternAndCircuitHash).onComplete(event -> {
if (event.failed()) {
message.reply(new JsonObject().put(STATUS, ERROR).put(MESSAGE, event.cause().getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public Future<Long> unlockSampleQueues() {
failedFutures.add(event1.cause().getMessage());
}
if (futureCounter.get() == 0) {
if (failedFutures.size() > 0) {
if (!failedFutures.isEmpty()) {
promise.fail("The following queues could not be unlocked: " + failedFutures);
} else {
promise.complete((long) queuesToUnlock.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.swisspush.gateleen.queue.queuing.circuitbreaker.impl;

import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
Expand Down Expand Up @@ -38,8 +37,10 @@ public class RedisQueueCircuitBreakerStorage implements QueueCircuitBreakerStora
public static final String STORAGE_OPEN_CIRCUITS = STORAGE_PREFIX + "open-circuits";
public static final String STORAGE_QUEUES_TO_UNLOCK = STORAGE_PREFIX + "queues-to-unlock";
public static final String FIELD_STATE = "state";
public static final String FIELD_STATUS = "status";
public static final String FIELD_FAILRATIO = "failRatio";
public static final String FIELD_CIRCUIT = "circuit";
public static final String FIELD_METRICNAME = "metricName";

private final LuaScriptState openCircuitLuaScriptState;
private final LuaScriptState closeCircuitLuaScriptState;
Expand Down Expand Up @@ -99,7 +100,7 @@ public Future<QueueCircuitState> getQueueCircuitState(String circuitHash) {
public Future<JsonObject> getQueueCircuitInformation(String circuitHash) {
Promise<JsonObject> promise = Promise.promise();
redisProvider.redis().onSuccess(redisAPI -> redisAPI.hmget(Arrays.asList(buildInfosKey(circuitHash), FIELD_STATE,
FIELD_FAILRATIO, FIELD_CIRCUIT), event -> {
FIELD_FAILRATIO, FIELD_CIRCUIT, FIELD_METRICNAME), event -> {
if (event.failed()) {
promise.fail(event.cause());
} else {
Expand All @@ -108,15 +109,19 @@ public Future<JsonObject> getQueueCircuitInformation(String circuitHash) {
QueueCircuitState.CLOSED);
String failRatioStr = Objects.toString(event.result().get(1), null);
String circuit = Objects.toString(event.result().get(2), null);
String metric = Objects.toString(event.result().get(3), null);
JsonObject result = new JsonObject();
result.put("status", state.name().toLowerCase());
result.put(FIELD_STATUS, state.name().toLowerCase());
JsonObject info = new JsonObject();
if (failRatioStr != null) {
info.put(FIELD_FAILRATIO, Integer.valueOf(failRatioStr));
}
if (circuit != null) {
info.put(FIELD_CIRCUIT, circuit);
}
if (StringUtils.isNotEmptyTrimmed(metric)) {
info.put(FIELD_METRICNAME, metric);
}
result.put("info", info);
promise.complete(result);
} catch (Exception e) {
Expand Down Expand Up @@ -156,6 +161,7 @@ public Future<UpdateStatisticsResult> updateStatistics(PatternAndCircuitHash pat
List<String> arguments = Arrays.asList(
uniqueRequestID,
patternAndCircuitHash.getPattern().pattern(),
patternAndCircuitHash.getMetricName() != null ? patternAndCircuitHash.getMetricName() : "",
patternAndCircuitHash.getCircuitHash(),
String.valueOf(timestamp),
String.valueOf(errorThresholdPercentage),
Expand Down Expand Up @@ -240,7 +246,7 @@ public Future<Void> closeAllCircuits() {
Future<Void> closeOpenCircuitsFuture = closeCircuitsByKey(STORAGE_OPEN_CIRCUITS);
Future<Void> closeHalfOpenCircuitsFuture = closeCircuitsByKey(STORAGE_HALFOPEN_CIRCUITS);

CompositeFuture.all(closeOpenCircuitsFuture, closeHalfOpenCircuitsFuture).onComplete(event -> {
Future.all(closeOpenCircuitsFuture, closeHalfOpenCircuitsFuture).onComplete(event -> {
if (event.succeeded()) {
promise.complete();
} else {
Expand All @@ -255,14 +261,14 @@ private Future<Void> closeCircuitsByKey(String key) {
Promise<Void> promise = Promise.promise();
redisProvider.redis().onSuccess(redisAPI -> redisAPI.smembers(key, event -> {
if (event.succeeded()) {
List<Future> promises = new ArrayList<>();
List<Future<Void>> promises = new ArrayList<>();
for (Response circuit : event.result()) {
promises.add(closeCircuit(circuit.toString(), false));
}
if (promises.size() == 0) {
if (promises.isEmpty()) {
promise.complete();
} else {
CompositeFuture.all(promises).onComplete(event1 -> {
Future.all(promises).onComplete(event1 -> {
if (event1.succeeded()) {
promise.complete();
} else {
Expand Down
Loading

0 comments on commit 9bc4263

Please sign in to comment.