From a2ac34d26298dd9cd16a0d0b29b5acb58efa3192 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:11:54 -0400 Subject: [PATCH] chore(recordings): check target's jvmId for recording events (#1126) (#1151) (cherry picked from commit c75c36a08100a19591c730b2a4d098bd54295f60) Co-authored-by: Ming Yu Wang <90855268+mwangggg@users.noreply.github.com> --- src/app/Agent/AgentLiveProbes.tsx | 2 +- src/app/RecordingMetadata/BulkEditLabels.tsx | 2 +- src/app/Recordings/ActiveRecordingsTable.tsx | 8 ++++---- src/app/Recordings/ArchivedRecordingsTable.tsx | 6 +++--- src/app/Shared/Services/api.types.ts | 1 - src/mirage/index.ts | 12 ------------ src/test/Agent/AgentLiveProbes.test.tsx | 4 +++- src/test/RecordingMetadata/BulkEditLabels.test.tsx | 5 ++++- src/test/Recordings/ActiveRecordingsTable.test.tsx | 10 +++++++--- src/test/Recordings/ArchivedRecordingsTable.test.tsx | 10 +++++++--- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/app/Agent/AgentLiveProbes.tsx b/src/app/Agent/AgentLiveProbes.tsx index 587097897..9b2f01d1e 100644 --- a/src/app/Agent/AgentLiveProbes.tsx +++ b/src/app/Agent/AgentLiveProbes.tsx @@ -210,7 +210,7 @@ export const AgentLiveProbes: React.FC = (_) => { context.target.target(), context.notificationChannel.messages(NotificationCategory.ProbeTemplateApplied), ]).subscribe(([currentTarget, e]) => { - if (currentTarget?.connectUrl != e.message.targetId) { + if (currentTarget?.connectUrl != e.message.targetId && currentTarget?.jvmId != e.message.jvmId) { return; } setProbes((old) => { diff --git a/src/app/RecordingMetadata/BulkEditLabels.tsx b/src/app/RecordingMetadata/BulkEditLabels.tsx index d4558dd8d..e47f92a3f 100644 --- a/src/app/RecordingMetadata/BulkEditLabels.tsx +++ b/src/app/RecordingMetadata/BulkEditLabels.tsx @@ -246,7 +246,7 @@ export const BulkEditLabels: React.FC = ({ ]).subscribe((parts) => { const currentTarget = parts[0]; const event = parts[1]; - if (currentTarget?.connectUrl != event.message.target) { + if (currentTarget?.connectUrl != event.message.target && currentTarget?.jvmId != event.message.jvmId) { return; } setRecordings((old) => diff --git a/src/app/Recordings/ActiveRecordingsTable.tsx b/src/app/Recordings/ActiveRecordingsTable.tsx index b1d4c861c..9f385e7ab 100644 --- a/src/app/Recordings/ActiveRecordingsTable.tsx +++ b/src/app/Recordings/ActiveRecordingsTable.tsx @@ -251,7 +251,7 @@ export const ActiveRecordingsTable: React.FC = (prop context.notificationChannel.messages(NotificationCategory.SnapshotCreated), ), ]).subscribe(([currentTarget, event]) => { - if (currentTarget?.connectUrl != event.message.target) { + if (currentTarget?.connectUrl != event.message.target && currentTarget?.jvmId != event.message.jvmId) { return; } setRecordings((old) => old.concat([event.message.recording])); @@ -268,7 +268,7 @@ export const ActiveRecordingsTable: React.FC = (prop context.notificationChannel.messages(NotificationCategory.SnapshotDeleted), ), ]).subscribe(([currentTarget, event]) => { - if (currentTarget?.connectUrl != event.message.target) { + if (currentTarget?.connectUrl != event.message.target && currentTarget?.jvmId != event.message.jvmId) { return; } @@ -284,7 +284,7 @@ export const ActiveRecordingsTable: React.FC = (prop context.target.target(), context.notificationChannel.messages(NotificationCategory.ActiveRecordingStopped), ]).subscribe(([currentTarget, event]) => { - if (currentTarget?.connectUrl != event.message.target) { + if (currentTarget?.connectUrl != event.message.target && currentTarget?.jvmId != event.message.jvmId) { return; } setRecordings((old) => { @@ -315,7 +315,7 @@ export const ActiveRecordingsTable: React.FC = (prop context.target.target(), context.notificationChannel.messages(NotificationCategory.RecordingMetadataUpdated), ]).subscribe(([currentTarget, event]) => { - if (currentTarget?.connectUrl != event.message.target) { + if (currentTarget?.connectUrl != event.message.target && currentTarget?.jvmId != event.message.jvmId) { return; } setRecordings((old) => diff --git a/src/app/Recordings/ArchivedRecordingsTable.tsx b/src/app/Recordings/ArchivedRecordingsTable.tsx index 8d53e16e6..c2f9a470d 100644 --- a/src/app/Recordings/ArchivedRecordingsTable.tsx +++ b/src/app/Recordings/ArchivedRecordingsTable.tsx @@ -310,7 +310,7 @@ export const ArchivedRecordingsTable: React.FC = ( context.notificationChannel.messages(NotificationCategory.ActiveRecordingSaved), ), ]).subscribe(([currentTarget, event]) => { - if (currentTarget?.connectUrl != event.message.target) { + if (currentTarget?.connectUrl != event.message.target && currentTarget?.jvmId != event.message.jvmId) { return; } setRecordings((old) => @@ -326,7 +326,7 @@ export const ArchivedRecordingsTable: React.FC = ( propsTarget, context.notificationChannel.messages(NotificationCategory.ArchivedRecordingDeleted), ]).subscribe(([currentTarget, event]) => { - if (currentTarget?.connectUrl != event.message.target) { + if (currentTarget?.connectUrl != event.message.target && currentTarget?.jvmId != event.message.jvmId) { return; } setRecordings((old) => old.filter((r) => r.name !== event.message.recording.name)); @@ -341,7 +341,7 @@ export const ArchivedRecordingsTable: React.FC = ( propsTarget, context.notificationChannel.messages(NotificationCategory.RecordingMetadataUpdated), ]).subscribe(([currentTarget, event]) => { - if (currentTarget?.connectUrl != event.message.target) { + if (currentTarget?.connectUrl != event.message.target && currentTarget?.jvmId != event.message.jvmId) { return; } setRecordings((old) => diff --git a/src/app/Shared/Services/api.types.ts b/src/app/Shared/Services/api.types.ts index 6a80e5083..4a1e94406 100644 --- a/src/app/Shared/Services/api.types.ts +++ b/src/app/Shared/Services/api.types.ts @@ -511,7 +511,6 @@ export interface NotificationMessage { meta: MessageMeta; // Should a message be any type? Try T? message: any; // eslint-disable-line @typescript-eslint/no-explicit-any - serverTime: number; } export interface MessageMeta { diff --git a/src/mirage/index.ts b/src/mirage/index.ts index 1047695c6..00077808e 100644 --- a/src/mirage/index.ts +++ b/src/mirage/index.ts @@ -38,7 +38,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { type: 'application', subtype: 'json', }, - serverTime: +Date.now(), }, message: { '127.0.0.1': 'accepted', @@ -116,7 +115,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'TargetJvmDiscovery', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: { event: { serviceRef: target, kind: 'FOUND' } }, }), @@ -186,7 +184,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'ArchivedRecordingDeleted', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: { recording: { @@ -229,7 +226,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'ActiveRecordingCreated', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: { target: request.params.targetId, @@ -253,7 +249,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'ActiveRecordingDeleted', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: { recording: { @@ -282,7 +277,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'ActiveRecordingStopped', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: { recording: { @@ -308,7 +302,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'ActiveRecordingSaved', type: { type: 'application', subType: 'json' }, - serverTime: ts, }, message: { recording: archived, @@ -426,7 +419,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'RuleCreated', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: rule, }; @@ -453,7 +445,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'RuleUpdated', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: rule, }; @@ -473,7 +464,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'RuleDeleted', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: rule, }; @@ -581,7 +571,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'RecordingMetadataUpdated', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: { recordingName: variables.recordingName, @@ -628,7 +617,6 @@ export const startMirage = ({ environment = 'development' } = {}) => { meta: { category: 'RecordingMetadataUpdated', type: { type: 'application', subType: 'json' }, - serverTime: +Date.now(), }, message: { recordingName: variables.recordingName, diff --git a/src/test/Agent/AgentLiveProbes.test.tsx b/src/test/Agent/AgentLiveProbes.test.tsx index 32680b604..6992d920b 100644 --- a/src/test/Agent/AgentLiveProbes.test.tsx +++ b/src/test/Agent/AgentLiveProbes.test.tsx @@ -32,7 +32,8 @@ import { of } from 'rxjs'; import { renderWithServiceContext } from '../Common'; const mockConnectUrl = 'service:jmx:rmi://someUrl'; -const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget' }; +const mockJvmId = 'id'; +const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget', jvmId: mockJvmId }; const mockMessageType = { type: 'application', subtype: 'json' } as MessageType; @@ -66,6 +67,7 @@ const mockApplyTemplateNotification = { message: { targetId: mockConnectUrl, events: [mockAnotherProbe], + jvmId: mockJvmId, }, } as NotificationMessage; diff --git a/src/test/RecordingMetadata/BulkEditLabels.test.tsx b/src/test/RecordingMetadata/BulkEditLabels.test.tsx index d29dc4af5..164b6dac1 100644 --- a/src/test/RecordingMetadata/BulkEditLabels.test.tsx +++ b/src/test/RecordingMetadata/BulkEditLabels.test.tsx @@ -35,7 +35,8 @@ jest.mock('@patternfly/react-core', () => ({ })); const mockConnectUrl = 'service:jmx:rmi://someUrl'; -const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget' }; +const mockJvmId = 'id'; +const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget', jvmId: mockJvmId }; const mockRecordingLabels = { someLabel: 'someValue', @@ -69,6 +70,7 @@ const mockActiveLabelsNotification = { message: { target: mockConnectUrl, recordingName: 'someActiveRecording', + jvmId: mockJvmId, metadata: { labels: { someLabel: 'someValue', someNewLabel: 'someNewValue' } }, }, } as NotificationMessage; @@ -79,6 +81,7 @@ const mockArchivedLabelsNotification = { message: { target: mockConnectUrl, recordingName: 'someArchivedRecording_some_random', + jvmId: mockJvmId, metadata: { labels: { someLabel: 'someValue', someNewLabel: 'someNewValue' } }, }, } as NotificationMessage; diff --git a/src/test/Recordings/ActiveRecordingsTable.test.tsx b/src/test/Recordings/ActiveRecordingsTable.test.tsx index 30e642b44..fb11ad425 100644 --- a/src/test/Recordings/ActiveRecordingsTable.test.tsx +++ b/src/test/Recordings/ActiveRecordingsTable.test.tsx @@ -39,7 +39,8 @@ import { } from '../Common'; const mockConnectUrl = 'service:jmx:rmi://someUrl'; -const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget' }; +const mockJvmId = 'id'; +const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget', jvmId: mockJvmId }; const mockRecordingLabels = { someLabel: 'someValue', }; @@ -59,16 +60,19 @@ const mockRecording: ActiveRecording = { }; const mockAnotherRecording = { ...mockRecording, name: 'anotherRecording', id: 1 }; const mockCreateNotification = { - message: { target: mockConnectUrl, recording: mockAnotherRecording }, + message: { target: mockConnectUrl, recording: mockAnotherRecording, jvmId: mockJvmId }, } as NotificationMessage; const mockLabelsNotification = { message: { target: mockConnectUrl, recordingName: 'someRecording', + jvmId: mockJvmId, metadata: { labels: { someLabel: 'someUpdatedValue' } }, }, } as NotificationMessage; -const mockStopNotification = { message: { target: mockConnectUrl, recording: mockRecording } } as NotificationMessage; +const mockStopNotification = { + message: { target: mockConnectUrl, recording: mockRecording, jvmId: mockJvmId }, +} as NotificationMessage; const mockDeleteNotification = mockStopNotification; const history = createMemoryHistory({ initialEntries: ['/recordings'] }); diff --git a/src/test/Recordings/ArchivedRecordingsTable.test.tsx b/src/test/Recordings/ArchivedRecordingsTable.test.tsx index 860471ea5..3917a36f4 100644 --- a/src/test/Recordings/ArchivedRecordingsTable.test.tsx +++ b/src/test/Recordings/ArchivedRecordingsTable.test.tsx @@ -38,7 +38,8 @@ import { } from '../Common'; const mockConnectUrl = 'service:jmx:rmi://someUrl'; -const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget' }; +const mockJvmId = 'id'; +const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget', jvmId: mockJvmId }; const mockUploadsTarget = { connectUrl: UPLOADS_SUBDIRECTORY, alias: '' }; const mockRecordingLabels = { someLabel: 'someValue', @@ -73,16 +74,19 @@ const mockArchivedRecordingsResponse = { const mockAnotherRecording = { ...mockRecording, name: 'anotherRecording' }; const mockCreateNotification = { - message: { target: mockConnectUrl, recording: mockAnotherRecording }, + message: { target: mockConnectUrl, recording: mockAnotherRecording, jvmId: mockJvmId }, } as NotificationMessage; const mockLabelsNotification = { message: { target: mockConnectUrl, recordingName: 'someRecording', + jvmId: mockJvmId, metadata: { labels: { someLabel: 'someUpdatedValue' } }, }, } as NotificationMessage; -const mockDeleteNotification = { message: { target: mockConnectUrl, recording: mockRecording } } as NotificationMessage; +const mockDeleteNotification = { + message: { target: mockConnectUrl, recording: mockRecording, jvmId: mockJvmId }, +} as NotificationMessage; const mockFileName = 'mock.jfr'; const mockFileUpload = new File([JSON.stringify(mockAnotherRecording)], mockFileName, { type: 'jfr' });