Skip to content

Commit

Permalink
Merge pull request #619 from swisspost/develop
Browse files Browse the repository at this point in the history
PR for Release
  • Loading branch information
mcweba authored Dec 9, 2024
2 parents db17c4c + 20aa5fe commit 99cc369
Show file tree
Hide file tree
Showing 49 changed files with 1,527 additions and 237 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.12-SNAPSHOT</version>
<version>2.1.13-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.12-SNAPSHOT</version>
<version>2.1.13-SNAPSHOT</version>
</parent>

<artifactId>gateleen-core</artifactId>
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.12-SNAPSHOT</version>
<version>2.1.13-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.12-SNAPSHOT</version>
<version>2.1.13-SNAPSHOT</version>
</parent>

<artifactId>gateleen-delta</artifactId>
Expand Down
26 changes: 25 additions & 1 deletion gateleen-expansion/README_expansion.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,28 @@ For more information about the StorageExpand feature see the [vertx-rest-storage
This allows you to create one octet-stream containing each json resource in the given collection (see expand feature).
Basically it works exactly the same way as the default expand feature works, except that it does not set an eTag for the request.

> <font color="orange">Attention: </font> No eTag header is created / returned when this feature is used!
> <font color="orange">Attention: </font> No eTag header is created / returned when this feature is used!
### Micrometer metrics
The expansion feature is monitored with micrometer. The following metrics are available:
* gateleen_expand_requests_total
* gateleen_storage_expand_requests_total

For `expand_requests_total` additional tags are provided to specify the expand level.

Example metrics:

```
# HELP gateleen_expand_requests_total
# TYPE gateleen_expand_requests_total counter
gateleen_expand_requests_total{level="1",} 23677.0
gateleen_expand_requests_total{level="2",} 2350.0
gateleen_expand_requests_total{level="3",} 77.0
gateleen_expand_requests_total{level="4",} 0.0
gateleen_expand_requests_total{level="0",} 0.0
# HELP gateleen_storage_expand_requests_total
# TYPE gateleen_storage_expand_requests_total counter
gateleen_storage_expand_requests_total 37.0
```

To enable the metrics, set a `MeterRegistry` instance by calling `setMeterRegistry(MeterRegistry meterRegistry)` method in `ExpansionHandler` class.
6 changes: 5 additions & 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.12-SNAPSHOT</version>
<version>2.1.13-SNAPSHOT</version>
</parent>

<artifactId>gateleen-expansion</artifactId>
Expand All @@ -22,6 +22,10 @@
<groupId>org.swisspush</groupId>
<artifactId>rest-storage</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>

<!-- TEST dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.swisspush.gateleen.expansion;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
Expand Down Expand Up @@ -27,10 +29,7 @@
import org.swisspush.gateleen.routing.RuleFeaturesProvider;
import org.swisspush.gateleen.routing.RuleProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

import static org.swisspush.gateleen.core.util.StatusCode.INTERNAL_SERVER_ERROR;
Expand Down Expand Up @@ -89,6 +88,10 @@ public class ExpansionHandler implements RuleChangesObserver {
private static final int DECREMENT_BY_ONE = 1;
private static final int MAX_RECURSION_LEVEL = 0;

private static final String EXPAND_REQUEST_METRIC = "gateleen.expand.requests";
private static final String STORAGE_EXPAND_REQUEST_METRIC = "gateleen.storage.expand.requests";
private static final String LEVEL = "level";

public static final String MAX_EXPANSION_LEVEL_SOFT_PROPERTY = "max.expansion.level.soft";
public static final String MAX_EXPANSION_LEVEL_HARD_PROPERTY = "max.expansion.level.hard";
public static final String MAX_SUBREQUEST_PROPERTY = "max.expansion.subrequests";
Expand Down Expand Up @@ -123,6 +126,9 @@ public class ExpansionHandler implements RuleChangesObserver {

private RuleFeaturesProvider ruleFeaturesProvider = new RuleFeaturesProvider(new ArrayList<>());

private final Map<Integer, Counter> counterMap = new HashMap<>();
private Counter storageExpandCounter;

/**
* Creates a new instance of the ExpansionHandler.
*
Expand Down Expand Up @@ -176,6 +182,26 @@ public int getMaxSubRequestCount() {
return maxSubRequestCount;
}

public void setMeterRegistry(MeterRegistry meterRegistry) {
counterMap.clear();
if(meterRegistry != null) {
counterMap.put(0, Counter.builder(EXPAND_REQUEST_METRIC).tag(LEVEL, "0").register(meterRegistry));
counterMap.put(1, Counter.builder(EXPAND_REQUEST_METRIC).tag(LEVEL, "1").register(meterRegistry));
counterMap.put(2, Counter.builder(EXPAND_REQUEST_METRIC).tag(LEVEL, "2").register(meterRegistry));
counterMap.put(3, Counter.builder(EXPAND_REQUEST_METRIC).tag(LEVEL, "3").register(meterRegistry));
counterMap.put(4, Counter.builder(EXPAND_REQUEST_METRIC).tag(LEVEL, "4").register(meterRegistry));

storageExpandCounter = Counter.builder(STORAGE_EXPAND_REQUEST_METRIC).register(meterRegistry);
}
}

private void incrementExpandReqCount(int level) {
Counter counter = counterMap.get(level);
if(counter != null) {
counter.increment();
}
}

/**
* Initialize the lists which defines, when which parameter
* is removed (if any).
Expand Down Expand Up @@ -363,6 +389,8 @@ private void handleExpansionRequest(final HttpServerRequest req, final Recursive
log.debug("constructed uri for request: {}", targetUri);

Integer finalExpandLevel = expandLevel;
incrementExpandReqCount(finalExpandLevel);

httpClient.request(HttpMethod.GET, targetUri).onComplete(asyncReqResult -> {
if (asyncReqResult.failed()) {
log.warn("Failed request to {}: {}", targetUri, asyncReqResult.cause());
Expand Down Expand Up @@ -505,6 +533,11 @@ private void makeStorageExpandRequest(final String targetUri, final List subReso
Logger log = RequestLoggerFactory.getLogger(ExpansionHandler.class, req);
HttpMethod reqMethod = HttpMethod.POST;
String reqUri = targetUri + "?storageExpand=true";

if(storageExpandCounter != null) {
storageExpandCounter.increment();
}

httpClient.request(reqMethod, reqUri).onComplete(asyncResult -> {
if (asyncResult.failed()) {
log.warn("Failed request to {}", reqUri, asyncResult.cause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class ExpansionHandlerTest {
public void setUp() {
vertx = Vertx.vertx();
httpClient = Mockito.mock(HttpClient.class);
// Mockito.when(httpClient.request(any(HttpMethod.class), anyString(), Matchers.<Handler<HttpClientResponse>>any())).thenReturn(Mockito.mock(HttpClientRequest.class));
storage = new MockResourceStorage();
}

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.12-SNAPSHOT</version>
<version>2.1.13-SNAPSHOT</version>
</parent>
<artifactId>gateleen-hook-js</artifactId>
<packaging>jar</packaging>
Expand Down
68 changes: 67 additions & 1 deletion gateleen-hook/README_hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ PUT http://myserver:7012/gateleen/everything/_hooks/listeners/http/myexample
"destination": "/gateleen/example/thePosition",
"filter": "/gateleen/everything/.*/position.*",
"headers": [
{ "header":"X-Expire-After", "value":"3600", mode:"complete"}
{ "header":"X-Expire-After", "value":"3600", "mode":"complete"}
],
"headersFilter": "x-foo: (A|B)"
}
Expand Down Expand Up @@ -240,10 +240,76 @@ hookHandler.enableResourceLogging(true);
```


## Query-Based Listener and Route Search

Gateleen allows searching for listeners and routes using the query parameter `q`. This simplifies filtering the registered hooks based on query parameters.

The search will be based on the value registered of the destination property

### Listener Search with `q`
Search for listeners based on a query parameter like this:

```
GET http://myserver:7012/playground/server/hooks/v1/registrations/listeners?q=mylistener
```

The response will contain the matching listeners. If no match is found, an empty list is returned:

**Example response with matches:**
```json
{
"listeners": [
"first+playground+server+test+nemo+origin+mylistener"
]
}
```

**Example response with no matches:**
```json
{
"listeners": []
}
```

### Route Search with `q`
Similarly, you can search for routes using a query parameter:

```
GET http://myserver:7012/playground/server/hooks/v1/registrations/routes/?q=myroute
```

The response contains the matching routes, or an empty list if no match is found.

**Example response with matches:**
```json
{
"routes": [
"first+playground+server+test+nemo+origin+myroute"
]
}

```
**Example response with no matches:**
```json
{
"routes": []
}
```

## Micrometer metrics
The hook feature is monitored with micrometer. The following metrics are available:
* gateleen_listener_count
* gateleen_routes_count

Example metrics:

```
# HELP gateleen_listener_count Amount of listener hooks currently registered
# TYPE gateleen_listener_count gauge
gateleen_listener_count 577.0
# HELP gateleen_routes_count Amount of route hooks currently registered
# TYPE gateleen_routes_count gauge
gateleen_routes_count 15.0
```

To enable the metrics, set a `MeterRegistry` instance by calling `setMeterRegistry(MeterRegistry meterRegistry)` method in `HookHandler` class.
6 changes: 5 additions & 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.12-SNAPSHOT</version>
<version>2.1.13-SNAPSHOT</version>
</parent>

<artifactId>gateleen-hook</artifactId>
Expand All @@ -17,6 +17,10 @@
<artifactId>gateleen-queue</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>

<!-- TEST dependencies -->
<dependency>
Expand Down
Loading

0 comments on commit 99cc369

Please sign in to comment.