-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0866be
commit 1b3d721
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,52 @@ | ||
" | ||
I group spans with my `selector` block, sort them with my `comparator` (or do not sort if not provided), and keep only the top `count`. | ||
" | ||
Class { | ||
#name : 'OTelTopNQuery', | ||
#superclass : 'OTelQuery', | ||
#instVars : [ | ||
'comparator', | ||
'count' | ||
], | ||
#category : 'Famix-OpenTelemetry-Importer', | ||
#package : 'Famix-OpenTelemetry-Importer' | ||
} | ||
|
||
{ #category : 'accessing' } | ||
OTelTopNQuery >> comparator [ | ||
"If not specified, do not sort" | ||
|
||
^ comparator | ||
] | ||
|
||
{ #category : 'accessing' } | ||
OTelTopNQuery >> comparator: aTwoArgsBlock [ | ||
|
||
comparator := aTwoArgsBlock | ||
] | ||
|
||
{ #category : 'transforming' } | ||
OTelTopNQuery >> count [ | ||
|
||
^ count ifNil: [ count := 1 ] | ||
] | ||
|
||
{ #category : 'transforming' } | ||
OTelTopNQuery >> count: anInteger [ | ||
|
||
count := anInteger max: 1 | ||
] | ||
|
||
{ #category : 'transforming' } | ||
OTelTopNQuery >> value: model [ | ||
"Only keep the top n of each group in the model." | ||
|
||
(model allSpans groupedBy: self selector) do: [ :spans | | ||
| sortedSpans | | ||
sortedSpans := self comparator | ||
ifNil: [ spans ] | ||
ifNotNil: [ :comp | spans sorted: comp ]. | ||
self count + 1 to: spans size do: [ :i | | ||
self removeSpan: (sortedSpans at: i) ] ]. | ||
^ model | ||
] |