Skip to content

Commit

Permalink
Change size and capacity to explicit int64
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jan 11, 2025
1 parent 7f4664e commit 20b2c53
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 70 deletions.
25 changes: 25 additions & 0 deletions .chloggen/mv-int64.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: exporterqueue

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Change Queue Size and Capacity to return explicit int64.

# One or more tracking issues or pull requests related to the change
issues: [12076]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
4 changes: 2 additions & 2 deletions exporter/exporterhelper/internal/queue_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (qs *QueueSender) Start(ctx context.Context, host component.Host) error {

dataTypeAttr := attribute.String(DataTypeKey, qs.obsrep.Signal.String())

reg1, err1 := qs.obsrep.TelemetryBuilder.InitExporterQueueSize(func() int64 { return int64(qs.queue.Size()) },
reg1, err1 := qs.obsrep.TelemetryBuilder.InitExporterQueueSize(func() int64 { return qs.queue.Size() },
metric.WithAttributeSet(attribute.NewSet(qs.traceAttribute, dataTypeAttr)))

if reg1 != nil {
Expand All @@ -140,7 +140,7 @@ func (qs *QueueSender) Start(ctx context.Context, host component.Host) error {
})
}

reg2, err2 := qs.obsrep.TelemetryBuilder.InitExporterQueueCapacity(func() int64 { return int64(qs.queue.Capacity()) },
reg2, err2 := qs.obsrep.TelemetryBuilder.InitExporterQueueCapacity(func() int64 { return qs.queue.Capacity() },
metric.WithAttributeSet(attribute.NewSet(qs.traceAttribute)))

if reg2 != nil {
Expand Down
2 changes: 1 addition & 1 deletion exporter/exporterhelper/internal/queue_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestQueuedRetry_StopWhileWaiting(t *testing.T) {
require.NoError(t, be.Send(context.Background(), secondMockR))
})

require.LessOrEqual(t, 1, be.QueueSender.(*QueueSender).queue.Size())
require.LessOrEqual(t, int64(1), be.QueueSender.(*QueueSender).queue.Size())

require.NoError(t, be.Shutdown(context.Background()))

Expand Down
10 changes: 5 additions & 5 deletions exporter/exporterqueue/bounded_memory_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func TestBoundedQueue(t *testing.T) {
return nil
}))
assert.Equal(t, 1, numConsumed)
assert.Equal(t, 0, q.Size())
assert.Equal(t, int64(0), q.Size())

// produce two more items. The first one should be accepted, but not consumed.
require.NoError(t, q.Offer(context.Background(), "b"))
assert.Equal(t, 1, q.Size())
assert.Equal(t, int64(1), q.Size())

// the second should be rejected since the queue is full
require.ErrorIs(t, q.Offer(context.Background(), "c"), ErrQueueIsFull)
assert.Equal(t, 1, q.Size())
assert.Equal(t, int64(1), q.Size())

assert.True(t, consume(q, func(_ context.Context, item string) error {
assert.Equal(t, "b", item)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestShutdownWhileNotEmpty(t *testing.T) {
}
assert.NoError(t, q.Shutdown(context.Background()))

assert.Equal(t, 10, q.Size())
assert.Equal(t, int64(10), q.Size())
numConsumed := 0
for i := 0; i < 10; i++ {
assert.True(t, consume(q, func(_ context.Context, item string) error {
Expand All @@ -92,7 +92,7 @@ func TestShutdownWhileNotEmpty(t *testing.T) {
}))
}
assert.Equal(t, 10, numConsumed)
assert.Equal(t, 0, q.Size())
assert.Equal(t, int64(0), q.Size())

assert.False(t, consume(q, func(_ context.Context, item string) error {
panic(item)
Expand Down
8 changes: 4 additions & 4 deletions exporter/exporterqueue/persistent_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ func (pq *persistentQueue[T]) Start(ctx context.Context, host component.Host) er
return nil
}

func (pq *persistentQueue[T]) Size() int {
func (pq *persistentQueue[T]) Size() int64 {
pq.mu.Lock()
defer pq.mu.Unlock()
return int(pq.queueSize)
return pq.queueSize
}

func (pq *persistentQueue[T]) Capacity() int {
return int(pq.set.capacity)
func (pq *persistentQueue[T]) Capacity() int64 {
return pq.set.capacity

Check warning on line 122 in exporter/exporterqueue/persistent_queue.go

View check run for this annotation

Codecov / codecov/patch

exporter/exporterqueue/persistent_queue.go#L121-L122

Added lines #L121 - L122 were not covered by tests
}

func (pq *persistentQueue[T]) initClient(ctx context.Context, client storage.Client) {
Expand Down
Loading

0 comments on commit 20b2c53

Please sign in to comment.