-
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
Remove AttributeKeyValue, make map insert/upsert safe by copying the given value #781
Conversation
bogdandrutu
commented
Apr 4, 2020
- Fix a bug in the setters for AttributeValue, the setter needs to overwrite the previous value with the default value.
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #781 +/- ##
==========================================
- Coverage 85.54% 85.49% -0.05%
==========================================
Files 155 155
Lines 11523 11547 +24
==========================================
+ Hits 9857 9872 +15
Misses 1295 1295
- Partials 371 380 +9
Continue to review full report at Codecov.
|
a.copyValues(emptyAttributeKeyValue) | ||
a.orig.Type = otlpcommon.AttributeKeyValue_STRING | ||
a.orig.StringValue = v |
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.
Alternatively it is possible to do:
*a.orig = otlpcommon.AttributeKeyValue{Type:..., StringValue...}
This seems shorter and no need for copyValue call or for emptyAttributeKeyValue var.
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.
Tried this idea:
func (a AttributeValue) SetStringVal(v string) {
*a.orig = otlpcommon.AttributeKeyValue{Key: a.orig.Key, Type: otlpcommon.AttributeKeyValue_STRING, StringValue: v}
}
func (a AttributeValue) SetIntVal(v int64) {
*a.orig = otlpcommon.AttributeKeyValue{Key: a.orig.Key, Type: otlpcommon.AttributeKeyValue_INT, IntValue: v}
}
func (a AttributeValue) SetDoubleVal(v float64) {
*a.orig = otlpcommon.AttributeKeyValue{Key: a.orig.Key, Type: otlpcommon.AttributeKeyValue_DOUBLE, DoubleValue: v}
}
func (a AttributeValue) SetBoolVal(v bool) {
*a.orig = otlpcommon.AttributeKeyValue{Key: a.orig.Key, Type: otlpcommon.AttributeKeyValue_BOOL, BoolValue: v}
}
Benchmarks with your proposal:
goos: darwin
goarch: amd64
pkg: github.com/open-telemetry/opentelemetry-collector/internal/data
BenchmarkSetIntVal
BenchmarkSetIntVal-16 346741474 3.50 ns/op
PASS
Process finished with exit code 0
Benchmarks with current implementation:
goos: darwin
goarch: amd64
pkg: github.com/open-telemetry/opentelemetry-collector/internal/data
BenchmarkSetIntVal
BenchmarkSetIntVal-16 601141042 1.93 ns/op
PASS
Process finished with exit code 0
Should we worry about this? Happy to change if you think makes code better.
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.
Strange. Let's keep your code, it is fine. This may be a frequent operation so let's not loose performance.
|
||
// Insert adds the string Value to the map when the key does not exist. | ||
// No action is applied to the map where the key already exists. | ||
func (am AttributeMap) InsertString(k string, v string) { |
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 is the benefit of using InsertString vs Insert?
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 do an extra allocation of the AttributeValue that will be thrown away anyway.
@tigrannajaryan PTAL |
* Typo * Swap order of ddsketch.New for consistency w/ histogram.New