-
Notifications
You must be signed in to change notification settings - Fork 159
Set unique flow id & timestamp to each flow #343
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
Open
sananguliyev
wants to merge
12
commits into
warpstreamlabs:main
Choose a base branch
from
sananguliyev:add-flow-id-and-timestampt-to-tracing-event
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
17b45cf
Set unique id & timestamp to each flow
sananguliyev 744227b
Simplify sorting
sananguliyev b50515b
Generated docs for flow id
sananguliyev f2e9295
Fix tests by removing `_bento_flow_id` from event meta data
sananguliyev cef67c8
Fix rest of the failing tests due to new metadata
sananguliyev cbe4bc7
suppress error messages if no git tags exists
sananguliyev 09903b5
Cleaned-up unnecessary comments
sananguliyev b90d55a
Refactor flow ID handling to use context instead of metadata
sananguliyev 03953f7
Removed stale `_bento_flow_id` usages & improved maps copy
sananguliyev 933a5b6
General cleanup
sananguliyev 0af83ff
Ensure flow id always
sananguliyev 8b337b0
Deprecate EventDeleteOf
sananguliyev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| package tracing | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/warpstreamlabs/bento/internal/message" | ||
| "github.com/warpstreamlabs/bento/internal/tracing" | ||
| ) | ||
|
|
||
| func TestFlowIDGeneration(t *testing.T) { | ||
| part := message.NewPart([]byte("test message")) | ||
|
|
||
| part = tracing.EnsureFlowID(part) | ||
| flowID1 := getFlowID(part) | ||
| assert.NotEmpty(t, flowID1) | ||
| // UUID V7 format: xxxxxxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx | ||
| assert.Regexp(t, `^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`, flowID1) | ||
|
|
||
| flowID2 := getFlowID(part) | ||
| assert.Equal(t, flowID1, flowID2) | ||
|
|
||
| ctx := message.GetContext(part) | ||
| storedFlowID := tracing.GetFlowID(ctx) | ||
| assert.NotEmpty(t, storedFlowID) | ||
| assert.Equal(t, flowID1, storedFlowID) | ||
| } | ||
|
|
||
| func TestFlowIDFromExistingContext(t *testing.T) { | ||
| part := message.NewPart([]byte("test message")) | ||
| expectedFlowID := "existing_flow_123" | ||
| ctx := tracing.WithFlowID(message.GetContext(part), expectedFlowID) | ||
| part = part.WithContext(ctx) | ||
|
|
||
| flowID := getFlowID(part) | ||
| assert.Equal(t, expectedFlowID, flowID) | ||
| } | ||
|
|
||
| func TestEnsureFlowIDWithExisting(t *testing.T) { | ||
| part := message.NewPart([]byte("test message")) | ||
| expectedFlowID := "existing_flow_123" | ||
| ctx := tracing.WithFlowID(message.GetContext(part), expectedFlowID) | ||
| part = part.WithContext(ctx) | ||
|
|
||
| part = tracing.EnsureFlowID(part) | ||
| flowID := getFlowID(part) | ||
| assert.Equal(t, expectedFlowID, flowID) | ||
| } | ||
|
|
||
| func TestEventCreationWithFlowID(t *testing.T) { | ||
| part := message.NewPart([]byte("test content")) | ||
| part.MetaSetMut("test_meta", "test_value") | ||
| part = tracing.EnsureFlowID(part) | ||
|
|
||
| before := time.Now() | ||
| produceEvent := EventProduceOf(part) | ||
| after := time.Now() | ||
|
|
||
| assert.Equal(t, EventProduce, produceEvent.Type) | ||
| assert.Equal(t, "test content", produceEvent.Content) | ||
| assert.Equal(t, "test_value", produceEvent.Meta["test_meta"]) | ||
| assert.NotEmpty(t, produceEvent.FlowID) | ||
| assert.True(t, produceEvent.Timestamp.After(before) || produceEvent.Timestamp.Equal(before)) | ||
| assert.True(t, produceEvent.Timestamp.Before(after) || produceEvent.Timestamp.Equal(after)) | ||
|
|
||
| consumeEvent := EventConsumeOf(part) | ||
| assert.Equal(t, EventConsume, consumeEvent.Type) | ||
| assert.Equal(t, produceEvent.FlowID, consumeEvent.FlowID) | ||
|
|
||
| deleteEvent := EventDeleteOfPart(part) | ||
| assert.Equal(t, EventDelete, deleteEvent.Type) | ||
| assert.Equal(t, produceEvent.FlowID, deleteEvent.FlowID) | ||
| assert.Empty(t, deleteEvent.Content) | ||
|
|
||
| testErr := assert.AnError | ||
| errorEvent := EventErrorOfPart(part, testErr) | ||
| assert.Equal(t, EventError, errorEvent.Type) | ||
| assert.Equal(t, testErr.Error(), errorEvent.Content) | ||
| assert.Equal(t, produceEvent.FlowID, errorEvent.FlowID) | ||
| } | ||
|
|
||
| // TestEventCreationWithoutPart tests deprecated functions that create events without flow IDs. | ||
| // These functions are kept for backward compatibility. | ||
| func TestEventCreationWithoutPart(t *testing.T) { | ||
| deleteEvent := EventDeleteOf() // Deprecated: use EventDeleteOfPart | ||
| assert.Equal(t, EventDelete, deleteEvent.Type) | ||
| assert.Empty(t, deleteEvent.FlowID) | ||
| assert.Empty(t, deleteEvent.Content) | ||
|
|
||
| testErr := assert.AnError | ||
| errorEvent := EventErrorOf(testErr) // Deprecated: use EventErrorOfPart | ||
| assert.Equal(t, EventError, errorEvent.Type) | ||
| assert.Equal(t, testErr.Error(), errorEvent.Content) | ||
| assert.Empty(t, errorEvent.FlowID) | ||
| } | ||
|
|
||
| func TestUniqueFlowIDs(t *testing.T) { | ||
| part1 := message.NewPart([]byte("message 1")) | ||
| part2 := message.NewPart([]byte("message 2")) | ||
|
|
||
| part1 = tracing.EnsureFlowID(part1) | ||
| part2 = tracing.EnsureFlowID(part2) | ||
|
|
||
| flowID1 := getFlowID(part1) | ||
| flowID2 := getFlowID(part2) | ||
|
|
||
| assert.NotEqual(t, flowID1, flowID2) | ||
| assert.NotEmpty(t, flowID1) | ||
| assert.NotEmpty(t, flowID2) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.