From 8e52bcef050a4043f9f42cc694bd4cb136c46745 Mon Sep 17 00:00:00 2001 From: Juan Vanecek Date: Wed, 3 Jul 2024 17:06:55 -0300 Subject: [PATCH] Remove outgoing logging in the StargateApplication and leave only the incoming requests logging parameterization this is because the StargateApplication is an HTTP Server and doesn't make sense to include the outgoing logging parameterization since it will not be necessary used. --- .../StargateApplicationTest.class.st | 112 +++--------------- .../StargateApplication.class.st | 17 +-- 2 files changed, 21 insertions(+), 108 deletions(-) diff --git a/source/Stargate-API-Skeleton-Tests/StargateApplicationTest.class.st b/source/Stargate-API-Skeleton-Tests/StargateApplicationTest.class.st index 9a07e8a..def5a9e 100644 --- a/source/Stargate-API-Skeleton-Tests/StargateApplicationTest.class.st +++ b/source/Stargate-API-Skeleton-Tests/StargateApplicationTest.class.st @@ -7,9 +7,8 @@ Class { #instVars : [ 'port', 'baseUrl', - 'logIncomingHTTPRequests', - 'logOutgoingHTTPRequests', - 'logger' + 'logger', + 'logHTTPRequests' ], #category : 'Stargate-API-Skeleton-Tests', #package : 'Stargate-API-Skeleton-Tests' @@ -108,8 +107,7 @@ StargateApplicationTest >> setUp [ port := self freeListeningTCPPort. StargateApplication logsDirectory ensureCreateDirectory. - logIncomingHTTPRequests := false. - logOutgoingHTTPRequests := false. + logHTTPRequests := false ] { #category : 'private' } @@ -131,10 +129,8 @@ StargateApplicationTest >> startPetStore [ withAll: { ( '--pet-store.stargate.public-url=http://localhost:<1p>' expandMacrosWith: port ) . ( '--pet-store.stargate.port=<1p>' expandMacrosWith: port ) . ( '--pet-store.stargate.operations-secret=<1s>' expandMacrosWith: self secret ) . - ( '--pet-store.stargate.log-incoming-http-requests=<1p>' expandMacrosWith: - logIncomingHTTPRequests ) . - ( '--pet-store.stargate.log-outgoing-http-requests=<1p>' expandMacrosWith: - logOutgoingHTTPRequests ) }. + ( '--pet-store.stargate.log-http-requests=<1p>' expandMacrosWith: + logHTTPRequests ) }. baseUrl := runningApplication configuration petStore stargate publicURL ] @@ -293,11 +289,11 @@ StargateApplicationTest >> testGetPets [ ] { #category : 'tests - logs' } -StargateApplicationTest >> testLogIncomingRequestsDuringSuccessfulGet [ +StargateApplicationTest >> testLogRequestsDuringSuccessfulGet [ | logRecord | logger runDuring: [ - logIncomingHTTPRequests := true. + logHTTPRequests := true. self testGetPets ]. @@ -317,11 +313,11 @@ StargateApplicationTest >> testLogIncomingRequestsDuringSuccessfulGet [ ] { #category : 'tests - logs' } -StargateApplicationTest >> testLogIncomingRequestsDuringSucessfulPost [ +StargateApplicationTest >> testLogRequestsDuringSucessfulPost [ | logRecord | logger runDuring: [ - logIncomingHTTPRequests := true. + logHTTPRequests := true. self testCreatePet ]. @@ -341,11 +337,11 @@ StargateApplicationTest >> testLogIncomingRequestsDuringSucessfulPost [ ] { #category : 'tests - logs' } -StargateApplicationTest >> testLogIncomingRequestsDuringUnsucessfulPost [ +StargateApplicationTest >> testLogRequestsDuringUnsucessfulPost [ | logRecord | logger runDuring: [ - logIncomingHTTPRequests := true. + logHTTPRequests := true. self testUnsupportedMediaType ]. @@ -364,78 +360,6 @@ StargateApplicationTest >> testLogIncomingRequestsDuringUnsucessfulPost [ assert: logRecord response totalSize equals: 72 ] -{ #category : 'tests - logs' } -StargateApplicationTest >> testLogOutgoingRequestsDuringSucessfulGet [ - - | logRecord | - logger runDuring: [ - logOutgoingHTTPRequests := true. - self testGetPets - ]. - - logRecord := NeoJSONObject fromString: - ( String streamContents: [ :stream | - logger recordings last printOneLineJsonOn: stream ] ). - - self - assert: logRecord level equals: 'DEBUG'; - assert: logRecord message equals: 'Outgoing HTTP request responded'; - assert: logRecord process equals: 'Launchpad CLI'; - assert: logRecord summary isExpectedOutgoingSummaryWith: 'GET \/pets'; - assert: logRecord request method equals: 'GET'; - assert: logRecord request uri equals: ( 'http://localhost:<1p>/pets' expandMacrosWith: port ); - assert: logRecord response code equals: 200; - assert: logRecord response totalSize equals: 59 -] - -{ #category : 'tests - logs' } -StargateApplicationTest >> testLogOutgoingRequestsDuringSucessfulPost [ - - | logRecord | - logger runDuring: [ - logOutgoingHTTPRequests := true. - self testCreatePet - ]. - - logRecord := NeoJSONObject fromString: - ( String streamContents: [ :stream | - logger recordings last printOneLineJsonOn: stream ] ). - - self - assert: logRecord level equals: 'DEBUG'; - assert: logRecord message equals: 'Outgoing HTTP request responded'; - assert: logRecord process equals: 'Launchpad CLI'; - assert: logRecord summary isExpectedOutgoingSummaryWith: 'POST \/pets'; - assert: logRecord request method equals: 'POST'; - assert: logRecord request uri equals: ( 'http://localhost:<1p>/pets' expandMacrosWith: port ); - assert: logRecord response code equals: 201; - assert: logRecord response totalSize equals: 96 -] - -{ #category : 'tests - logs' } -StargateApplicationTest >> testLogOutgoingRequestsDuringUnsucessfulPost [ - - | logRecord | - logger runDuring: [ - logOutgoingHTTPRequests := true. - self testUnsupportedMediaType - ]. - - logRecord := NeoJSONObject fromString: - ( String streamContents: [ :stream | - logger recordings last printOneLineJsonOn: stream ] ). - - self - assert: logRecord level equals: 'DEBUG'; - assert: logRecord message equals: 'Outgoing HTTP request responded'; - assert: logRecord process equals: 'Launchpad CLI'; - assert: logRecord summary isExpectedOutgoingSummaryWith: 'POST \/pets'; - assert: logRecord request method equals: 'POST'; - assert: logRecord request uri equals: ( 'http://localhost:<1p>/pets' expandMacrosWith: port ); - assert: logRecord response code equals: 415; - assert: logRecord response totalSize equals: 72 -] - { #category : 'tests - api' } StargateApplicationTest >> testMethodNotAllowed [ @@ -492,7 +416,7 @@ StargateApplicationTest >> testPrintHelpOn [ self assert: help isLineEndingInsensitiveEqualsTo: ('NAME pet-store [<1s>] - A RESTful API for Pet stores SYNOPSYS - pet-store --pet-store.stargate.public-url=% --pet-store.stargate.port=% --pet-store.stargate.operations-secret=% [--pet-store.stargate.log-incoming-http-requests=%] [--pet-store.stargate.log-outgoing-http-requests=%] [--pet-store.stargate.concurrent-connections-threshold=%] + pet-store --pet-store.stargate.public-url=% --pet-store.stargate.port=% --pet-store.stargate.operations-secret=% [--pet-store.stargate.log-http-requests=%] [--pet-store.stargate.concurrent-connections-threshold=%] PARAMETERS --pet-store.stargate.public-url=% Public URL where the API is deployed. Used to create hypermedia links. @@ -500,10 +424,8 @@ PARAMETERS Listening port. --pet-store.stargate.operations-secret=% Secret key for checking JWT signatures. - --pet-store.stargate.log-incoming-http-requests=% - Boolean that indicates whether to log all the Incoming HTTP Requests. Defaults to false. - --pet-store.stargate.log-outgoing-http-requests=% - Boolean that indicates whether to log all the Outgoing HTTP Requests. Defaults to false. + --pet-store.stargate.log-http-requests=% + Boolean that indicates whether to log all the incoming HTTP requests. Defaults to false. --pet-store.stargate.concurrent-connections-threshold=% Set the maximum number of concurrent connections that I will accept. When this threshold is reached, a 503 Service Unavailable response will be sent and the connection will be closed. Defaults to 32. ENVIRONMENT @@ -513,10 +435,8 @@ ENVIRONMENT Listening port. PET_STORE__STARGATE__OPERATIONS_SECRET Secret key for checking JWT signatures. - PET_STORE__STARGATE__LOG_INCOMING_HTTP_REQUESTS - Boolean that indicates whether to log all the Incoming HTTP Requests. Defaults to false. - PET_STORE__STARGATE__LOG_OUTGOING_HTTP_REQUESTS - Boolean that indicates whether to log all the Outgoing HTTP Requests. Defaults to false. + PET_STORE__STARGATE__LOG_HTTP_REQUESTS + Boolean that indicates whether to log all the incoming HTTP requests. Defaults to false. PET_STORE__STARGATE__CONCURRENT_CONNECTIONS_THRESHOLD Set the maximum number of concurrent connections that I will accept. When this threshold is reached, a 503 Service Unavailable response will be sent and the connection will be closed. Defaults to 32. ' expandMacrosWith: PetStoreApplication version) diff --git a/source/Stargate-API-Skeleton/StargateApplication.class.st b/source/Stargate-API-Skeleton/StargateApplication.class.st index dadb510..dac1502 100644 --- a/source/Stargate-API-Skeleton/StargateApplication.class.st +++ b/source/Stargate-API-Skeleton/StargateApplication.class.st @@ -105,14 +105,8 @@ StargateApplication class >> stargateConfigurationParameters [ inside: self sectionsForStargateConfiguration convertingWith: #asByteArray ) asSensitive; add: ( OptionalConfigurationParameter - named: 'Log Incoming HTTP Requests' - describedBy: 'Boolean that indicates whether to log all the Incoming HTTP Requests' - inside: self sectionsForStargateConfiguration - defaultingTo: false - convertingWith: #asBoolean ); - add: ( OptionalConfigurationParameter - named: 'Log Outgoing HTTP Requests' - describedBy: 'Boolean that indicates whether to log all the Outgoing HTTP Requests' + named: 'Log HTTP Requests' + describedBy: 'Boolean that indicates whether to log all the incoming HTTP requests' inside: self sectionsForStargateConfiguration defaultingTo: false convertingWith: #asBoolean ); @@ -243,10 +237,9 @@ StargateApplication >> configureGlobalErrorHandlerIn: api [ { #category : 'private - activation/deactivation' } StargateApplication >> configureHTTPRequestsLogging [ - znEventToLogRecordAdapter logOutgoingRequests: self stargateConfiguration logOutgoingHTTPRequests. - znEventToLogRecordAdapter logIncomingRequests: self stargateConfiguration logIncomingHTTPRequests. - - znEventToLogRecordAdapter startUpListeners + znEventToLogRecordAdapter + logIncomingRequests: self stargateConfiguration logHTTPRequests; + startUpListeners ] { #category : 'private - activation/deactivation' }