From f0f2e999c8c16a7371e4ecc5614ed5d7f3f3819d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Thu, 15 May 2025 14:28:56 +0200 Subject: [PATCH] Cleaning --- source/StatsDClient/NullStatsDClient.class.st | 20 ++++---- .../StatsDClient/ProxyStatsDClient.class.st | 14 +++--- .../ProxyStatsDClientTest.class.st | 10 ++-- .../StatsDClient/QueuedStatsDClient.class.st | 16 ++++--- .../QueuedStatsDClientTest.class.st | 12 +++-- source/StatsDClient/StatsDClientBase.class.st | 48 ++++++++++--------- .../StatsDClientBaseTest.class.st | 12 +++-- source/StatsDClient/UDPStatsDClient.class.st | 16 ++++--- source/StatsDClient/package.st | 2 +- 9 files changed, 83 insertions(+), 67 deletions(-) diff --git a/source/StatsDClient/NullStatsDClient.class.st b/source/StatsDClient/NullStatsDClient.class.st index 49ca877..8706c3e 100644 --- a/source/StatsDClient/NullStatsDClient.class.st +++ b/source/StatsDClient/NullStatsDClient.class.st @@ -2,32 +2,34 @@ I do no work " Class { - #name : #NullStatsDClient, - #superclass : #StatsDClientBase, - #category : #StatsDClient + #name : 'NullStatsDClient', + #superclass : 'StatsDClientBase', + #category : 'StatsDClient-Client', + #package : 'StatsDClient', + #tag : 'Client' } -{ #category : #'as yet unclassified' } +{ #category : 'api' } NullStatsDClient >> decrement: aName rate: aRate [ ] -{ #category : #'as yet unclassified' } +{ #category : 'api' } NullStatsDClient >> gauge: aName value: aValue rate: aRate [ ] -{ #category : #'as yet unclassified' } +{ #category : 'api' } NullStatsDClient >> increment: aName by: aCount rate: aRate [ ] -{ #category : #'as yet unclassified' } +{ #category : 'api' } NullStatsDClient >> increment: aName rate: aRate [ ] -{ #category : #'as yet unclassified' } +{ #category : 'api' } NullStatsDClient >> set: aName value: aValue rate: aRate [ ] -{ #category : #'as yet unclassified' } +{ #category : 'api' } NullStatsDClient >> time: aName rate: aRate block: aBlock [ aBlock value ] diff --git a/source/StatsDClient/ProxyStatsDClient.class.st b/source/StatsDClient/ProxyStatsDClient.class.st index ec08ec4..9c2f9c4 100644 --- a/source/StatsDClient/ProxyStatsDClient.class.st +++ b/source/StatsDClient/ProxyStatsDClient.class.st @@ -2,26 +2,28 @@ I am a proxy/tee to allow to send one occurence to multiple endpoints. " Class { - #name : #ProxyStatsDClient, - #superclass : #StatsDClientBase, + #name : 'ProxyStatsDClient', + #superclass : 'StatsDClientBase', #instVars : [ 'clients' ], - #category : #StatsDClient + #category : 'StatsDClient-Client', + #package : 'StatsDClient', + #tag : 'Client' } -{ #category : #'as yet unclassified' } +{ #category : 'adding' } ProxyStatsDClient >> addClient: aClient [ clients add: aClient ] -{ #category : #initialization } +{ #category : 'initialization' } ProxyStatsDClient >> initialize [ super initialize. clients := OrderedCollection new. ] -{ #category : #initialization } +{ #category : 'sending' } ProxyStatsDClient >> sendData: aMsg [ clients do: [:each | each sendData: aMsg]. diff --git a/source/StatsDClient/ProxyStatsDClientTest.class.st b/source/StatsDClient/ProxyStatsDClientTest.class.st index fd3192e..fe696b8 100644 --- a/source/StatsDClient/ProxyStatsDClientTest.class.st +++ b/source/StatsDClient/ProxyStatsDClientTest.class.st @@ -2,12 +2,14 @@ A ProxyStatsDClientTest is a test class for testing the behavior of ProxyStatsDClient " Class { - #name : #ProxyStatsDClientTest, - #superclass : #TestCase, - #category : #'StatsDClient-Tests' + #name : 'ProxyStatsDClientTest', + #superclass : 'TestCase', + #category : 'StatsDClient-Tests', + #package : 'StatsDClient', + #tag : 'Tests' } -{ #category : #tests } +{ #category : 'tests' } ProxyStatsDClientTest >> testAllClientsReceive_success [ | clientA clientB statsd | diff --git a/source/StatsDClient/QueuedStatsDClient.class.st b/source/StatsDClient/QueuedStatsDClient.class.st index 10f8e8b..33c1e3e 100644 --- a/source/StatsDClient/QueuedStatsDClient.class.st +++ b/source/StatsDClient/QueuedStatsDClient.class.st @@ -4,23 +4,25 @@ I can be used to queue/delay. Currently I require a flush. TODO: Separate network from format.. here.. " Class { - #name : #QueuedStatsDClient, - #superclass : #StatsDClientBase, + #name : 'QueuedStatsDClient', + #superclass : 'StatsDClientBase', #instVars : [ 'semaphore', 'queued', 'client' ], - #category : #StatsDClient + #category : 'StatsDClient-Client', + #package : 'StatsDClient', + #tag : 'Client' } -{ #category : #'as yet unclassified' } +{ #category : 'accessing' } QueuedStatsDClient >> client: aRealClient [ self flag: #todo. "We need to separate network from the client" client := aRealClient ] -{ #category : #'as yet unclassified' } +{ #category : 'accessing' } QueuedStatsDClient >> flush [ | data | "Swap all queued messages" @@ -36,14 +38,14 @@ QueuedStatsDClient >> flush [ ] -{ #category : #'as yet unclassified' } +{ #category : 'initialization' } QueuedStatsDClient >> initialize [ super initialize. semaphore := Semaphore forMutualExclusion. queued := OrderedCollection new. ] -{ #category : #'as yet unclassified' } +{ #category : 'sending' } QueuedStatsDClient >> sendData: aMsg [ semaphore critical: [ queued add: aMsg ] ] diff --git a/source/StatsDClient/QueuedStatsDClientTest.class.st b/source/StatsDClient/QueuedStatsDClientTest.class.st index 802ca72..6a92d6b 100644 --- a/source/StatsDClient/QueuedStatsDClientTest.class.st +++ b/source/StatsDClient/QueuedStatsDClientTest.class.st @@ -2,20 +2,22 @@ A QueuedStatsDClientTest is a test class for testing the behavior of QueuedStatsDClient " Class { - #name : #QueuedStatsDClientTest, - #superclass : #TestCase, + #name : 'QueuedStatsDClientTest', + #superclass : 'TestCase', #instVars : [ 'statsd' ], - #category : #'StatsDClient-Tests' + #category : 'StatsDClient-Tests', + #package : 'StatsDClient', + #tag : 'Tests' } -{ #category : #'as yet unclassified' } +{ #category : 'running' } QueuedStatsDClientTest >> setUp [ statsd := QueuedStatsDClient new. ] -{ #category : #'as yet unclassified' } +{ #category : 'tests' } QueuedStatsDClientTest >> testCounterApi [ | queued | diff --git a/source/StatsDClient/StatsDClientBase.class.st b/source/StatsDClient/StatsDClientBase.class.st index b13443b..958b5cc 100644 --- a/source/StatsDClient/StatsDClientBase.class.st +++ b/source/StatsDClient/StatsDClientBase.class.st @@ -2,26 +2,28 @@ I am the baseclass and I know how to format things. " Class { - #name : #StatsDClientBase, - #superclass : #Object, + #name : 'StatsDClientBase', + #superclass : 'Object', #instVars : [ 'rateRandom', 'prefix' ], - #category : #StatsDClient + #category : 'StatsDClient-Client', + #package : 'StatsDClient', + #tag : 'Client' } -{ #category : #api } +{ #category : 'api' } StatsDClientBase >> decrement: aName rate: aRate [ ^self increment: aName by: -1 rate: aRate. ] -{ #category : #'as yet unclassified' } +{ #category : 'accessing' } StatsDClientBase >> flush [ "Do nothing here. Part of the 'pipeline' part" ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> format: aName value: aValue rate: aRate type: aType [ ^String streamContents: [:str | str @@ -37,97 +39,97 @@ StatsDClientBase >> format: aName value: aValue rate: aRate type: aType [ ]] ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> formatCounter: aCounterName value: aValue [ ^self formatCounter: aCounterName value: aValue rate: 1 ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> formatCounter: aCounterName value: aValue rate: aRate [ ^self format: aCounterName value: aValue asString rate: aRate type: 'c' ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> formatGauge: aGaugeName value: aValue [ ^self formatGauge: aGaugeName value: aValue rate: 1 ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> formatGauge: aGaugeName value: aValue rate: aRate [ ^self format: aGaugeName value: aValue asString rate: aRate type: 'g' ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> formatSet: aSetName value: aValue [ ^self formatSet: aSetName value: aValue rate: 1 ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> formatSet: aSetName value: aValue rate: aRate [ ^self format: aSetName value: aValue asString rate: aRate type: 's' ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> formatTimer: aTimerName value: aValue [ ^self formatTimer: aTimerName value: aValue rate: 1 ] -{ #category : #format } +{ #category : 'format' } StatsDClientBase >> formatTimer: aTimerName value: aValue rate: aRate [ ^self format: aTimerName value: aValue asString rate: aRate type: 'ms' ] -{ #category : #'as yet unclassified' } +{ #category : 'api' } StatsDClientBase >> forwardEvent: aRate [ ^aRate < 1 ifTrue: [rateRandom next <= aRate] ifFalse: [true] ] -{ #category : #api } +{ #category : 'api' } StatsDClientBase >> gauge: aName value: aValue rate: aRate [ (self forwardEvent: aRate) ifTrue: [ self sendData: (self formatGauge: aName value: aValue rate: aRate)] ] -{ #category : #api } +{ #category : 'api' } StatsDClientBase >> increment: aName by: aCount rate: aRate [ (self forwardEvent: aRate) ifTrue: [ self sendData: (self formatCounter: aName value: aCount rate: aRate)] ] -{ #category : #api } +{ #category : 'api' } StatsDClientBase >> increment: aName rate: aRate [ ^self increment: aName by: 1 rate: aRate. ] -{ #category : #'as yet unclassified' } +{ #category : 'initialization' } StatsDClientBase >> initialize [ super initialize. rateRandom := Random new. prefix := ''. ] -{ #category : #api } +{ #category : 'api' } StatsDClientBase >> prefix: aPrefix [ prefix := aPrefix ] -{ #category : #'as yet unclassified' } +{ #category : 'sending' } StatsDClientBase >> sendData: aMsg [ self subclassResponsibility ] -{ #category : #api } +{ #category : 'api' } StatsDClientBase >> set: aName value: aValue rate: aRate [ (self forwardEvent: aRate) ifTrue: [ self sendData: (self formatSet: aName value: aValue rate: aRate)] ] -{ #category : #api } +{ #category : 'api' } StatsDClientBase >> time: aName rate: aRate block: aBlock [ | initialMicroseconds | "We could use >>#value here but then sampled/unsampled would behave diff --git a/source/StatsDClient/StatsDClientBaseTest.class.st b/source/StatsDClient/StatsDClientBaseTest.class.st index 594887d..35ba20a 100644 --- a/source/StatsDClient/StatsDClientBaseTest.class.st +++ b/source/StatsDClient/StatsDClientBaseTest.class.st @@ -2,20 +2,22 @@ A StatsDClientBaseTest is a test class for testing the behavior of StatsDClientBase " Class { - #name : #StatsDClientBaseTest, - #superclass : #TestCase, + #name : 'StatsDClientBaseTest', + #superclass : 'TestCase', #instVars : [ 'client' ], - #category : #'StatsDClient-Tests' + #category : 'StatsDClient-Tests', + #package : 'StatsDClient', + #tag : 'Tests' } -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } StatsDClientBaseTest >> setUp [ client := StatsDClientBase new. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } StatsDClientBaseTest >> testFormat [ self assert: (client formatCounter: 'counter' value: 1) equals: 'counter:1|c'. diff --git a/source/StatsDClient/UDPStatsDClient.class.st b/source/StatsDClient/UDPStatsDClient.class.st index 1729d32..4a91c83 100644 --- a/source/StatsDClient/UDPStatsDClient.class.st +++ b/source/StatsDClient/UDPStatsDClient.class.st @@ -4,32 +4,34 @@ I am a UDP client for the statsdD protocol Set the destination hostname/port and then call start. Use the normal API for the rest of it. " Class { - #name : #UDPStatsDClient, - #superclass : #StatsDClientBase, + #name : 'UDPStatsDClient', + #superclass : 'StatsDClientBase', #instVars : [ 'socket', 'address', 'port' ], - #category : #StatsDClient + #category : 'StatsDClient-Client', + #package : 'StatsDClient', + #tag : 'Client' } -{ #category : #'as yet unclassified' } +{ #category : 'initialization' } UDPStatsDClient >> hostname: aHostname [ address := NetNameResolver addressForName: aHostname. ] -{ #category : #'as yet unclassified' } +{ #category : 'accessing' } UDPStatsDClient >> port: aPort [ port := aPort. ] -{ #category : #'as yet unclassified' } +{ #category : 'sending' } UDPStatsDClient >> sendData: aMsg [ socket sendUDPData: aMsg toHost: address port: port ] -{ #category : #'as yet unclassified' } +{ #category : 'accessing' } UDPStatsDClient >> start [ socket := Socket newUDP. ] diff --git a/source/StatsDClient/package.st b/source/StatsDClient/package.st index d45ce03..6ae38b0 100644 --- a/source/StatsDClient/package.st +++ b/source/StatsDClient/package.st @@ -1 +1 @@ -Package { #name : #StatsDClient } +Package { #name : 'StatsDClient' }