Skip to content

Commit

Permalink
Merge branch 'release-candidate' into localization
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed Jul 19, 2024
2 parents e94126d + 266b05c commit 2412a49
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 11 deletions.
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'
]
}
25 changes: 15 additions & 10 deletions source/BaselineOfHyperspace/BaselineOfHyperspace.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,26 @@ BaselineOfHyperspace >> projectClass [
{ #category : 'initialization' }
BaselineOfHyperspace >> setUpDependencies: spec [

spec
baseline: 'Buoy' with: [ spec repository: 'github://ba-st/Buoy:v8' ];
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:v8' ];
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' }
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' ];
group: 'Deployment' with: 'Hyperspace-Extensions';
Expand All @@ -63,7 +68,7 @@ BaselineOfHyperspace >> setUpPackages: spec [
spec
package: 'Hyperspace-Model-Tests' with: [
spec requires: #( 'Hyperspace-Model' 'Hyperspace-Extensions' 'Hyperspace-Pharo-Extensions'
'Hyperspace-Buoy-Extensions' 'Dependent-SUnit-Extensions' )
'Hyperspace-Buoy-Extensions' 'Dependent-SUnit-Extensions' 'Bell-SUnit')
];
group: 'Tests' with: 'Hyperspace-Model-Tests'.

Expand Down
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
]
153 changes: 153 additions & 0 deletions source/Hyperspace-Model/ZnEventToLogRecordAdapter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
Class {
#name : 'ZnEventToLogRecordAdapter',
#superclass : 'Object',
#instVars : [
'logOutgoingRequests',
'logIncomingRequests',
'subscriptions'
],
#category : 'Hyperspace-Model',
#package : 'Hyperspace-Model'
}

{ #category : 'private - dumping' }
ZnEventToLogRecordAdapter >> asStructuredRequest: aZnRequest [

| json |

json := NeoJSONObject new.
json
at: #method put: aZnRequest method;
at: #uri put: aZnRequest uri asString.
^json
]

{ #category : 'private - dumping' }
ZnEventToLogRecordAdapter >> asStructuredResponse: aZnResponse [

| json |

json := NeoJSONObject new.
json
at: #code put: aZnResponse code;
at: #totalSize put: aZnResponse contentLength.
^json
]

{ #category : 'private - dumping' }
ZnEventToLogRecordAdapter >> dumpConnectionEvent: aZnServerConnectionClosedEvent on: data [

data
at: #remoteAddress put: ( self ipAddressToString: aZnServerConnectionClosedEvent );
at: #processId put: aZnServerConnectionClosedEvent processId;
at: #eventId put: aZnServerConnectionClosedEvent id
]

{ #category : 'private - dumping' }
ZnEventToLogRecordAdapter >> dumpRequestAndResponseOf: event on: json [

| response |

self dumpRequestOf: event on: json.
response := event response.
(response hasEntity
and: [response entity hasContentType and: [response entity contentType isBinary not]])
then: [json at: #response put: (self asStructuredResponse: response)].
^json
]

{ #category : 'private - dumping' }
ZnEventToLogRecordAdapter >> dumpRequestOf: event on: json [

json
at: #summary put: event printString;
at: #durationInMilliseconds put: event duration;
at: #request put: (self asStructuredRequest: event request);
at: #processId put: event processId;
at: #eventId put: event id.
^json
]

{ #category : 'system startup' }
ZnEventToLogRecordAdapter >> initialize [

super initialize.

logOutgoingRequests := false.
logIncomingRequests := false.
subscriptions := OrderedCollection new
]

{ #category : 'private - dumping' }
ZnEventToLogRecordAdapter >> ipAddressToString: aZnServerConnectionClosedEvent [

^ aZnServerConnectionClosedEvent address isString
then: [ aZnServerConnectionClosedEvent address ]
otherwise: [ ZnNetworkingUtils ipAddressToString: aZnServerConnectionClosedEvent address ]
]

{ #category : 'private - configuring' }
ZnEventToLogRecordAdapter >> logIncomingRequests: aBoolean [

logIncomingRequests := aBoolean
]

{ #category : 'private - configuring' }
ZnEventToLogRecordAdapter >> logOutgoingRequests: aBoolean [

logOutgoingRequests := aBoolean
]

{ #category : 'system startup' }
ZnEventToLogRecordAdapter >> startUpIncomingRequestListeners [

self subscribeToEventsOf: ZnServerConnectionClosedEvent andDo: [ :event |
LogRecord emitStructuredDebuggingInfo: 'Server closed connection'
with: [ :data | self dumpConnectionEvent: event on: data ]
].
self subscribeToEventsOf: ZnConnectionAcceptedEvent andDo: [ :event |
LogRecord emitStructuredDebuggingInfo: 'Server accepted connection'
with: [ :data | self dumpConnectionEvent: event on: data ]
].
self subscribeToEventsOf: ZnRequestReadEvent andDo: [ :event |
LogRecord emitStructuredDebuggingInfo: 'Incoming HTTP request received'
with: [ :data | self dumpRequestOf: event on: data ]
].
self subscribeToEventsOf: ZnRequestResponseHandledEvent andDo: [ :event |
LogRecord emitStructuredDebuggingInfo: 'Incoming HTTP request responded'
with: [ :data | self dumpRequestAndResponseOf: event on: data ]
]
]

{ #category : 'system startup' }
ZnEventToLogRecordAdapter >> startUpListeners [

logOutgoingRequests then: [ self startUpOutgoingRequestListeners ].

logIncomingRequests then: [ self startUpIncomingRequestListeners ]
]

{ #category : 'system startup' }
ZnEventToLogRecordAdapter >> startUpOutgoingRequestListeners [

self subscribeToEventsOf: ZnRequestWrittenEvent andDo: [ :event |
LogRecord emitStructuredDebuggingInfo: 'Outgoing HTTP request sent'
with: [ :data | self dumpRequestOf: event on: data ]
].
self subscribeToEventsOf: ZnClientTransactionEvent andDo: [ :event |
LogRecord emitStructuredDebuggingInfo: 'Outgoing HTTP request responded'
with: [ :data | self dumpRequestAndResponseOf: event on: data ]
]
]

{ #category : 'system startup' }
ZnEventToLogRecordAdapter >> stopListeners [

subscriptions do: [:subscription | ZnLogEvent announcer removeSubscription: subscription]
]

{ #category : 'system startup' }
ZnEventToLogRecordAdapter >> subscribeToEventsOf: anEventType andDo: aBlock [

subscriptions add: ( ZnLogEvent announcer when: anEventType do: aBlock for: self )
]

0 comments on commit 2412a49

Please sign in to comment.