Skip to content

Commit

Permalink
Remove outgoing logging in the StargateApplication and leave only the…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
jvanecek committed Jul 3, 2024
1 parent 28a603f commit 8e52bce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 108 deletions.
112 changes: 16 additions & 96 deletions source/Stargate-API-Skeleton-Tests/StargateApplicationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ Class {
#instVars : [
'port',
'baseUrl',
'logIncomingHTTPRequests',
'logOutgoingHTTPRequests',
'logger'
'logger',
'logHTTPRequests'
],
#category : 'Stargate-API-Skeleton-Tests',
#package : 'Stargate-API-Skeleton-Tests'
Expand Down Expand Up @@ -108,8 +107,7 @@ StargateApplicationTest >> setUp [
port := self freeListeningTCPPort.
StargateApplication logsDirectory ensureCreateDirectory.

logIncomingHTTPRequests := false.
logOutgoingHTTPRequests := false.
logHTTPRequests := false
]

{ #category : 'private' }
Expand All @@ -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
]

Expand Down Expand Up @@ -293,11 +289,11 @@ StargateApplicationTest >> testGetPets [
]

{ #category : 'tests - logs' }
StargateApplicationTest >> testLogIncomingRequestsDuringSuccessfulGet [
StargateApplicationTest >> testLogRequestsDuringSuccessfulGet [

| logRecord |
logger runDuring: [
logIncomingHTTPRequests := true.
logHTTPRequests := true.
self testGetPets
].

Expand All @@ -317,11 +313,11 @@ StargateApplicationTest >> testLogIncomingRequestsDuringSuccessfulGet [
]

{ #category : 'tests - logs' }
StargateApplicationTest >> testLogIncomingRequestsDuringSucessfulPost [
StargateApplicationTest >> testLogRequestsDuringSucessfulPost [

| logRecord |
logger runDuring: [
logIncomingHTTPRequests := true.
logHTTPRequests := true.
self testCreatePet
].

Expand All @@ -341,11 +337,11 @@ StargateApplicationTest >> testLogIncomingRequestsDuringSucessfulPost [
]

{ #category : 'tests - logs' }
StargateApplicationTest >> testLogIncomingRequestsDuringUnsucessfulPost [
StargateApplicationTest >> testLogRequestsDuringUnsucessfulPost [

| logRecord |
logger runDuring: [
logIncomingHTTPRequests := true.
logHTTPRequests := true.
self testUnsupportedMediaType
].

Expand All @@ -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 [

Expand Down Expand Up @@ -492,18 +416,16 @@ StargateApplicationTest >> testPrintHelpOn [
self assert: help isLineEndingInsensitiveEqualsTo: ('NAME
pet-store [<1s>] - A RESTful API for Pet stores
SYNOPSYS
pet-store --pet-store.stargate.public-url=%<publicURL%> --pet-store.stargate.port=%<port%> --pet-store.stargate.operations-secret=%<operationsSecret%> [--pet-store.stargate.log-incoming-http-requests=%<logIncomingHTTPRequests%>] [--pet-store.stargate.log-outgoing-http-requests=%<logOutgoingHTTPRequests%>] [--pet-store.stargate.concurrent-connections-threshold=%<concurrentConnectionsThreshold%>]
pet-store --pet-store.stargate.public-url=%<publicURL%> --pet-store.stargate.port=%<port%> --pet-store.stargate.operations-secret=%<operationsSecret%> [--pet-store.stargate.log-http-requests=%<logHTTPRequests%>] [--pet-store.stargate.concurrent-connections-threshold=%<concurrentConnectionsThreshold%>]
PARAMETERS
--pet-store.stargate.public-url=%<publicURL%>
Public URL where the API is deployed. Used to create hypermedia links.
--pet-store.stargate.port=%<port%>
Listening port.
--pet-store.stargate.operations-secret=%<operationsSecret%>
Secret key for checking JWT signatures.
--pet-store.stargate.log-incoming-http-requests=%<logIncomingHTTPRequests%>
Boolean that indicates whether to log all the Incoming HTTP Requests. Defaults to false.
--pet-store.stargate.log-outgoing-http-requests=%<logOutgoingHTTPRequests%>
Boolean that indicates whether to log all the Outgoing HTTP Requests. Defaults to false.
--pet-store.stargate.log-http-requests=%<logHTTPRequests%>
Boolean that indicates whether to log all the incoming HTTP requests. Defaults to false.
--pet-store.stargate.concurrent-connections-threshold=%<concurrentConnectionsThreshold%>
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
Expand All @@ -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)
Expand Down
17 changes: 5 additions & 12 deletions source/Stargate-API-Skeleton/StargateApplication.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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' }
Expand Down

0 comments on commit 8e52bce

Please sign in to comment.