From fb275fec37dd55f6e9a95aead128a07bbd705823 Mon Sep 17 00:00:00 2001 From: Marc-Andre Weber Date: Wed, 25 Jan 2023 12:58:00 +0100 Subject: [PATCH] Removed duplication of request header holding the unique request id. --- README.md | 50 +++++++++---------- .../core/http/RequestLoggerFactory.java | 3 -- .../core/logging/RequestLoggerTest.java | 8 +-- gateleen-logging/README_logging.md | 2 +- .../impl/QueueCircuitBreakerImpl.java | 3 -- .../swisspush/gateleen/routing/Forwarder.java | 3 -- .../gateleen/routing/StorageForwarder.java | 17 ------- .../gateleen/runconfig/RunConfig.java | 6 --- 8 files changed, 30 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index aac0bb585..70818388d 100755 --- a/README.md +++ b/README.md @@ -114,32 +114,32 @@ mvn install -PnonUiIntegrationTests ## Headers This is a list of the custom headers used by Gateleen. -| Header | Description | Link to documentation | -|:-------------------- | :--------------------------------------- | :---------------------:| -| x-rp-unique-id | unique id | | -| x-request-id | id of the request (unique?) | | -| x-self-request | indicates if the request is triggered by a communication server and the target is the communication server itself | | -| x-rp-grp | group header | [gateleen-user](gateleen-user/README_user.md) | -| x-roles | role header | | -| x-delta | used by the delta parameter to mark a delta request | [gateleen-delta](gateleen-delta/README_delta.md) | -| x-delta-backend | used by the delta parameter as a marker header to know that we should let the request continue to the router | [gateleen-delta](gateleen-delta/README_delta.md) | -| x-expire-After | indicates how long (in seconds) a request is 'valid' before it expires | | -| x-hooked | used by the HookHandler to indicate the original hook request as hooked | [gateleen-hook](gateleen-hook/README_hook.md) | -| x-pack-size | indicates if a request is packed | [gateleen-packing](gateleen-packing/README_packing.md) | -| x-client-timestamp | timestamp of the client while sending the request | | -| x-server-timestamp | timestamp of the server while sending the request | | -| x-queue | indicates a queued request | [gateleen-queue](gateleen-queue/README_queue.md) | -| x-duplicate-check | indicates if a request is a duplicate or not | | +| Header | Description | Link to documentation | +|:---------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| :---------------------:| +| x-rp-unique_id | unique id of the request. Normally provided by a proxy server | | +| x-request-id | unique id of the request when no x-rp-unique_id request header was provided | | +| x-self-request | indicates if the request is triggered by a communication server and the target is the communication server itself | | +| x-rp-grp | group header | [gateleen-user](gateleen-user/README_user.md) | +| x-roles | role header | | +| x-delta | used by the delta parameter to mark a delta request | [gateleen-delta](gateleen-delta/README_delta.md) | +| x-delta-backend | used by the delta parameter as a marker header to know that we should let the request continue to the router | [gateleen-delta](gateleen-delta/README_delta.md) | +| x-expire-After | indicates how long (in seconds) a request is 'valid' before it expires | | +| x-hooked | used by the HookHandler to indicate the original hook request as hooked | [gateleen-hook](gateleen-hook/README_hook.md) | +| x-pack-size | indicates if a request is packed | [gateleen-packing](gateleen-packing/README_packing.md) | +| x-client-timestamp | timestamp of the client while sending the request | | +| x-server-timestamp | timestamp of the server while sending the request | | +| x-queue | indicates a queued request | [gateleen-queue](gateleen-queue/README_queue.md) | +| x-duplicate-check | indicates if a request is a duplicate or not | | | x-on-behalf-of | indicates the user the request originally was made from. This header is used when the request of a user is sent by another user because it couldn't be sent at that time (offline) | | -| x-user-\ | used for the user profile | | -| x-rp-deviceid | used to check if device is authorized | | -| x-rp-usr | used to check if user is authorized | [gateleen-user](gateleen-user/README_user.md) | -| x-rp-lang | used to specify the language of the user profile | [gateleen-user](gateleen-user/README_user.md) | -| x-valid | indicates if a request is to be validated or not | [gateleen-validation](gateleen-validation/README_validation.md) | -| x-sync | | | -| x-log | | | -| x-service | contains the name of the service, which created the request | | -| x-queue-expire-after | indicates how long (in seconds) a request is 'valid' in the queue before it expires | | +| x-user-\ | used for the user profile | | +| x-rp-deviceid | used to check if device is authorized | | +| x-rp-usr | used to check if user is authorized | [gateleen-user](gateleen-user/README_user.md) | +| x-rp-lang | used to specify the language of the user profile | [gateleen-user](gateleen-user/README_user.md) | +| x-valid | indicates if a request is to be validated or not | [gateleen-validation](gateleen-validation/README_validation.md) | +| x-sync | | | +| x-log | | | +| x-service | contains the name of the service, which created the request | | +| x-queue-expire-after | indicates how long (in seconds) a request is 'valid' in the queue before it expires | | ## Performance Tuning * The amount of max open files per process should be at least 16384. You can check your max open files per process with this command `cat /proc//limits`. diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/RequestLoggerFactory.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/RequestLoggerFactory.java index a18e572f3..bd491c44c 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/RequestLoggerFactory.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/RequestLoggerFactory.java @@ -29,9 +29,6 @@ public static Logger getLogger(Class clazz, MultiMap headers) { uid = rid; } rid = headers.get("x-rp-unique_id"); - if (rid == null) { - rid = headers.get("x-rp-unique-id"); - } if (rid != null) { if (uid != null) { uid = uid + " " + rid; diff --git a/gateleen-core/src/test/java/org/swisspush/gateleen/core/logging/RequestLoggerTest.java b/gateleen-core/src/test/java/org/swisspush/gateleen/core/logging/RequestLoggerTest.java index 5152b2cf5..8b668f0e5 100644 --- a/gateleen-core/src/test/java/org/swisspush/gateleen/core/logging/RequestLoggerTest.java +++ b/gateleen-core/src/test/java/org/swisspush/gateleen/core/logging/RequestLoggerTest.java @@ -37,7 +37,7 @@ public void testLogRequest(TestContext context){ EventBus eventBus = Mockito.mock(EventBus .class); MultiMap headers = MultiMap.caseInsensitiveMultiMap(); headers.add("Content-Type", "application/json"); - headers.add("x-rp-unique-id", "123456"); + headers.add("x-rp-unique_id", "123456"); MockedResponse response = new MockedResponse(MultiMap.caseInsensitiveMultiMap()); MockedRequest request = new MockedRequest("/uri/to/a/resource", HttpMethod.PUT, headers, response); JsonObject body = new JsonObject().put("key_1", "value_2").put("key_2", 99); @@ -47,7 +47,7 @@ public void testLogRequest(TestContext context){ JsonObject expected = new JsonObject(); expected.put(REQUEST_URI, "/uri/to/a/resource"); expected.put(REQUEST_METHOD, "PUT"); - JsonObject requestHeaders = new JsonObject().put("Content-Type", "application/json").put("x-rp-unique-id", "123456"); + JsonObject requestHeaders = new JsonObject().put("Content-Type", "application/json").put("x-rp-unique_id", "123456"); expected.put(REQUEST_HEADERS, requestHeaders); expected.put(RESPONSE_HEADERS, new JsonObject()); expected.put(REQUEST_STATUS, StatusCode.OK.getStatusCode()); @@ -62,7 +62,7 @@ public void testLogRequestResponseHeaders(TestContext context){ EventBus eventBus = Mockito.mock(EventBus .class); MultiMap headers = MultiMap.caseInsensitiveMultiMap(); headers.add("Content-Type", "application/json"); - headers.add("x-rp-unique-id", "123456"); + headers.add("x-rp-unique_id", "123456"); MockedRequest request = new MockedRequest("/uri/to/a/resource", HttpMethod.PUT, headers, new MockedResponse(MultiMap.caseInsensitiveMultiMap())); JsonObject body = new JsonObject().put("key_1", "value_2").put("key_2", 99); @@ -76,7 +76,7 @@ public void testLogRequestResponseHeaders(TestContext context){ JsonObject expected = new JsonObject(); expected.put(REQUEST_URI, "/uri/to/a/resource"); expected.put(REQUEST_METHOD, "PUT"); - JsonObject requestHeaders = new JsonObject().put("Content-Type", "application/json").put("x-rp-unique-id", "123456"); + JsonObject requestHeaders = new JsonObject().put("Content-Type", "application/json").put("x-rp-unique_id", "123456"); expected.put(REQUEST_HEADERS, requestHeaders); JsonObject responseHeadersJsonObject = new JsonObject().put("header_1", "value_1").put("header_2", "value_2"); expected.put(RESPONSE_HEADERS, responseHeadersJsonObject); diff --git a/gateleen-logging/README_logging.md b/gateleen-logging/README_logging.md index 66c18cc92..e7efba497 100644 --- a/gateleen-logging/README_logging.md +++ b/gateleen-logging/README_logging.md @@ -169,5 +169,5 @@ Examples of logged request payloads and headers: ```json {"url":"/gateleen/server/test/r1","method":"GET","statusCode":304,"statusMessage":"Not Modified","request":{"headers":{"x-server-timestamp":"2015-01-21T15:12:21.392+01:00"}},"response":{"headers":{}}} {"url":"/gateleen/server/test/r1","method":"GET","statusCode":304,"statusMessage":"Not Modified","request":{"headers":{"if-none-match":"adafffea-cc94-4cf0-b138-9420f9c4fa27"}},"response":{"headers":{}}} -{"url":"/gateleen/server/test/r1","method":"GET","statusCode":304,"statusMessage":"Not Modified","request":{"headers":{"connection":"keep-alive","cache-control":"max-age=0","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","user-agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36","accept-encoding":"gzip, deflate, sdch","accept-language":"de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,fr;q=0.2,it;q=0.2","cookie":"JSESSIONID=ljv80nz7bmfz1wynkwpf5lte5","if-none-match":"adafffea-cc94-4cf0-b138-9420f9c4fa27","x-rp-unique_id":"5edb1d7c7ee93b3dd65779d39171c02c","x-server-timestamp":"2015-01-21T13:49:47.172+01:00","x-rp-unique-id":"5edb1d7c7ee93b3dd65779d39171c02c","host":"localhost:8989","transfer-encoding":"chunked"}},"response":{"headers":{"etag":"adafffea-cc94-4cf0-b138-9420f9c4fa27","content-length":"0"}}} +{"url":"/gateleen/server/test/r1","method":"GET","statusCode":304,"statusMessage":"Not Modified","request":{"headers":{"connection":"keep-alive","cache-control":"max-age=0","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","user-agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36","accept-encoding":"gzip, deflate, sdch","accept-language":"de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,fr;q=0.2,it;q=0.2","cookie":"JSESSIONID=ljv80nz7bmfz1wynkwpf5lte5","if-none-match":"adafffea-cc94-4cf0-b138-9420f9c4fa27","x-rp-unique_id":"5edb1d7c7ee93b3dd65779d39171c02c","x-server-timestamp":"2015-01-21T13:49:47.172+01:00","host":"localhost:8989","transfer-encoding":"chunked"}},"response":{"headers":{"etag":"adafffea-cc94-4cf0-b138-9420f9c4fa27","content-length":"0"}}} ``` diff --git a/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImpl.java b/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImpl.java index 3c817be45..b9e4092c4 100644 --- a/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImpl.java +++ b/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImpl.java @@ -492,9 +492,6 @@ private PatternAndCircuitHash getPatternAndCircuitHashFromRequest(HttpRequest re private String getRequestUniqueId(HttpRequest request) { String unique = request.getHeaders().get("x-rp-unique_id"); - if (unique == null) { - unique = request.getHeaders().get("x-rp-unique-id"); - } if (unique == null) { log.warn("request to {} has no unique-id header. Using request uri instead", request.getUri()); unique = request.getUri(); diff --git a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java index 349a1d3b7..37b295833 100755 --- a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java +++ b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java @@ -255,9 +255,6 @@ public void handle(AsyncResult event) { cReq.headers().set(SELF_REQUEST_HEADER, "true"); } - if (uniqueId != null) { - cReq.headers().set("x-rp-unique-id", uniqueId); - } setProfileHeaders(log, profileHeaderMap, cReq); if (base64UsernamePassword != null) { diff --git a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/StorageForwarder.java b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/StorageForwarder.java index ccd3ff982..a2c75205a 100755 --- a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/StorageForwarder.java +++ b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/StorageForwarder.java @@ -77,8 +77,6 @@ public void handle(final RoutingContext ctx) { return; } - setUniqueIdHeader(requestHeaders); - final Buffer header = Buffer.buffer(new HttpRequest(ctx.request().method(), targetUri, requestHeaders, null).toJsonObject().encode()); final Buffer requestBuffer = Buffer.buffer(); requestBuffer.setInt(0, header.length()).appendBuffer(header); @@ -105,9 +103,6 @@ public void handle(final RoutingContext ctx) { MultiMap responseHeaders = null; if (headers != null && headers.size() > 0) { responseHeaders = JsonMultiMap.fromJson(headers); - - setUniqueIdHeader(responseHeaders); - ctx.response().headers().setAll(responseHeaders); } corsHandler.handle(ctx.request()); @@ -151,16 +146,4 @@ public void handle(final RoutingContext ctx) { })); } - - /** - * Translates the x-rp-unique_id header to x-rp-unique-id. - * - * @param headers the request headers - */ - private void setUniqueIdHeader(MultiMap headers) { - final String uid = headers.get("x-rp-unique_id"); - if (uid != null) { - headers.set("x-rp-unique-id", uid); - } - } } diff --git a/gateleen-runconfig/src/main/java/org/swisspush/gateleen/runconfig/RunConfig.java b/gateleen-runconfig/src/main/java/org/swisspush/gateleen/runconfig/RunConfig.java index 424b24e4c..0381b2c02 100755 --- a/gateleen-runconfig/src/main/java/org/swisspush/gateleen/runconfig/RunConfig.java +++ b/gateleen-runconfig/src/main/java/org/swisspush/gateleen/runconfig/RunConfig.java @@ -679,12 +679,6 @@ private void logRequest(HttpServerRequest request) { if (uid != null) { sb.append(uid); sb.append(" "); - } else { - uid = request.headers().get("x-rp-unique-id"); - if (uid != null) { - sb.append(uid); - sb.append(" "); - } } sb.append(request.method());