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
35 changes: 35 additions & 0 deletions source/Canopy-Core-Tests/CanopyDescriptionTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Class {
#name : 'CanopyDescriptionTest',
#superclass : 'TestCase',
#category : 'Canopy-Core-Tests',
#package : 'Canopy-Core-Tests'
}

{ #category : 'tests' }
CanopyDescriptionTest >> testABranchAndACellCarryADescription [
| branch cell |
branch := CanopyBranchNode new.
cell := CanopyCell new value: 1.
branch description: 'where the limits live'.
cell description: 'the maximum of open files'.
self assert: branch description equals: 'where the limits live'.
self assert: cell description equals: 'the maximum of open files'
]

{ #category : 'tests' }
CanopyDescriptionTest >> testAHolderCarriesADescriptionAndLabels [
| holder |
holder := CanopyValue value: 1.
holder description: 'what the component says'.
holder labelAt: #database put: 'alpha'.
self assert: holder description equals: 'what the component says'.
self assert: (holder labels at: #database) equals: 'alpha'
]

{ #category : 'tests' }
CanopyDescriptionTest >> testNothingIsDescribedUnlessSomeoneSaidSo [
self assert: CanopyBranchNode new description isNil.
self assert: (CanopyCell new value: 1) description isNil.
self assert: (CanopyValue value: 1) description isNil.
self assert: (CanopyValue value: 1) labels isEmpty
]
16 changes: 15 additions & 1 deletion source/Canopy-Core/CanopyNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Class {
#instVars : [
'parent',
'tags',
'labels'
'labels',
'description'
],
#category : 'Canopy-Core',
#package : 'Canopy-Core'
Expand All @@ -28,6 +29,19 @@ CanopyNode >> allKeys [
ifNil: [ #() ]
]

{ #category : 'accessing' }
CanopyNode >> description [
"What this node is for, declared where the tree is built. Branches, cells and accessors all
carry one. Nil when nobody said; the export then falls back to what the value holder of a
leaf brings along, and last to the key."
^ description
]

{ #category : 'accessing' }
CanopyNode >> description: aString [
description := aString
]

{ #category : 'accessing' }
CanopyNode >> fullKey [
^ '_' join: (self allKeys collect: [ :k | k asString ])
Expand Down
34 changes: 33 additions & 1 deletion source/Canopy-Core/CanopyValueHolder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ Class {
#name : 'CanopyValueHolder',
#superclass : 'Object',
#instVars : [
'value'
'value',
'description',
'labels'
],
#category : 'Canopy-Core',
#package : 'Canopy-Core'
Expand All @@ -22,6 +24,36 @@ CanopyValueHolder >> asCanopyValue [
^ self
]

{ #category : 'accessing' }
CanopyValueHolder >> description [
"What the component itself says this value is for. A description on the node wins over
this one - see CanopyNode>>description - so this is the fallback a component brings along."
^ description
]

{ #category : 'accessing' }
CanopyValueHolder >> description: aString [
description := aString
]

{ #category : 'initialization' }
CanopyValueHolder >> initialize [
super initialize.
labels := Dictionary new
]

{ #category : 'accessing' }
CanopyValueHolder >> labelAt: aKey put: anObject [
"A label the component itself knows, as opposed to one the tree carries - the stage of a
deployment hangs at the root, the database a number belongs to is known here."
labels at: aKey put: anObject
]

{ #category : 'accessing' }
CanopyValueHolder >> labels [
^ labels
]

{ #category : 'printing' }
CanopyValueHolder >> printOn: aStream [
super printOn: aStream.
Expand Down
14 changes: 14 additions & 0 deletions source/Canopy-Metrics-Tests/CanopyDeclaredMetricTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ CanopyDeclaredMetricTest >> setUp [
branch := root /+ #server
]

{ #category : 'tests' }
CanopyDeclaredMetricTest >> testTheNodeDescriptionBeatsTheOneOfTheHolder [
"The node is the declaration made where the tree is built, the holder only what the component
brings along when it is read - so the node wins, and the holder answers only where the node
says nothing."
| described |
branch counter: #requests description: 'from the holder' reading: [ 3 ].
branch counter: #errors description: 'from the holder' reading: [ 1 ].
described := branch / #requests.
described description: 'from the node'.
self assert: (self scrape includesSubstring: '# HELP server_requests from the node').
self assert: (self scrape includesSubstring: '# HELP server_errors from the holder')
]

{ #category : 'tests' }
CanopyDeclaredMetricTest >> testACounterIsWrittenAsOne [
branch counter: #requests description: 'requests served' reading: [ 3 ].
Expand Down
32 changes: 1 addition & 31 deletions source/Canopy-Metrics/CanopyMetric.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,12 @@ Class {
#name : 'CanopyMetric',
#superclass : 'CanopyValueHolder',
#instVars : [
'type',
'description',
'labels'
'type'
],
#category : 'Canopy-Metrics',
#package : 'Canopy-Metrics'
}

{ #category : 'accessing' }
CanopyMetric >> description [
^ description
]

{ #category : 'accessing' }
CanopyMetric >> description: aString [
description := aString
]

{ #category : 'initialization' }
CanopyMetric >> initialize [
super initialize.
labels := Dictionary new
]

{ #category : 'accessing' }
CanopyMetric >> labelAt: aKey put: anObject [
"A label the component itself knows, as opposed to one the tree carries - the stage of a
deployment hangs at the root, the database a number belongs to is known here."
labels at: aKey put: anObject
]

{ #category : 'accessing' }
CanopyMetric >> labels [
^ labels
]

{ #category : 'enumerating' }
CanopyMetric >> readingsDo: aBlock [
"One reading: the labels this metric knows itself, and its value. Whatever the tree adds is
Expand Down
3 changes: 2 additions & 1 deletion source/Canopy-Metrics/CanopyPrometheusVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ CanopyPrometheusVisitor >> writeHelpLine: aNode holder: aMetric [
nextPutAll: '# HELP ';
nextPutAll: (self convertMetricName: aNode);
nextPutAll: ' '.
stream nextPutAll: (aMetric description ifNil: [ aNode key asString ]).
stream nextPutAll: (aNode description
ifNil: [ aMetric description ifNil: [ aNode key asString ] ]).
stream nextPut: Character linefeed
]

Expand Down
Loading