Skip to content

Commit 451d1d2

Browse files
authored
Add validation error when queue_size smaller than batch.min_size (#12949)
<!-- Issue number if applicable --> #### Link to tracking issue Fixes #12948 Signed-off-by: Israel Blancas <[email protected]>
1 parent c4b6423 commit 451d1d2

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

.chloggen/12948.yaml

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: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: exporterhelper
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Add validation error for batch config if min_size is greater than queue_size."
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12948]
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: []

exporter/exporterhelper/internal/queuebatch/config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,16 @@ func (cfg *Config) Validate() error {
9292
return errors.New("persistent queue configured with `storage` only supports `requests` sizer")
9393
}
9494

95-
// Only support items sizer for batch at this moment.
96-
if cfg.Batch != nil && (cfg.Sizer != request.SizerTypeItems && cfg.Sizer != request.SizerTypeBytes) {
97-
return errors.New("`batch` supports only `items` or `bytes` sizer")
95+
if cfg.Batch != nil {
96+
// Only support items or bytes sizer for batch at this moment.
97+
if cfg.Sizer != request.SizerTypeItems && cfg.Sizer != request.SizerTypeBytes {
98+
return errors.New("`batch` supports only `items` or `bytes` sizer")
99+
}
100+
101+
// Avoid situations where the queue is not able to hold any data.
102+
if cfg.Batch.MinSize > cfg.QueueSize {
103+
return errors.New("`min_size` must be less than or equal to `queue_size`")
104+
}
98105
}
99106

100107
return nil

exporter/exporterhelper/internal/queuebatch/config_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func TestConfig_Validate(t *testing.T) {
5050
cfg.Sizer = request.SizerTypeRequests
5151
require.EqualError(t, cfg.Validate(), "`batch` supports only `items` or `bytes` sizer")
5252

53+
cfg = newTestConfig()
54+
cfg.QueueSize = cfg.Batch.MinSize - 1
55+
require.EqualError(t, cfg.Validate(), "`min_size` must be less than or equal to `queue_size`")
56+
5357
cfg = newTestConfig()
5458
cfg.Sizer = request.SizerTypeBytes
5559
require.NoError(t, cfg.Validate())

0 commit comments

Comments
 (0)