Skip to content

Commit

Permalink
chore(recordings): check target's jvmId for recording events (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg authored Oct 30, 2023
1 parent bf9af76 commit c75c36a
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/app/Agent/AgentLiveProbes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const AgentLiveProbes: React.FC<AgentLiveProbesProps> = (_) => {
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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/RecordingMetadata/BulkEditLabels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const BulkEditLabels: React.FC<BulkEditLabelsProps> = ({
]).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) =>
Expand Down
8 changes: 4 additions & 4 deletions src/app/Recordings/ActiveRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export const ActiveRecordingsTable: React.FC<ActiveRecordingsTableProps> = (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]));
Expand All @@ -266,7 +266,7 @@ export const ActiveRecordingsTable: React.FC<ActiveRecordingsTableProps> = (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;
}

Expand All @@ -282,7 +282,7 @@ export const ActiveRecordingsTable: React.FC<ActiveRecordingsTableProps> = (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) => {
Expand Down Expand Up @@ -313,7 +313,7 @@ export const ActiveRecordingsTable: React.FC<ActiveRecordingsTableProps> = (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) =>
Expand Down
6 changes: 3 additions & 3 deletions src/app/Recordings/ArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export const ArchivedRecordingsTable: React.FC<ArchivedRecordingsTableProps> = (
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) =>
Expand All @@ -326,7 +326,7 @@ export const ArchivedRecordingsTable: React.FC<ArchivedRecordingsTableProps> = (
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));
Expand All @@ -341,7 +341,7 @@ export const ArchivedRecordingsTable: React.FC<ArchivedRecordingsTableProps> = (
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) =>
Expand Down
1 change: 0 additions & 1 deletion src/app/Shared/Services/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions src/mirage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
type: 'application',
subtype: 'json',
},
serverTime: +Date.now(),
},
message: {
'127.0.0.1': 'accepted',
Expand Down Expand Up @@ -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' } },
}),
Expand Down Expand Up @@ -186,7 +184,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'ArchivedRecordingDeleted',
type: { type: 'application', subType: 'json' },
serverTime: +Date.now(),
},
message: {
recording: {
Expand Down Expand Up @@ -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,
Expand All @@ -253,7 +249,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'ActiveRecordingDeleted',
type: { type: 'application', subType: 'json' },
serverTime: +Date.now(),
},
message: {
recording: {
Expand Down Expand Up @@ -282,7 +277,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'ActiveRecordingStopped',
type: { type: 'application', subType: 'json' },
serverTime: +Date.now(),
},
message: {
recording: {
Expand All @@ -308,7 +302,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'ActiveRecordingSaved',
type: { type: 'application', subType: 'json' },
serverTime: ts,
},
message: {
recording: archived,
Expand Down Expand Up @@ -426,7 +419,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'RuleCreated',
type: { type: 'application', subType: 'json' },
serverTime: +Date.now(),
},
message: rule,
};
Expand All @@ -453,7 +445,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'RuleUpdated',
type: { type: 'application', subType: 'json' },
serverTime: +Date.now(),
},
message: rule,
};
Expand All @@ -473,7 +464,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'RuleDeleted',
type: { type: 'application', subType: 'json' },
serverTime: +Date.now(),
},
message: rule,
};
Expand Down Expand Up @@ -581,7 +571,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'RecordingMetadataUpdated',
type: { type: 'application', subType: 'json' },
serverTime: +Date.now(),
},
message: {
recordingName: variables.recordingName,
Expand Down Expand Up @@ -628,7 +617,6 @@ export const startMirage = ({ environment = 'development' } = {}) => {
meta: {
category: 'RecordingMetadataUpdated',
type: { type: 'application', subType: 'json' },
serverTime: +Date.now(),
},
message: {
recordingName: variables.recordingName,
Expand Down
4 changes: 3 additions & 1 deletion src/test/Agent/AgentLiveProbes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { of } from 'rxjs';
import { render, renderSnapshot } from '../utils';

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;

Expand Down Expand Up @@ -63,6 +64,7 @@ const mockApplyTemplateNotification = {
message: {
targetId: mockConnectUrl,
events: [mockAnotherProbe],
jvmId: mockJvmId,
},
} as NotificationMessage;

Expand Down
5 changes: 4 additions & 1 deletion src/test/RecordingMetadata/BulkEditLabels.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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',
Expand Down Expand Up @@ -66,6 +67,7 @@ const mockActiveLabelsNotification = {
message: {
target: mockConnectUrl,
recordingName: 'someActiveRecording',
jvmId: mockJvmId,
metadata: { labels: { someLabel: 'someValue', someNewLabel: 'someNewValue' } },
},
} as NotificationMessage;
Expand All @@ -76,6 +78,7 @@ const mockArchivedLabelsNotification = {
message: {
target: mockConnectUrl,
recordingName: 'someArchivedRecording_some_random',
jvmId: mockJvmId,
metadata: { labels: { someLabel: 'someValue', someNewLabel: 'someNewValue' } },
},
} as NotificationMessage;
Expand Down
10 changes: 7 additions & 3 deletions src/test/Recordings/ActiveRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import { of, Subject } from 'rxjs';
import { basePreloadedState, DEFAULT_DIMENSIONS, render, resize } from '../utils';

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',
};
Expand All @@ -52,16 +53,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;

jest.mock('@app/Recordings/RecordingFilters', () => {
Expand Down
10 changes: 7 additions & 3 deletions src/test/Recordings/ArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { of, Subject } from 'rxjs';
import { basePreloadedState, DEFAULT_DIMENSIONS, render, resize } from '../utils';

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',
Expand Down Expand Up @@ -66,16 +67,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' });
Expand Down

0 comments on commit c75c36a

Please sign in to comment.