Skip to content

Commit 250a1ca

Browse files
authored
[consumer/consumertest] Add ProfileCount() (#14251)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description In #14239 `(Profiles)ProfileCount() int` was introduced. Provide this function also in consumertests for other tests. <!-- Issue number if applicable --> #### Link to tracking issue Fixes # <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> --------- Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
1 parent 54ac205 commit 250a1ca

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

.chloggen/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ components:
1313
- connector/forward
1414
- connector/sample
1515
- consumer/consumererror/xconsumererror
16-
- consumer/consumertest
1716
- consumer/xconsumer
1817
- docs/rfcs
1918
- exporter/debug
@@ -38,6 +37,7 @@ components:
3837
- pkg/config/configtelemetry
3938
- pkg/config/configtls
4039
- pkg/confmap
40+
- pkg/consumer/consumertest
4141
- pkg/exporterhelper
4242
- pkg/otelcol
4343
- pkg/pdata
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp)
7+
component: pkg/consumer/consumertest
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add ProfileCount()
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14251]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

consumer/consumertest/sink.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,11 @@ func (sle *LogsSink) Contexts() []context.Context {
201201
// stores all profiles and allows querying them for testing.
202202
type ProfilesSink struct {
203203
nonMutatingConsumer
204-
mu sync.Mutex
205-
profiles []pprofile.Profiles
206-
contexts []context.Context
207-
sampleCount int
204+
mu sync.Mutex
205+
profiles []pprofile.Profiles
206+
contexts []context.Context
207+
sampleCount int
208+
profileCount int
208209
}
209210

210211
var _ xconsumer.Profiles = (*ProfilesSink)(nil)
@@ -217,6 +218,7 @@ func (ste *ProfilesSink) ConsumeProfiles(ctx context.Context, td pprofile.Profil
217218
ste.profiles = append(ste.profiles, td)
218219
ste.contexts = append(ste.contexts, ctx)
219220
ste.sampleCount += td.SampleCount()
221+
ste.profileCount += td.ProfileCount()
220222

221223
return nil
222224
}
@@ -231,13 +233,20 @@ func (ste *ProfilesSink) AllProfiles() []pprofile.Profiles {
231233
return copyProfiles
232234
}
233235

234-
// SampleCount returns the number of profiles stored by this sink since last Reset.
236+
// SampleCount returns the number of samples stored by this sink since last Reset.
235237
func (ste *ProfilesSink) SampleCount() int {
236238
ste.mu.Lock()
237239
defer ste.mu.Unlock()
238240
return ste.sampleCount
239241
}
240242

243+
// ProfileCount returns the number of profiles stored by this sink since last Reset.
244+
func (ste *ProfilesSink) ProfileCount() int {
245+
ste.mu.Lock()
246+
defer ste.mu.Unlock()
247+
return ste.profileCount
248+
}
249+
241250
// Reset deletes any stored data.
242251
func (ste *ProfilesSink) Reset() {
243252
ste.mu.Lock()
@@ -246,6 +255,7 @@ func (ste *ProfilesSink) Reset() {
246255
ste.profiles = nil
247256
ste.contexts = nil
248257
ste.sampleCount = 0
258+
ste.profileCount = 0
249259
}
250260

251261
// Contexts returns the contexts stored by this sink since last Reset.

consumer/consumertest/sink_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ func TestProfilesSink(t *testing.T) {
7878
want = append(want, td)
7979
}
8080
assert.Equal(t, want, sink.AllProfiles())
81+
// Each Profile in Profiles holds a single sample.
82+
// So SampleCount() equals ProfileCount() in this case.
8183
assert.Equal(t, len(want), sink.SampleCount())
84+
assert.Equal(t, len(want), sink.ProfileCount())
8285
sink.Reset()
8386
assert.Empty(t, sink.AllProfiles())
84-
assert.Empty(t, sink.SampleCount())
87+
assert.Equal(t, 0, sink.SampleCount())
88+
assert.Equal(t, 0, sink.ProfileCount())
8589
}
8690

8791
func TestTracesSinkWithContext(t *testing.T) {

0 commit comments

Comments
 (0)