Skip to content
Merged
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
28 changes: 22 additions & 6 deletions source/Canopy-Metrics-Tests/CanopyZincCounterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@ Class {
}

{ #category : 'as yet unclassified' }
CanopyZincCounterTest >> testHandleAnnouncementAdjustsDurationWithExponentialMovingAverage [
"Mirrors ZincCounter (pharo-metrics, out of scope otherwise): first duration sets the
baseline, subsequent durations are folded in with 99% weight on the running average."
CanopyZincCounterTest >> testAFreshCounterAlreadyCarriesTheUsualStatusCodes [
"Parity with what the servers export today: the status series exist from the first scrape at
zero instead of appearing with the first response of that kind, and the average duration is a
number rather than nil - which is not even valid exposition."
| counter |
counter := CanopyZincCounter new.
self assert: counter duration equals: 0.
self assert: (counter responses at: 200) equals: 0.
self assert: (counter responses at: 500) equals: 0.
self assert: counter responses size equals: 15
]

{ #category : 'as yet unclassified' }
CanopyZincCounterTest >> testHandleAnnouncementFoldsDurationsIntoARunningAverage [
"Mirrors ZincCounter (pharo-metrics): the average starts at zero and every duration is folded
in with 99% weight on the running value. The first request therefore does not set a baseline -
it moves the average by a hundredth, which is what the servers have been exporting all along.
Canopy did set the baseline from the first request, because its average started as nil; the
nil guard in adjustDuration: is unreachable now."
[ CanopyZincCounter reset.
CanopyZincCounter instance handleAnnouncement: (CanopyZincTestAnnouncement new responseCode: 200 duration: 10; yourself).
CanopyZincCounter instance handleAnnouncement: (CanopyZincTestAnnouncement new responseCode: 200 duration: 1000; yourself).
self assert: CanopyZincCounter instance duration equals: 10.
CanopyZincCounter instance handleAnnouncement: (CanopyZincTestAnnouncement new responseCode: 200 duration: 20; yourself).
self assert: CanopyZincCounter instance duration equals: (((99 * 10) + 20) / 100) asInteger ]
CanopyZincCounter instance handleAnnouncement: (CanopyZincTestAnnouncement new responseCode: 200 duration: 1000; yourself).
self assert: CanopyZincCounter instance duration equals: (((99 * 10) + 1000) / 100) asInteger ]
ensure: [ CanopyZincCounter reset ]
]

Expand Down
14 changes: 13 additions & 1 deletion source/Canopy-Metrics/CanopyZincCounter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ CanopyZincCounter >> increaseStatusCode: statusCode [
CanopyZincCounter >> initialize [
super initialize.
requests := 0.
responses := Dictionary new
duration := 0.
responses := Dictionary new.
self initializeResponses
]

{ #category : 'initialization' }
CanopyZincCounter >> initializeResponses [
"Seed the status codes the servers actually answer, so their series exist from the first
scrape instead of appearing out of nowhere with the first response of that kind. Same list
as pharo-metrics seeds today - a counter that starts at zero reads differently from one that
starts existing halfway through the day."
#( 200 201 202 204 301 302 400 401 403 404 405 500 502 503 504 ) do: [ :code |
responses at: code put: 0 ]
]

{ #category : 'installing' }
Expand Down
Loading