Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions source/StatsDClient/NullStatsDClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
14 changes: 8 additions & 6 deletions source/StatsDClient/ProxyStatsDClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
10 changes: 6 additions & 4 deletions source/StatsDClient/ProxyStatsDClientTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
16 changes: 9 additions & 7 deletions source/StatsDClient/QueuedStatsDClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 ]
]
12 changes: 7 additions & 5 deletions source/StatsDClient/QueuedStatsDClientTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
48 changes: 25 additions & 23 deletions source/StatsDClient/StatsDClientBase.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions source/StatsDClient/StatsDClientBaseTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
16 changes: 9 additions & 7 deletions source/StatsDClient/UDPStatsDClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.
]
2 changes: 1 addition & 1 deletion source/StatsDClient/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #StatsDClient }
Package { #name : 'StatsDClient' }