-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[exporter][batching] configuration and config validation for bytes based batching #12154
base: main
Are you sure you want to change the base?
[exporter][batching] configuration and config validation for bytes based batching #12154
Conversation
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (68.42%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #12154 +/- ##
==========================================
- Coverage 91.39% 91.35% -0.04%
==========================================
Files 468 469 +1
Lines 25598 25636 +38
==========================================
+ Hits 23395 23421 +26
- Misses 1787 1797 +10
- Partials 416 418 +2 ☔ View full report in Codecov by Sentry. |
exporter/exporterbatcher/config.go
Outdated
MinSizeItems int `mapstructure:"min_size_items"` | ||
MinSizeBytes int `mapstructure:"min_size_bytes"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we have a "Sizer"("SizerType") as enum with 3 values (request, items, bytes) and the "size" value instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. How about something like this:
type BatcherConfig struct {
...
minSize SizeConfig `mapstructure:"min_size"`
maxSize SizeConfig `mapstructure:"max_size"`
}
type SizeConfig struct {
sizer string `mapstructure:"sizer"`
size int `mapstructure:"size"`
}
func (c SizeConfig) validate() {
...
}
Does the option request
mean that the request will implement its own sizing method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need "sizer" in both min/max, since I don't think we need to accept different sizer for min and max.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to accept different sizer for min and max.
Good point. How about
type BatcherConfig struct {
...
sizer SizeType `mapstructure:",squash"`
minSize int `mapstructure:"max_size"`
maxSize int `mapstructure:"max_size"`
}
type SizerType struct {
sizer string `mapstructure:"sizer"`
}
func (c SizerType) validate() {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is "Sizer" a configuration string? What does it name, and how does the user configure it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of something that encapsulates better. How about
type SizeConfig struct {
Sizer string `mapstructure:"sizer"`
MinSize int `mapstructure:"mix_size"`
MaxSize int `mapstructure:"max_size"`
}
That way we can validate SizeConfig
pass it around as a whole.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmacd we are considering the options for the user Sizer -> "requests"|"items"|"bytes"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sfc-gh-sili still need an enum with possible values for Sizer
because usages of the SizeConfig
need to do different things based on different types of sizers.
PS: I like the SizeConfig, but would still keep the SizerType :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bogdandrutu Sounds good! I updated the config to have BatchConfig -> SizeConfig -> SizerType. Would you mind taking another look?
exporter/exporterbatcher/config.go
Outdated
err := c.SizeConfig.Validate() | ||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to call Validate, it is called automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks!
MinSize: 100, | ||
}, | ||
} | ||
require.EqualError(t, cfg.Validate(), "sizer should either be bytes or items") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test that it is called automatically, use component.ValidateConfig()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
exporter/exporterbatcher/config.go
Outdated
|
||
type SizerType struct { | ||
// Sizer should either be bytes or items. | ||
Sizer string `mapstructure:"sizer"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this private and create an UnmarshalText
(implement this interface https://pkg.go.dev/encoding#TextUnmarshaler). See https://github.com/open-telemetry/opentelemetry-collector/blob/main/pipeline/internal/globalsignal/signal.go
That way, we can control to only allow specific values.
exporter/exporterbatcher/config.go
Outdated
const SizerTypeItems = "items" | ||
const SizerTypeBytes = "bytes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they should be SizerType
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
exporter/exporterbatcher/config.go
Outdated
if c.Sizer != SizerTypeItems && c.Sizer != SizerTypeBytes { | ||
return errors.New("sizer should either be bytes or items") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this if you do what I suggest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I replaced Validate()
with TextUnmarshal
and updated the tests accordingly. Let me know if there is further issues
6669be4
to
a39ba31
Compare
5c51d8b
to
fd15914
Compare
357d13c
to
1fe0fe6
Compare
Description
This PR adds config API that will be used for serialized bytes based batching.
We will deprecate
MinSizeConfig
andMaxSizeConfig
in favor of:Link to tracking issue
#3262
#12303
Testing
Documentation