-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(#4858): deduplicate events #4872
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
Merged
+108
−10
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e72ebf4
fix-4858 dedeuplicate
b6f7bf2
removing comments
fb949dd
Merge branch 'master' into fix-4858-deduplicate
teja2 0cc0842
Merge branch 'master' into fix-4858-deduplicate
SteKoe d86b76a
fix: enhance deduplication logic for instance events to include type …
SteKoe f892412
Merge branch 'master' into fix-4858-deduplicate
SteKoe 6215c2d
fix: reorder imports for deduplication logic in index.vue
SteKoe 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
Some comments aren't visible on the classic Files Changed page.
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
63 changes: 63 additions & 0 deletions
63
spring-boot-admin-server-ui/src/main/frontend/views/journal/deduplicate-events.spec.ts
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,63 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { deduplicateInstanceEvents } from './deduplicate-events'; | ||
|
|
||
| import { | ||
| InstanceEvent, | ||
| InstanceEventType, | ||
| } from '@/views/journal/InstanceEvent'; | ||
|
|
||
| const createEvent = ( | ||
| instance: string, | ||
| version: number, | ||
| type = InstanceEventType.REGISTERED, | ||
| ) => | ||
| new InstanceEvent({ | ||
| instance, | ||
| version, | ||
| type, | ||
| timestamp: '2024-01-01T10:00:00Z', | ||
| registration: { name: instance }, | ||
| }); | ||
|
|
||
| describe('deduplicateInstanceEvents', () => { | ||
| it('removes events with identical instance, type and version', () => { | ||
| const events = [ | ||
| createEvent('instance-1', 1), | ||
| createEvent('instance-1', 1, InstanceEventType.DEREGISTERED), | ||
| createEvent('instance-2', 3), | ||
| createEvent('instance-2', 3), | ||
| createEvent('instance-3', 2), | ||
| createEvent('instance-3', 2, InstanceEventType.INFO_CHANGED), | ||
| createEvent('instance-3', 2, InstanceEventType.INFO_CHANGED), | ||
| ]; | ||
|
|
||
| const result = deduplicateInstanceEvents(events); | ||
|
|
||
| expect(result).toHaveLength(5); | ||
| expect(result.map((event) => event.key)).toEqual([ | ||
| 'instance-1-1-REGISTERED-1704103200000', | ||
| 'instance-1-1-DEREGISTERED-1704103200000', | ||
| 'instance-2-3-REGISTERED-1704103200000', | ||
| 'instance-3-2-REGISTERED-1704103200000', | ||
| 'instance-3-2-INFO_CHANGED-1704103200000', | ||
| ]); | ||
| }); | ||
|
|
||
| it('preserves the order of the first occurrences', () => { | ||
| const events = [ | ||
| createEvent('instance-1', 2), | ||
| createEvent('instance-2', 1), | ||
| createEvent('instance-1', 2), | ||
| createEvent('instance-3', 4), | ||
| ]; | ||
|
|
||
| const result = deduplicateInstanceEvents(events); | ||
|
|
||
| expect(result.map((event) => event.key)).toEqual([ | ||
| 'instance-1-2-REGISTERED-1704103200000', | ||
| 'instance-2-1-REGISTERED-1704103200000', | ||
| 'instance-3-4-REGISTERED-1704103200000', | ||
| ]); | ||
| }); | ||
| }); |
30 changes: 30 additions & 0 deletions
30
spring-boot-admin-server-ui/src/main/frontend/views/journal/deduplicate-events.ts
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,30 @@ | ||
| import { InstanceEvent } from '@/views/journal/InstanceEvent'; | ||
|
|
||
| /** | ||
| * Removes duplicate instance events from an array based on their key property. | ||
| * | ||
| * This function filters an array of InstanceEvent objects, keeping only the first occurrence | ||
| * of each unique event key. Subsequent events with the same key are filtered out. | ||
| * | ||
| * @param events - Array of InstanceEvent objects to deduplicate | ||
| * @returns A new array containing only unique events (by key), preserving the order of first occurrence | ||
| * | ||
| * @example | ||
| * const events = [ | ||
| * { key: 'event1', ... }, | ||
| * { key: 'event2', ... }, | ||
| * { key: 'event1', ... } // duplicate | ||
| * ]; | ||
| * const unique = deduplicateInstanceEvents(events); | ||
| * // Returns first two events only | ||
| */ | ||
| export function deduplicateInstanceEvents(events: InstanceEvent[]) { | ||
| const seen = new Set<string>(); | ||
| return events.filter((event) => { | ||
| if (seen.has(event.key)) { | ||
| return false; | ||
| } | ||
| seen.add(event.key); | ||
| return true; | ||
| }); | ||
| } | ||
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
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.
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.
@SteKoe is the event key really enough?
It's imperative, in my opinion, that a SBA instance X shows the events recorded by the same instance and not, for example, by the instance Y.
Otherwise there is no traceability anymore and it's, therefore, better to keep things as they're now by enduring the duplicates.
Uh oh!
There was an error while loading. Please reload this page.
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.
Since the backend does not contain the instance name of SBA in the events, this would be a bigger change than just adding deduplication in frontend.
As
keyis just usinginstanceIdandversion, no. We have to respect any value here. Event type as well as timestamp. Otherwise the following events would be reduced, even though they are not the same:Thanks to the existing tests, I was able to extend the behavior and added some more use cases.
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.
But then you won't dedup anything I think