Skip to content

Commit

Permalink
Merge pull request #71 from ba-st/zinc-event-logger
Browse files Browse the repository at this point in the history
Log Incoming and Outgoing Requests
  • Loading branch information
gcotelli authored Jul 2, 2024
2 parents 3b78b26 + e945302 commit 266b05c
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 23 deletions.
2 changes: 1 addition & 1 deletion rowan/components/Dependent-SUnit-Extensions.ston
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RwSimpleProjectLoadComponentV2 {
#name : 'Dependent-SUnit-Extensions',
#condition : 'sunit',
#projectNames : [ ],
#projectNames : [ ],
#componentNames : [
'Deployment'
],
Expand Down
3 changes: 2 additions & 1 deletion rowan/components/Deployment.ston
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
RwSimpleProjectLoadComponentV2 {
#name : 'Deployment',
#projectNames : [
'Zinc'
'Zinc',
'Bell'
],
#componentNames : [ ],
#packageNames : [
Expand Down
11 changes: 11 additions & 0 deletions rowan/projects/Bell.ston
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RwLoadSpecificationV2 {
#specName: 'Bell',
#projectName : 'Bell',
#gitUrl : 'https://github.com/ba-st/Bell.git',
#revision : 'v2',
#projectSpecFile : 'rowan/project.ston',
#componentNames : [
'Deployment',
'Dependent-SUnit-Extensions'
]
}
45 changes: 25 additions & 20 deletions source/BaselineOfHyperspace/BaselineOfHyperspace.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Class {
#name : #BaselineOfHyperspace,
#superclass : #BaselineOf,
#category : #BaselineOfHyperspace
#name : 'BaselineOfHyperspace',
#superclass : 'BaselineOf',
#category : 'BaselineOfHyperspace',
#package : 'BaselineOfHyperspace'
}

