Skip to content
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

Merged
merged 1 commit into from Apr 7, 2020

Conversation

bogdandrutu
Copy link
Member

  • 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>
@bogdandrutu bogdandrutu changed the title Remove AttributeKeyValue, make update methods safe Remove AttributeKeyValue, make map insert/upsert safe by copying the given value Apr 4, 2020
@codecov-io
Copy link

Codecov Report

Merging #781 into master will decrease coverage by 0.04%.
The diff coverage is 80.64%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
translator/internaldata/oc_to_traces.go 82.38% <44.44%> (ø)
translator/internaldata/traces_to_oc.go 79.34% <66.66%> (ø)
internal/data/common.go 90.36% <83.69%> (-4.48%) ⬇️
translator/internaldata/resource_to_oc.go 71.01% <85.71%> (ø)
translator/internaldata/oc_to_resource.go 91.89% <90.00%> (ø)
receiver/opencensusreceiver/octrace/opencensus.go 93.33% <0.00%> (+3.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84326d9...0f3c3a5. Read the comment docs.

Comment on lines +114 to 116
a.copyValues(emptyAttributeKeyValue)
a.orig.Type = otlpcommon.AttributeKeyValue_STRING
a.orig.StringValue = v
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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) {
Copy link
Member

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?

Copy link
Member Author

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.

@bogdandrutu
Copy link
Member Author

@tigrannajaryan PTAL

@tigrannajaryan tigrannajaryan merged commit dbc92d6 into open-telemetry:master Apr 7, 2020
@bogdandrutu bogdandrutu deleted the newapimaps branch August 5, 2020 18:50
MovieStoreGuy pushed a commit to atlassian-forks/opentelemetry-collector that referenced this pull request Nov 11, 2021
* Typo

* Swap order of ddsketch.New for consistency w/ histogram.New
hughesjj pushed a commit to hughesjj/opentelemetry-collector that referenced this pull request Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants