Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
adding signal to context (#137)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Rammer <[email protected]>

Signed-off-by: Daniel Rammer <[email protected]>
  • Loading branch information
hamersaw authored Dec 2, 2022
1 parent ab23187 commit 80d1624
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contextutils/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
RoutineLabelKey Key = "routine"
LaunchPlanIDKey Key = "lp"
ResourceVersionKey Key = "res_ver"
SignalIDKey Key = "signal"
)

func (k Key) String() string {
Expand Down Expand Up @@ -126,6 +127,11 @@ func WithTaskType(ctx context.Context, taskType string) context.Context {
return context.WithValue(ctx, TaskTypeKey, taskType)
}

// Gets a new context with SignalID set.
func WithSignalID(ctx context.Context, signalID string) context.Context {
return context.WithValue(ctx, SignalIDKey, signalID)
}

// Gets a new context with Go Routine label key set and a label assigned to the context using pprof.Labels.
// You can then call pprof.SetGoroutineLabels(ctx) to annotate the current go-routine and have that show up in
// pprof analysis.
Expand Down
7 changes: 7 additions & 0 deletions contextutils/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ func TestWithTaskID(t *testing.T) {
assert.Equal(t, "task", ctx.Value(TaskIDKey))
}

func TestWithSignalID(t *testing.T) {
ctx := context.Background()
assert.Nil(t, ctx.Value(SignalIDKey))
ctx = WithSignalID(ctx, "signal")
assert.Equal(t, "signal", ctx.Value(SignalIDKey))
}

func TestGetFields(t *testing.T) {
ctx := context.Background()
ctx = WithJobID(WithNamespace(ctx, "ns123"), "job123")
Expand Down

0 comments on commit 80d1624

Please sign in to comment.