{ #category : #baselines }
{ #category : 'baselines' }
BaselineOfHyperspace >> baseline: spec [

<baseline>
Expand All @@ -27,31 +28,35 @@ BaselineOfHyperspace >> baseline: spec [
spec for: #'pharo10.x' do: [ self setUpPharo10Packages: spec ]
]

{ #category : #accessing }
{ #category : 'accessing' }
BaselineOfHyperspace >> projectClass [

^ MetacelloCypressBaselineProject
]

{ #category : #initialization }
{ #category : 'initialization' }
BaselineOfHyperspace >> setUpDependencies: spec [

spec
baseline: 'Buoy' with: [ spec repository: 'github://ba-st/Buoy:v7' ];
project: 'Buoy-Deployment' copyFrom: 'Buoy' with: [ spec loads: 'Deployment' ];
project: 'Buoy-SUnit' copyFrom: 'Buoy' with: [ spec loads: 'Dependent-SUnit-Extensions' ];
project: 'Buoy-Tools' copyFrom: 'Buoy' with: [ spec loads: 'Tools' ].
spec
baseline: 'ZincHTTPComponents' with: [ spec repository: 'github://svenvc/zinc' ];
project: 'Zinc-Core' copyFrom: 'ZincHTTPComponents' with: [ spec loads: 'Core' ]
spec
baseline: 'Buoy' with: [ spec repository: 'github://ba-st/Buoy:v7' ];
project: 'Buoy-Deployment' copyFrom: 'Buoy' with: [ spec loads: 'Deployment' ];
project: 'Buoy-SUnit' copyFrom: 'Buoy' with: [ spec loads: 'Dependent-SUnit-Extensions' ];
project: 'Buoy-Tools' copyFrom: 'Buoy' with: [ spec loads: 'Tools' ].
spec
baseline: 'ZincHTTPComponents' with: [ spec repository: 'github://svenvc/zinc' ];
project: 'Zinc-Core' copyFrom: 'ZincHTTPComponents' with: [ spec loads: 'Core' ].

spec
baseline: 'Bell' with: [ spec repository: 'github://ba-st/Bell:v2' ];
project: 'Bell-Deployment' copyFrom: 'Bell' with: [ spec loads: 'Deployment' ];
project: 'Bell-SUnit' copyFrom: 'Bell' with: [ spec loads: 'Dependent-SUnit-Extensions' ]
]

{ #category : #initialization }
{ #category : 'initialization' }
BaselineOfHyperspace >> setUpPackages: spec [

spec
package: 'Hyperspace-Model'
with: [ spec requires: #( 'Buoy-Deployment' 'Zinc-Core' ) ];
package: 'Hyperspace-Model' with: [ spec requires: #('Buoy-Deployment' 'Zinc-Core' 'Bell-Deployment')];
group: 'Deployment' with: 'Hyperspace-Model';
package: 'Hyperspace-Extensions'
with: [ spec requires: 'Hyperspace-Model' ];
Expand All @@ -64,7 +69,7 @@ BaselineOfHyperspace >> setUpPackages: spec [
package: 'Hyperspace-Model-Tests' with: [
spec requires:
#( 'Hyperspace-Model' 'Hyperspace-Extensions'
'Hyperspace-Pharo-Extensions' 'Dependent-SUnit-Extensions' ) ];
'Hyperspace-Pharo-Extensions' 'Dependent-SUnit-Extensions' 'Bell-SUnit') ];
group: 'Tests' with: 'Hyperspace-Model-Tests'.

spec
Expand All @@ -75,10 +80,10 @@ BaselineOfHyperspace >> setUpPackages: spec [
with: [ spec requires: 'Hyperspace-SUnit-Model' ];
group: 'Tests' with: 'Hyperspace-SUnit-Model-Tests'.

spec group: 'Tools' with: 'Buoy-Tools'
spec group: 'Tools' with: 'Buoy-Tools'
]

{ #category : #initialization }
{ #category : 'initialization' }
BaselineOfHyperspace >> setUpPharo10Packages: spec [

spec
Expand Down
2 changes: 1 addition & 1 deletion source/BaselineOfHyperspace/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #BaselineOfHyperspace }
Package { #name : 'BaselineOfHyperspace' }
164 changes: 164 additions & 0 deletions source/Hyperspace-Model-Tests/ZnEventToLogRecordAdapterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
Class {
#name : 'ZnEventToLogRecordAdapterTest',
#superclass : 'TestCase',
#instVars : [
'loggingAsserter',
'zincEventToLogRecordAdapter'
],
#category : 'Hyperspace-Model-Tests-Zinc',
#package : 'Hyperspace-Model-Tests',
#tag : 'Zinc'
}

{ #category : 'private' }
ZnEventToLogRecordAdapterTest >> addTimestampRegexTo: aLogEntryCollection [

^ aLogEntryCollection collect: [ :regexExpression |
'\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d+)?(\+|-)(\d+\:\d+) <1s>' expandMacrosWith:
regexExpression
]
]

{ #category : 'private' }
ZnEventToLogRecordAdapterTest >> runMemoryLoggerDuring: aBlock assertingLogRecordsMatchRegexes: expectedLogEntries [

| expectedLogEntriesWithTimestamp |

expectedLogEntriesWithTimestamp := self addTimestampRegexTo: expectedLogEntries.

loggingAsserter
runMemoryLoggerDuring: aBlock;
assertLogRecordsMatchUsing: expectedLogEntriesWithTimestamp
]

{ #category : 'running' }
ZnEventToLogRecordAdapterTest >> setUp [

super setUp.
loggingAsserter := LoggingAsserter on: self.
zincEventToLogRecordAdapter := ZnEventToLogRecordAdapter new
]

{ #category : 'running' }
ZnEventToLogRecordAdapterTest >> tearDown [

zincEventToLogRecordAdapter stopListeners.
loggingAsserter stopLoggers.

super tearDown
]

{ #category : 'running' }
ZnEventToLogRecordAdapterTest >> testLogsOfIncomingGetRequest [

zincEventToLogRecordAdapter
logIncomingRequests: true;
startUpListeners.

self
runMemoryLoggerDuring: [
self withServerDo: [ :server |
| client |
server onRequestRespond: [ :request |
( ZnResponse ok: ( ZnEntity textCRLF: 'OK' ) )
setConnectionClose;
yourself
].
client := ZnClient new.
client url: server localUrl.
client get
]
]
assertingLogRecordsMatchRegexes:
#( '\[DEBUG\] Server accepted connection \{"remoteAddress"\:"127.0.0.1","processId"\:(\d+),"eventId"\:(\d+)\}'
'\[DEBUG\] Incoming HTTP request received \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Read a\s{0,1}ZnRequest\(GET /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"GET","uri"\:"/"\},"processId"\:(\d+),"eventId"\:(\d+)\}'
'\[DEBUG\] Incoming HTTP request responded \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Handled a\s{0,1}ZnRequest\(GET /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"GET","uri"\:"/"\},"processId"\:(\d+),"eventId"\:(\d+),"response"\:\{"code"\:200,"totalSize"\:(\d+)\}\}'
'\[DEBUG\] Server closed connection \{"remoteAddress"\:"127.0.0.1","processId"\:(\d+),"eventId"\:(\d+)\}' )
]
{ #category : 'running' }
ZnEventToLogRecordAdapterTest >> testLogsOfIncomingPostRequest [
zincEventToLogRecordAdapter
logIncomingRequests: true;
startUpListeners.
self
runMemoryLoggerDuring: [
self withServerDo: [ :server |
| client |
server onRequestRespond: [ :request |
( ZnResponse ok: ( ZnEntity textCRLF: 'Hi you too!' ) )
setConnectionClose;
yourself
].
client := ZnClient new.
client post: server localUrl contents: 'Hi there!'
]
]
assertingLogRecordsMatchRegexes:
#( '\[DEBUG\] Server accepted connection \{"remoteAddress"\:"127.0.0.1","processId"\:(\d+),"eventId"\:(\d+)\}'
'\[DEBUG\] Incoming HTTP request received \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Read a\s{0,1}ZnRequest\(POST /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"POST","uri"\:"/"\},"processId"\:(\d+),"eventId"\:(\d+)\}'
'\[DEBUG\] Incoming HTTP request responded \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Handled a\s{0,1}ZnRequest\(POST /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"POST","uri"\:"/"\},"processId"\:(\d+),"eventId"\:(\d+),"response"\:\{"code"\:200,"totalSize"\:(\d+)\}\}'
'\[DEBUG\] Server closed connection \{"remoteAddress"\:"127.0.0.1","processId"\:(\d+),"eventId"\:(\d+)\}' )
]
{ #category : 'running' }
ZnEventToLogRecordAdapterTest >> testLogsOfOutgoingGetRequest [
zincEventToLogRecordAdapter
logOutgoingRequests: true;
startUpListeners.
self
runMemoryLoggerDuring: [
self withServerDo: [ :server |
| client |
server onRequestRespond: [ :request |
( ZnResponse ok: ( ZnEntity textCRLF: 'OK' ) )
setConnectionClose;
yourself
].
client := ZnClient new.
client url: server localUrl.
client get
]
]
assertingLogRecordsMatchRegexes:
#( '\[DEBUG\] Outgoing HTTP request sent \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Written a\s{0,1}ZnRequest\(GET /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"GET","uri"\:"http\://localhost\:(\d+)/"\},"processId"\:(\d+),"eventId"\:(\d+)\}'
'\[DEBUG\] Outgoing HTTP request responded \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? GET / 200 (\d+)B (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"GET","uri"\:"http\://localhost\:(\d+)/"\},"processId"\:(\d+),"eventId"\:(\d+),"response"\:\{"code"\:200,"totalSize"\:(\d+)\}\}' )
]
{ #category : 'running' }
ZnEventToLogRecordAdapterTest >> testLogsOfOutgoingPostRequest [
zincEventToLogRecordAdapter
logOutgoingRequests: true;
startUpListeners.
self
runMemoryLoggerDuring: [
self withServerDo: [ :server |
| client |
server onRequestRespond: [ :request |
( ZnResponse ok: ( ZnEntity textCRLF: 'Hi you too!' ) )
setConnectionClose;
yourself
].
client := ZnClient new.
client post: server localUrl contents: 'Hi there!'
]
]
assertingLogRecordsMatchRegexes:
#( '\[DEBUG\] Outgoing HTTP request sent \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? Request Written a\s{0,1}ZnRequest\(POST /\) (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"POST","uri"\:"http\://localhost\:(\d+)/"\},"processId"\:(\d+),"eventId"\:(\d+)\}'
'\[DEBUG\] Outgoing HTTP request responded \{"summary"\:"\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} ((\d+) (\d+))? POST / 200 (\d+)B (\d+)ms","durationInMilliseconds"\:(\d+),"request"\:\{"method"\:"POST","uri"\:"http\://localhost\:(\d+)/"\},"processId"\:(\d+),"eventId"\:(\d+),"response"\:\{"code"\:200,"totalSize"\:(\d+)\}\}' )
]
{ #category : 'enumerating' }
ZnEventToLogRecordAdapterTest >> withServerDo: block [
ZnServer withOSAssignedPortDo: block
]
Loading

0 comments on commit 266b05c

Please sign in to comment.