Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

honey: replace no-op event with new NonSendingEvent that stores fields in memory#61854

Merged
ggilmore merged 1 commit into
mainfrom
spr/main/12b8f3ad
Apr 13, 2024
Merged

honey: replace no-op event with new NonSendingEvent that stores fields in memory#61854
ggilmore merged 1 commit into
mainfrom
spr/main/12b8f3ad

Conversation

@ggilmore

@ggilmore ggilmore commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Fixes: https://github.com/sourcegraph/sourcegraph/issues/60726


When honeycomb wasn't enabled, we use a noop Event type everywhere. However, there are some places where we'd like to inspect or log the event regardless of whether or not honeycomb is enabled, like the following code in gitserver.

https://github.com/sourcegraph/sourcegraph/blob/ee9199762853c10e6a737f341ceb0808ceca20ea/cmd/gitserver/internal/git/gitcli/command.go#L280-L286

Our use of the noop type, resulted in unexpected behavior - such as the ev.Fields in the log line not getting populated (https://github.com/sourcegraph/sourcegraph/issues/60726).

This PR fixes this issue by replacing the noop event type a new NonSendingEvent which still allows Fields to be aggregated in memory and later retrieved with Fields(). This ensures that use cases like the logging one above still work as expected.

Test plan

Unit tests

Also saw the following logs when I ran sourcegraph with SRC_DEVELOPMENT=false SRC_LOG_FORMAT=json sg start (notice that ev.Fields is no-longer null).

[    gitserver-0] {"SeverityText":"WARN","Timestamp":1712965049496465000,"InstrumentationScope":"gitserver","Caller":"gitcli/command.go:286","Function":"github.com/sourcegraph/sourcegraph/cmd/gitserver/internal/git/gitcli.(*cmdReader).trace","Body":"Long exec request","Resource":{"service.name":"gitserver","service.version":"0.0.0+dev","service.instance.id":"127.0.0.1:3178"},"TraceId":"db86930d642952fd9b2dd3df0ec7e380","SpanId":"e41abbebd5b8c832","Attributes":{"ev.Fields":{"cmd":"config","args":"[git config sourcegraph.type git]","duration_ms":"6","exit_status":"0","user_time":"1.957ms","traceID":"db86930d642952fd9b2dd3df0ec7e380","trace":"https://sourcegraph.test:3443/-/debug/jaeger/trace/db86930d642952fd9b2dd3df0ec7e380","repo":"github.com/sourcegraph/deploy-sourcegraph","actor":"0","cmd_duration_ms":"6","system_time":"2.311ms"}}}

@cla-bot cla-bot Bot added the cla-signed label Apr 12, 2024
@github-actions github-actions Bot added team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all labels Apr 12, 2024
@ggilmore ggilmore force-pushed the spr/main/12b8f3ad branch from 878ab53 to 885b541 Compare April 12, 2024 23:57
@ggilmore ggilmore requested a review from a team April 13, 2024 00:00
Comment thread internal/honey/event.go Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't use the Add function anywhere in the codebase. Simply removing this from the interface means that we don't have to re-implement this unnecessarily.

Comment thread internal/honey/non_sending.go Outdated
Comment on lines 30 to 37

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does the event need to be concurrency safe? would the real event be safe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, that's a good call out. Funnily enough, the event type from libhoney is threadsafe - but I think our eventwrapper isn't 🙃

I'll wrap a mutex around this anyway.

@ggilmore ggilmore force-pushed the spr/main/12b8f3ad branch 2 times, most recently from bb27938 to b5c0cd1 Compare April 13, 2024 00:34
@ggilmore ggilmore enabled auto-merge (squash) April 13, 2024 00:41
@ggilmore ggilmore disabled auto-merge April 13, 2024 00:41
@ggilmore ggilmore force-pushed the spr/main/12b8f3ad branch from b5c0cd1 to cbc178b Compare April 13, 2024 00:43
@ggilmore ggilmore enabled auto-merge (squash) April 13, 2024 00:45
@ggilmore ggilmore merged commit 3f20d82 into main Apr 13, 2024
@ggilmore ggilmore deleted the spr/main/12b8f3ad branch April 13, 2024 00:48
Comment on lines +34 to +42
var wg sync.WaitGroup
for i := 0; i < 1000; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
event.AddField(fmt.Sprintf("key%d", i), i)
}(i)
}
wg.Wait()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This kind of code would be slightly simpler with our conc library.

		wg := conc.NewWaitGroup()
		for i := 0; i < 1000; i++ {
			wg.Go(func() {
				event.AddField(fmt.Sprintf("key%d", i), i)
			})
		}
		wg.Wait()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty logs produced when honeycomb is disabled

3 participants