-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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: crrect initialization of a few slices #12674
Conversation
@@ -269,7 +269,7 @@ func (q *IngesterQuerier) TailersCount(ctx context.Context) ([]uint32, error) { | |||
return nil, err | |||
} | |||
|
|||
counts := make([]uint32, len(responses)) |
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.
this seems like a good change, AFAICT atm we could be allocating # of ingesters * 2
uint32's since we could have a response from every ingester
@@ -305,7 +305,7 @@ func (c *IndexReaderWriter) chunksToSeries(ctx context.Context, in []logproto.Ch | |||
return nil, err | |||
} | |||
|
|||
results := make([]labels.Labels, len(chunksBySeries)) // Flatten out the per-job results. | |||
results := make([]labels.Labels, 0, len(chunksBySeries)) // Flatten out the per-job results. |
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.
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.
No, len(chunksBySeries)
looks correct. I also feel len(perJobResults)
is correct at first sight.
Actually, argument of append
is innerSlice...
, not innerSlice
. And sum of their length is probably len(chunkBySeries)
(groups := make([]chunkGroup, 0, len(chunksBySeries)/c.chunkBatchSize+1
).
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.
Ah you're right, I misread the append line 👍 good find
Thank you for kindful & speedy review! |
What this PR does / why we need it:
I found suspicious slice initialization so fixed them.
These slices are initialized by
make([]type, size)
. But their contents are filled byslice = append(slice, newElem)
. It should result leading zero values.Say,
will result
xs = []int{0, 0, 0, 1, 2, 3}
. Probably it's unintentional and meansWhich issue(s) this PR fixes:
N/A. I consider it's a trivial fix.
Special notes for your reviewer:
Feel free to reject this PR.I'm sorry but I'm not familiar with Loki. I found it just scanning Loki with my experimental static checker.
I've read codes around these lines and callers of them. I suppose that they have confusion between length and capacity but I don't understand what they do in context of entire application.
Anyway, I suppose leading zero values look unintentional and tests pass.
Checklist
CONTRIBUTING.md
guide (required)Documentation addeddocs/sources/setup/upgrade/_index.md
For Helm chart changes bump the Helm chart version inproduction/helm/loki/Chart.yaml
and updateproduction/helm/loki/CHANGELOG.md
andproduction/helm/loki/README.md
. Example PRIf the change is deprecating or removing a configuration option, update thedeprecated-config.yaml
anddeleted-config.yaml
files respectively in thetools/deprecated-config-checker
directory. Example PR