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

fix: slice init length #35848

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/filter/filterconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (mp *MatchProperties) ValidateForSpans() error {
if len(mp.SpanKinds) > 0 && mp.MatchType == "strict" {
for _, kind := range mp.SpanKinds {
if !spanKinds[kind] {
validSpanKinds := make([]string, len(spanKinds))
validSpanKinds := make([]string, 0, len(spanKinds))
for k := range spanKinds {
validSpanKinds = append(validSpanKinds, k)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/filter/filterspan/filterspan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestSpan_validateMatchesConfiguration_InvalidConfig(t *testing.T) {
},
Attributes: []filterconfig.Attribute{},
},
errorString: "span_kinds string must match one of the standard span kinds when match_type=strict: [ SPAN_KIND_CLIENT SPAN_KIND_CONSUMER SPAN_KIND_INTERNAL SPAN_KIND_PRODUCER SPAN_KIND_SERVER]",
errorString: "span_kinds string must match one of the standard span kinds when match_type=strict: [SPAN_KIND_CLIENT SPAN_KIND_CONSUMER SPAN_KIND_INTERNAL SPAN_KIND_PRODUCER SPAN_KIND_SERVER]",
},
}
for _, tc := range testcases {
Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sobjectsreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *Config) Validate() error {
for _, object := range c.Objects {
gvrs, ok := validObjects[object.Name]
if !ok {
availableResource := make([]string, len(validObjects))
availableResource := make([]string, 0, len(validObjects))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use case would be better improved if we set via an index instead of append.

Leaving availableResource := make([]string, len(validObjects)) but doing availableResource[i] = k feels the most efficient, since we know that every element in validObjects needs to end up in availableResource.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we know the validObjects is a map, so if we wanna set the value to the index of availableResource, we need a counter there, IMO append is good

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need to update availableResource @TylerHelmuth ?

for k := range validObjects {
availableResource = append(availableResource, k)
}
Expand Down