Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Record which direction the resource was blocked #72

Merged
merged 2 commits into from
Jul 27, 2022
Merged
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
12 changes: 10 additions & 2 deletions obs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,22 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
// Drop the connection or stream id
scopeName = strings.SplitN(scopeName, "-", 2)[0]

// If something else gets added here, make sure to update the size hint
// below when we make `tagsWithDir`.
tags := []tag.Mutator{tag.Upsert(scopeTag, scopeName), tag.Upsert(resourceTag, resource)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to allocate a slice of length 3 here, so the append later doesn't cause any allocs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm actually not appending to this slice. I make another slice of tags in case the event has both delta in/out (I don't think we are doing this anywhere but we can't assume we will never do this).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I allocated the other slices upfront so maybe they'll be on the stack and not cause a heap alloc. Based on this SO answer/related tweet it seems like the Go 1.17 runtime (and above?) will do stack allocations here.

I couldn't find any official documentation around this though.


if evt.DeltaIn != 0 {
stats.RecordWithTags(ctx, tags, blockedResources.M(int64(1)))
tagsWithDir := make([]tag.Mutator, 3)
tagsWithDir = append(tagsWithDir, tag.Insert(directionTag, "inbound"))
tagsWithDir = append(tagsWithDir, tags...)
stats.RecordWithTags(ctx, tagsWithDir[0:], blockedResources.M(int64(1)))
}

if evt.DeltaOut != 0 {
stats.RecordWithTags(ctx, tags, blockedResources.M(int64(1)))
tagsWithDir := make([]tag.Mutator, 3)
tagsWithDir = append(tagsWithDir, tag.Insert(directionTag, "outbound"))
tagsWithDir = append(tagsWithDir, tags...)
stats.RecordWithTags(ctx, tagsWithDir, blockedResources.M(int64(1)))
}

if evt.Delta != 0 {
Expand Down