Skip to content

Commit 3c46505

Browse files
committed
pfp: separate recorders options
Place Recorder and NodeRecorder options in one file for easier navigation. Signed-off-by: Shereen Haj <shajmakh@redhat.com>
1 parent 7377133 commit 3c46505

2 files changed

Lines changed: 67 additions & 48 deletions

File tree

pkg/pfpstatus/record/options.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package record
18+
19+
import "time"
20+
21+
type Option func(*Recorder)
22+
23+
func WithNodeCapacity(nodeCapacity int) Option {
24+
return func(rec *Recorder) {
25+
rec.nodeCapacity = nodeCapacity
26+
}
27+
}
28+
29+
func WithNodeTimestamper(tsr func() time.Time) Option {
30+
return func(rec *Recorder) {
31+
rec.timestamper = tsr
32+
}
33+
}
34+
35+
func WithMaxNodes(maxNodes int) Option {
36+
return func(rec *Recorder) {
37+
rec.maxNodes = maxNodes
38+
}
39+
}
40+
41+
func WithPFPCoalescing(val bool) Option {
42+
return func(rr *Recorder) {
43+
rr.coalesceLast = val
44+
}
45+
}
46+
47+
type NodeOption func(*NodeRecorder)
48+
49+
func WithCapacity(capacity int) NodeOption {
50+
return func(nr *NodeRecorder) {
51+
nr.capacity = capacity
52+
}
53+
}
54+
55+
func WithTimestamper(tsr func() time.Time) NodeOption {
56+
return func(nr *NodeRecorder) {
57+
nr.timestamper = tsr
58+
}
59+
}
60+
61+
func WithCoalescing(val bool) NodeOption {
62+
return func(nr *NodeRecorder) {
63+
nr.coalesceLast = val
64+
}
65+
}

pkg/pfpstatus/record/recorder.go

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,6 @@ type NodeRecorder struct {
5959
coalesceLast bool
6060
}
6161

62-
type NodeOption func(*NodeRecorder)
63-
64-
func WithCapacity(capacity int) NodeOption {
65-
return func(nr *NodeRecorder) {
66-
nr.capacity = capacity
67-
}
68-
}
69-
70-
func WithTimestamper(tsr func() time.Time) NodeOption {
71-
return func(nr *NodeRecorder) {
72-
nr.timestamper = tsr
73-
}
74-
}
75-
76-
func WithCoalescing(val bool) NodeOption {
77-
return func(nr *NodeRecorder) {
78-
nr.coalesceLast = val
79-
}
80-
}
81-
8262
// NewNodeRecorder creates a new recorder for the given node with the given capacity.
8363
// The record is a ring buffer, so only the latest <capacity> Statuses are kept at any time.
8464
// The timestamper callback is used to mark times. Use `time.Now` if unsure.
@@ -161,7 +141,7 @@ func (nr *NodeRecorder) Cap() int {
161141
return nr.capacity
162142
}
163143

164-
// Content() returns a shallow copy of all the recorded statuses.
144+
// Content returns a shallow copy of all the recorded statuses.
165145
func (nr *NodeRecorder) Content() []RecordedStatus {
166146
return nr.statuses
167147
}
@@ -181,32 +161,6 @@ type Recorder struct {
181161
coalesceLast bool
182162
}
183163

184-
type Option func(*Recorder)
185-
186-
func WithNodeCapacity(nodeCapacity int) Option {
187-
return func(rec *Recorder) {
188-
rec.nodeCapacity = nodeCapacity
189-
}
190-
}
191-
192-
func WithNodeTimestamper(tsr func() time.Time) Option {
193-
return func(rec *Recorder) {
194-
rec.timestamper = tsr
195-
}
196-
}
197-
198-
func WithMaxNodes(maxNodes int) Option {
199-
return func(rec *Recorder) {
200-
rec.maxNodes = maxNodes
201-
}
202-
}
203-
204-
func WithPFPCoalescing(val bool) Option {
205-
return func(rr *Recorder) {
206-
rr.coalesceLast = val
207-
}
208-
}
209-
210164
// NewRecorder creates a new recorder up to the given node count, each with the given capacity.
211165
// Each per-node recorder is a ring buffer, so only the latest <nodeCapacity> Statuses are kept
212166
// at any time for each node. The per-node records are created lazily as needed.
@@ -298,7 +252,7 @@ func (rr *Recorder) Push(st podfingerprint.Status) error {
298252
return nr.Push(st)
299253
}
300254

301-
// Content() returns a shallow copy of all the recorded statuses, by node name.
255+
// Content returns a shallow copy of all the recorded statuses, by node name.
302256
func (rr *Recorder) Content() map[string][]RecordedStatus {
303257
ret := make(map[string][]RecordedStatus, len(rr.nodes))
304258
for nodeName, nr := range rr.nodes {

0 commit comments

Comments
 (0)