-
Notifications
You must be signed in to change notification settings - Fork 2.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
[processor/spanmetrics] Support for specifying Resource Attributes on metrics generated from traces #6717
Closed
Tenaria
wants to merge
38
commits into
open-telemetry:main
from
atlassian-forks:OBC-256-Resource-Attributes-Merge-Upstream
Closed
[processor/spanmetrics] Support for specifying Resource Attributes on metrics generated from traces #6717
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
f5553a1
starts initial work on optional resource attributes config to span me…
Tenaria f186407
adds test to check metric length when copying resources
Tenaria 3206a11
adds changelog and fixes tests
Tenaria 3da4719
Merge branch 'main' into OBC-256-Resource-Attributes-Merge-Upstream
Tenaria 945a6d1
fix tests
Tenaria fc62eab
remove empty new line
Tenaria 07b5ad3
updates changelog
Tenaria 5782cb0
add accidentally removed comment back in
Tenaria e2eb41d
revert variable name change and fix comment
Tenaria 321c6e2
revert variable name cahnge
Tenaria fb0561c
adds test to ensure ordering of keys used for aggregation
Tenaria 80ebf64
fixes lock held; optimise for loop; add parallel in test; add comments
Tenaria 19775dc
reverse conditions to simplify code
Tenaria 8c2d38e
update tests to use defined constant instrumentationLibraryName
Tenaria cbbf532
Merge branch 'main' into OBC-256-Resource-Attributes-Merge-Upstream
chenzhihao 91c8b7d
update the logic of method updateCallMetrics
chenzhihao 068a1bd
fix tests
chenzhihao 18f20d0
add todos
chenzhihao 4d370ad
add todos
chenzhihao 024a122
Merge branch 'main' into OBC-256-Resource-Attributes-Merge-Upstream
chenzhihao 7561f97
fix lint
chenzhihao 62e892f
fix lint
chenzhihao d8edfda
remove resourceAttrList
chenzhihao d175a4e
Update "resource_attributes"
chenzhihao 608a083
fix lint
chenzhihao a0519c0
remove duplicate p.resetExemplarData()
chenzhihao 9772056
refactor how processor reset after every ConsumeTraces process
chenzhihao ae17b37
move keybuilder to a package
chenzhihao 8ea124c
update comments
chenzhihao 78c11f3
add copyright license
chenzhihao fbea55f
user defer for p.reset() so that downstream components can get data q…
chenzhihao 3d6b4c1
gofmt
chenzhihao fd42b76
refactor how we use p.lock
chenzhihao 7ed4b1c
gofmt
chenzhihao f676e46
added a set of unit tests to cover the excessive concurrent usage
chenzhihao 4b71675
change the usage of the lock to make sure the processor can only be e…
chenzhihao 494b483
Merge branch 'main' into OBC-256-Resource-Attributes-Merge-Upstream
chenzhihao 38ebb2a
add comments; lint
chenzhihao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package keybuilder // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/spanmetricsprocessor/keybuilder" | ||
|
||
import "strings" | ||
|
||
const ( | ||
separator = string(byte(0)) | ||
defaultCapacity = 1024 | ||
) | ||
|
||
type KeyBuilder interface { | ||
Append(value ...string) | ||
String() string | ||
} | ||
|
||
type keyBuilder struct { | ||
sb strings.Builder | ||
separator string | ||
} | ||
|
||
func New() KeyBuilder { | ||
b := keyBuilder{ | ||
sb: strings.Builder{}, | ||
separator: separator, | ||
} | ||
b.sb.Grow(defaultCapacity) | ||
return &b | ||
} | ||
|
||
func (mkb *keyBuilder) Append(values ...string) { | ||
for _, value := range values { | ||
if len(value) == 0 { | ||
continue | ||
} | ||
if mkb.sb.Len() != 0 { | ||
mkb.sb.WriteString(mkb.separator) | ||
} | ||
// It's worth noting that from pprof benchmarks, WriteString is the most expensive operation of this processor. | ||
// Specifically, the need to grow the underlying []byte slice to make room for the appended string. | ||
mkb.sb.WriteString(value) | ||
} | ||
} | ||
|
||
func (mkb *keyBuilder) String() string { | ||
return mkb.sb.String() | ||
} |
58 changes: 58 additions & 0 deletions
58
processor/spanmetricsprocessor/keybuilder/keybuilder_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package keybuilder | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
t.Run("should create new keybuilder", func(t *testing.T) { | ||
assert.NotPanics(t, func() { | ||
assert.NotNil(t, New()) | ||
}) | ||
}) | ||
} | ||
|
||
func Test_metricKeyBuilder_Append(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args [][]string | ||
result string | ||
}{ | ||
{ | ||
name: "should skip empty string", | ||
args: [][]string{{"", "abc", "", "def"}}, | ||
result: fmt.Sprintf("abc%sdef", separator), | ||
}, | ||
{ | ||
name: "should concat multiple append", | ||
args: [][]string{{"abc", "def"}, {"", "hij"}}, | ||
result: fmt.Sprintf("abc%sdef%shij", separator, separator), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
kb := New() | ||
for _, arg := range tt.args { | ||
kb.Append(arg...) | ||
} | ||
assert.Equal(t, tt.result, kb.String()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 you need to update the changelog, the maintainers will do this upon a new release
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 saw in Zhihao's PR that there was a changelog added (see comment #6503 (review)). @MovieStoreGuy can you confirm whether we update the changelog or the maintainers do?
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 think it is fine for us to update the changelog, we have the greatest overall idea of what has changed so I think it makes sense to add it. However, If a maintainer says otherwise, I am also fine with 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.
We would definitely prefer that you add a changelog entry, and there is CI automation that will complain if you don't! It generally makes it easier for us to prepare releases when we don't need to track down all the changes that have been made and think about how to describe them.