Skip to content

Commit

Permalink
chore(discovery): use target.agent field for determining connection t…
Browse files Browse the repository at this point in the history
…ype (#1321)
  • Loading branch information
andrewazores authored Aug 22, 2024
1 parent 2e8ad02 commit 09c7afc
Show file tree
Hide file tree
Showing 29 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/app/Archives/AllTargetsArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
setArchivesForTargets(
targetNodes.map((node) => {
const target: Target = {
agent: node.target.agent,
id: node.target.id,
jvmId: node.target.jvmId,
connectUrl: node.target.connectUrl,
Expand Down Expand Up @@ -172,6 +173,7 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
`query AllTargetsArchives {
targetNodes {
target {
agent
id
connectUrl
alias
Expand Down
1 change: 1 addition & 0 deletions src/app/Archives/Archives.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { AllTargetsArchivedRecordingsTable } from './AllTargetsArchivedRecording
notification handling in the ArchivedRecordingsTable.
*/
export const uploadAsTarget: Target = {
agent: false,
connectUrl: UPLOADS_SUBDIRECTORY,
alias: '',
labels: [],
Expand Down
1 change: 1 addition & 0 deletions src/app/Archives/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const indexOfDirectory = (arr: RecordingDirectory[], dir: RecordingDirect

export const getTargetFromDirectory = (dir: RecordingDirectory): Target => {
return {
agent: dir.connectUrl.startsWith('http'),
connectUrl: dir.connectUrl,
alias: dir.jvmId,
labels: [],
Expand Down
3 changes: 1 addition & 2 deletions src/app/CreateRecording/CustomRecordingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
Target,
KeyValue,
} from '@app/Shared/Services/api.types';
import { isTargetAgentHttp } from '@app/Shared/Services/api.utils';
import { NotificationsContext } from '@app/Shared/Services/Notifications.service';
import { ServiceContext } from '@app/Shared/Services/Services';
import { useSubscriptions } from '@app/utils/hooks/useSubscriptions';
Expand Down Expand Up @@ -286,7 +285,7 @@ export const CustomRecordingForm: React.FC = () => {
setAdvancedRecordingOptions(recordingOptions);
},
error: (error) => {
setErrorMessage(isTargetAgentHttp(target) ? 'Unsupported operation: Create Recordings' : error.message);
setErrorMessage(error.message);
setTemplates([]);
setFormData((old) => ({ ...old, template: undefined }));
setAdvancedRecordingOptions({});
Expand Down
3 changes: 2 additions & 1 deletion src/app/Shared/Services/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class XMLHttpError extends Error {
}
}

export type TargetStub = Omit<Target, 'jvmId' | 'labels' | 'annotations'>;
export type TargetStub = Omit<Target, 'agent' | 'jvmId' | 'labels' | 'annotations'>;

export type TargetForTest = Pick<Target, 'alias' | 'connectUrl'> & {
labels: object;
Expand Down Expand Up @@ -473,6 +473,7 @@ export const TEMPLATE_UNSUPPORTED_MESSAGE = 'The template type used in this Reco
export interface Target {
id?: number; // present in responses but we must not include it in requests to create targets
jvmId?: string; // present in responses, but we do not need to provide it in requests
agent: boolean;
connectUrl: string;
alias: string;
labels: KeyValue[];
Expand Down
2 changes: 0 additions & 2 deletions src/app/Shared/Services/api.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ export const indexOfTarget = (arr: Target[], target: Target): number => {
export const getTargetRepresentation = (t: Target) =>
!t.alias || t.alias === t.connectUrl ? `${t.connectUrl}` : `${t.alias} (${t.connectUrl})`;

export const isTargetAgentHttp = (t: Target) => t.connectUrl.startsWith('http');

export const isTargetNode = (node: EnvironmentNode | TargetNode): node is TargetNode => {
return node['target'] !== undefined;
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/Topology/Actions/CreateTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export const CreateTarget: React.FC<CreateTargetProps> = ({ prefilled }) => {
};

export interface SampleNodeDonutProps {
target: Target;
target: Omit<Target, 'agent'>;
testing?: boolean;
validation: {
option: ValidatedOptions;
Expand Down
2 changes: 1 addition & 1 deletion src/app/Topology/GraphView/CustomNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const CustomNode: React.FC<CustomNodeProps> = ({

const data: TargetNode = element.getData();

const graphic = React.useMemo(() => (data.target.connectUrl.startsWith('http') ? cryostatSvg : openjdkSvg), [data]);
const graphic = React.useMemo(() => (data.target.agent ? cryostatSvg : openjdkSvg), [data]);

const [nodeStatus] = getStatusTargetNode(data);

Expand Down
1 change: 1 addition & 0 deletions src/app/utils/fakeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { TargetService } from '@app/Shared/Services/Target.service';
import { Observable, of } from 'rxjs';

export const fakeTarget: Target = {
agent: false,
jvmId: 'rpZeYNB9wM_TEnXoJvAFuR0jdcUBXZgvkXiKhjQGFvY=',
connectUrl: 'service:jmx:rmi:///jndi/rmi://10-128-2-25.my-namespace.pod:9097/jmxrmi',
alias: 'quarkus-test-77f556586c-25bkv',
Expand Down
1 change: 1 addition & 0 deletions src/mirage/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { FactoryDefinition } from 'miragejs/-types';
import { Resource } from './typings';

export const targetFactory: FactoryDefinition<any> = Factory.extend({
agent: true,
alias: 'Fake Target',
connectUrl: 'http://fake-target.local:1234',
jvmId: '1234',
Expand Down
1 change: 1 addition & 0 deletions src/test/Agent/AgentLiveProbes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { render, renderSnapshot } from '../utils';
const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockJvmId = 'id';
const mockTarget = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'fooTarget',
jvmId: mockJvmId,
Expand Down
4 changes: 4 additions & 0 deletions src/test/Archives/AllTargetsArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { render, renderSnapshot } from '../utils';
const mockConnectUrl1 = 'service:jmx:rmi://someUrl1';
const mockAlias1 = 'fooTarget1';
const mockTarget1: Target = {
agent: false,
jvmId: 'target1',
connectUrl: mockConnectUrl1,
alias: mockAlias1,
Expand All @@ -36,6 +37,7 @@ const mockTarget1: Target = {
const mockConnectUrl2 = 'service:jmx:rmi://someUrl2';
const mockAlias2 = 'fooTarget2';
const mockTarget2: Target = {
agent: false,
jvmId: 'target2',
connectUrl: mockConnectUrl2,
alias: mockAlias2,
Expand All @@ -48,6 +50,7 @@ const mockTarget2: Target = {
const mockConnectUrl3 = 'service:jmx:rmi://someUrl3';
const mockAlias3 = 'fooTarget3';
const mockTarget3: Target = {
agent: false,
jvmId: 'target3',
connectUrl: mockConnectUrl3,
alias: mockAlias3,
Expand All @@ -60,6 +63,7 @@ const mockTarget3: Target = {
const mockNewConnectUrl = 'service:jmx:rmi://someNewUrl';
const mockNewAlias = 'newTarget';
const mockNewTarget: Target = {
agent: false,
jvmId: 'target4',
connectUrl: mockNewConnectUrl,
alias: mockNewAlias,
Expand Down
1 change: 1 addition & 0 deletions src/test/CreateRecording/CustomRecordingForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jest.mock('react-router-dom', () => ({

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'fooTarget',
jvmId: 'foo',
Expand Down
1 change: 1 addition & 0 deletions src/test/CreateRecording/SnapshotRecordingForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { render, renderSnapshot } from '../utils';

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'fooTarget',
jvmId: 'foo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jest.mock('@app/Dashboard/AutomatedAnalysis/AutomatedAnalysisCardList', () => {
});

const mockTarget = {
agent: false,
connectUrl: 'service:jmx:rmi://someUrl',
alias: 'fooTarget',
jvmId: 'foo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { of } from 'rxjs';
import { render, testT } from '../../utils';

const mockTarget = {
agent: false,
connectUrl: 'service:jmx:rmi://someUrl',
alias: 'fooTarget',
jvmId: 'foo',
Expand Down
1 change: 1 addition & 0 deletions src/test/Dashboard/Charts/jfr/JFRMetricsChartCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const mockDashboardUrl = 'http://localhost:3000';
jest.spyOn(defaultServices.api, 'grafanaDashboardUrl').mockReturnValue(of(mockDashboardUrl));

const mockTarget = {
agent: false,
connectUrl: 'service:jmx:rmi://someUrl',
alias: 'fooTarget',
jvmId: 'foo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jest.spyOn(defaultServices.target, 'authRetry').mockReturnValue(of());
jest.spyOn(defaultServices.target, 'sslFailure').mockReturnValue(of());

const mockTarget = {
agent: false,
connectUrl: 'service:jmx:rmi://someUrl',
alias: 'fooTarget',
jvmId: 'foo',
Expand Down
1 change: 1 addition & 0 deletions src/test/Dashboard/Dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { of } from 'rxjs';
const mockFooConnectUrl = 'service:jmx:rmi://someFooUrl';

const mockFooTarget: Target = {
agent: false,
connectUrl: mockFooConnectUrl,
alias: 'fooTarget',
labels: [],
Expand Down
1 change: 1 addition & 0 deletions src/test/Events/EventTemplates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { render, renderSnapshot } from '../utils';

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'fooTarget',
jvmId: 'foo',
Expand Down
1 change: 1 addition & 0 deletions src/test/Events/EventTypes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { render, renderSnapshot } from '../utils';

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'fooTarget',
jvmId: 'foo',
Expand Down
1 change: 1 addition & 0 deletions src/test/RecordingMetadata/BulkEditLabels.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jest.mock('@patternfly/react-core', () => ({
const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockJvmId = 'id';
const mockTarget: Target = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'fooTarget',
jvmId: mockJvmId,
Expand Down
1 change: 1 addition & 0 deletions src/test/RecordingMetadata/LabelCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import userEvent from '@testing-library/user-event';
import { render, renderSnapshot } from '../utils';

const mockFooTarget: Target = {
agent: false,
connectUrl: 'service:jmx:rmi://someFooUrl',
alias: 'fooTarget',
labels: [],
Expand Down
1 change: 1 addition & 0 deletions src/test/Recordings/ActiveRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { basePreloadedState, DEFAULT_DIMENSIONS, render, resize } from '../utils
const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockJvmId = 'id';
const mockTarget = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'fooTarget',
jvmId: mockJvmId,
Expand Down
2 changes: 2 additions & 0 deletions src/test/Recordings/ArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ import { basePreloadedState, DEFAULT_DIMENSIONS, render, resize } from '../utils
const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockJvmId = 'id';
const mockTarget: Target = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'fooTarget',
jvmId: mockJvmId,
labels: [],
annotations: { cryostat: [], platform: [] },
};
const mockUploadsTarget = {
agent: false,
connectUrl: UPLOADS_SUBDIRECTORY,
alias: '',
labels: [],
Expand Down
1 change: 1 addition & 0 deletions src/test/Recordings/RecordingFilters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { of } from 'rxjs';
import { basePreloadedState, render } from '../utils';

const mockFooTarget: Target = {
agent: false,
connectUrl: 'service:jmx:rmi://someFooUrl',
alias: 'fooTarget',
labels: [],
Expand Down
1 change: 1 addition & 0 deletions src/test/Recordings/Recordings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jest.mock('@app/TargetView/TargetView', () => {
});

const mockFooTarget: Target = {
agent: false,
connectUrl: 'service:jmx:rmi://someFooUrl',
alias: 'fooTarget',
labels: [],
Expand Down
1 change: 1 addition & 0 deletions src/test/Rules/CreateRule.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jest.mock('@app/Shared/Components/MatchExpression/MatchExpressionVisualizer', ()

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget: Target = {
agent: false,
connectUrl: mockConnectUrl,
alias: 'io.cryostat.Cryostat',
labels: [],
Expand Down
1 change: 1 addition & 0 deletions src/test/TargetView/TargetSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const cryostatAnnotation = [
},
];
const mockFooTarget: Target = {
agent: false,
jvmId: 'abcd',
connectUrl: mockFooConnectUrl,
alias: 'fooTarget',
Expand Down

0 comments on commit 09c7afc

Please sign in to comment.