Skip to content

Commit

Permalink
fix: Codemie loading, monitoring url, deptrack url (#537) (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmevladik authored Jan 8, 2025
1 parent 6f8052e commit a66c29b
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const EnvironmentStage = ({
monitoringQuickLink?.metadata?.labels[QUICK_LINK_LABEL_SELECTOR_TYPE],
baseURL: QuickLinksURLS?.[SYSTEM_QUICK_LINKS.MONITORING],
namespace: stage.spec.namespace,
clusterName: stage.spec.clusterName,
})}
QuickLinkComponent={monitoringQuickLink}
size="small"
Expand All @@ -162,11 +163,13 @@ export const EnvironmentStage = ({
icon={ICONS.OPENSEARCH}
iconBase64={loggingQuickLink?.spec?.icon}
enabledText="Open Logs"
externalLink={LinkCreationService.logging.createDashboardLink(
loggingQuickLink?.metadata?.labels[QUICK_LINK_LABEL_SELECTOR_TYPE],
QuickLinksURLS?.[SYSTEM_QUICK_LINKS.LOGGING],
stage.spec.namespace
)}
externalLink={LinkCreationService.logging.createDashboardLink({
provider:
loggingQuickLink?.metadata?.labels[QUICK_LINK_LABEL_SELECTOR_TYPE],
baseURL: QuickLinksURLS?.[SYSTEM_QUICK_LINKS.LOGGING],
namespace: stage.spec.namespace,
clusterName: stage.spec.clusterName,
})}
QuickLinkComponent={loggingQuickLink}
size="small"
/>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/component-details/providers/Data/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const DataContextProvider: React.FC = ({ children }) => {
data: {
metrics: depTrackProjectMetrics,
baseUrl: QuickLinksURLS?.[SYSTEM_QUICK_LINKS.DEPENDENCY_TRACK],
projectID: depTrackProjectID,
},
error: (noApiGatewayUrlError ||
depTrackProjectError ||
Expand All @@ -157,6 +158,7 @@ export const DataContextProvider: React.FC = ({ children }) => {
[
QuickLinksURLS,
depTrackProjectError,
depTrackProjectID,
depTrackProjectMetrics,
depTrackProjectMetricsError,
depTrackProjectQueryStatus,
Expand Down
1 change: 1 addition & 0 deletions src/pages/component-details/providers/Data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface DataContextProviderValue {
depTrackData: DataProviderValue<{
metrics: DepTrackMetrics;
baseUrl: string;
projectID: string;
}>;
sonarData: DataProviderValue<{
metrics: Record<MetricKey, string>;
Expand Down
39 changes: 32 additions & 7 deletions src/pages/configuration/pages/codemie/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export const PageView = () => {
return <ErrorContent error={forbiddenError} outlined />;
}

if (codemie.error) {
return <ErrorContent error={codemie.error} outlined />;
}

if (codemieSecret.error) {
return <ErrorContent error={codemieSecret.error} outlined />;
}

if (codemieProject.error) {
return <ErrorContent error={codemieProject.error} outlined />;
}

if (!codemie.isLoading && !codemie.data && !codemieSecret.isLoading && !codemieSecret.data) {
return (
<>
Expand Down Expand Up @@ -150,9 +162,16 @@ export const PageView = () => {
);
}, [
error,
codemie,
codemieSecret,
codemieProject.data,
codemie.error,
codemie.isLoading,
codemie.data,
codemieSecret.error,
codemieSecret.isLoading,
codemieSecret.data,
codemieProject.error,
codemieProject.data?.status?.value,
codemieProject.data?.status?.error,
codemieProject.data?.metadata.name,
isLoading,
codemieQuickLink.data,
permissions,
Expand Down Expand Up @@ -267,8 +286,12 @@ export const PageView = () => {
>
Project Settings
</Typography>
<LoadingWrapper isLoading={codemieProjectSettings.isLoading}>
{codemieProjectSettings.data?.length ? (
<LoadingWrapper
isLoading={codemieProjectSettings.isLoading && !codemieProjectSettings.error}
>
{codemieProjectSettings.error ? (
<ErrorContent error={codemieProjectSettings.error} outlined />
) : codemieProjectSettings.data?.length ? (
<Grid container spacing={2}>
{codemieProjectSettings.data?.map((_setting) => {
const setting = _setting.jsonData;
Expand Down Expand Up @@ -339,8 +362,10 @@ export const PageView = () => {
>
Applications
</Typography>
<LoadingWrapper isLoading={codemieApplications.isLoading}>
{codemieApplications.data?.length ? (
<LoadingWrapper isLoading={codemieApplications.isLoading && !codemieApplications.error}>
{codemieApplications.error ? (
<ErrorContent error={codemieApplications.error} outlined />
) : codemieApplications.data?.length ? (
<Grid container spacing={2}>
{codemieApplications.data?.map((_application) => {
const application = _application.jsonData;
Expand Down
8 changes: 4 additions & 4 deletions src/pages/configuration/pages/gitops/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export const PageView = () => {
return <ErrorContent error={forbiddenError} outlined />;
}

if (!isLoading && !gitServers?.length && !permissions?.create?.Codebase.allowed) {
return <EmptyList customText={permissions?.create?.Codebase.reason} />;
}

if (!isLoading && !gitServers?.length) {
return (
<EmptyList
Expand All @@ -81,10 +85,6 @@ export const PageView = () => {
);
}

if (!isLoading && !permissions?.create?.Codebase.allowed) {
return <EmptyList customText={permissions?.create?.Codebase.reason} />;
}

if (!isLoading && !gitOpsCodebase && !error) {
return (
<>
Expand Down
3 changes: 3 additions & 0 deletions src/pages/stage-details/components/Monitoring/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export const Monitoring = ({
provider,
baseUrl,
namespace,
clusterName,
}: {
provider: string;
baseUrl: string;
namespace: string;
clusterName;
}) => {
return (
<iframe
Expand All @@ -20,6 +22,7 @@ export const Monitoring = ({
provider,
baseURL: baseUrl,
namespace,
clusterName,
})}
></iframe>
);
Expand Down
1 change: 1 addition & 0 deletions src/pages/stage-details/hooks/usePageTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const usePageTabs = (): Tab[] => {
provider={monitoringQuickLink?.metadata?.labels[QUICK_LINK_LABEL_SELECTOR_TYPE]}
baseUrl={QuickLinksURLS?.monitoring}
namespace={stage.data?.spec.namespace}
clusterName={stage.data?.spec.clusterName}
/>
</TabSection>
</LoadingWrapper>
Expand Down
12 changes: 7 additions & 5 deletions src/pages/stage-details/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const PageView = () => {
provider: monitoringQuickLink?.metadata?.labels[QUICK_LINK_LABEL_SELECTOR_TYPE],
baseURL: QuickLinksURLs.data?.[SYSTEM_QUICK_LINKS.MONITORING],
namespace: stage.spec.namespace,
clusterName: stage.spec.clusterName,
})}
QuickLinkComponent={monitoringQuickLink}
isTextButton
Expand All @@ -129,11 +130,12 @@ export const PageView = () => {
}}
enabledText="logging dashboard"
iconBase64={loggingQuickLink?.spec?.icon}
externalLink={LinkCreationService.logging.createDashboardLink(
loggingQuickLink?.metadata?.labels[QUICK_LINK_LABEL_SELECTOR_TYPE],
QuickLinksURLs.data?.[SYSTEM_QUICK_LINKS.LOGGING],
stage.spec.namespace
)}
externalLink={LinkCreationService.logging.createDashboardLink({
provider: loggingQuickLink?.metadata?.labels[QUICK_LINK_LABEL_SELECTOR_TYPE],
baseURL: QuickLinksURLs.data?.[SYSTEM_QUICK_LINKS.LOGGING],
namespace: stage.spec.namespace,
clusterName: stage.spec.clusterName,
})}
QuickLinkComponent={loggingQuickLink}
isTextButton
/>
Expand Down
14 changes: 4 additions & 10 deletions src/services/link-creation/deptrack/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
import { DepTrackURLService } from './index';

describe('testing link-creation DepTrackURLService', () => {
it('should successfully create DepTrack project api url based on given depTrackURLOrigin, codebaseName params', () => {
it('should successfully create DepTrack project dashboard link', () => {
expect(
DepTrackURLService.createProjectByNameApiUrl(
DepTrackURLService.createDashboardLink(
'https://deptrack-test.com',
'test-codebase-name'
'test-project-name'
)
).toEqual('https://deptrack-test.com/api/v1/project?name=test-codebase-name');
});

it('should successfully create DepTrack metrics api url based on given depTrackURLOrigin, codebaseName params', () => {
expect(
DepTrackURLService.createProjectVulnsApiUrl('https://deptrack-test.com', 'test-uuid')
).toEqual('https://deptrack-test.com/api/v1/metrics/project/test-uuid/current');
).toEqual('https://deptrack-test.com/projects/test-project-name');
});
});
17 changes: 3 additions & 14 deletions src/services/link-creation/deptrack/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
export const DepTrackURLService = {
createProjectByNameApiUrl: (depTrackURLOrigin: string, codebaseName: string) => {
if (!depTrackURLOrigin) {
createDashboardLink: (baseURL: string, projectID: string) => {
if (!baseURL) {
return undefined;
}

const url = new URL(`${depTrackURLOrigin}/api/v1/project`);

url.searchParams.append('name', codebaseName);

return url.toString();
},
createProjectVulnsApiUrl: (depTrackURLOrigin: string, projectUUID: string) => {
if (!depTrackURLOrigin) {
return undefined;
}

const url = new URL(`${depTrackURLOrigin}/api/v1/metrics/project/${projectUUID}/current`);
const url = new URL(`${baseURL}/projects/${projectID}`);

return url.toString();
},
Expand Down
39 changes: 26 additions & 13 deletions src/services/link-creation/logging/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
import { LoggingURLService } from './index';

describe('testing link-creation LoggingURLService', () => {
it('should successfully create OpenSearch url based on given baseURL and namespace params', () => {
it('should successfully create OpenSearch url', () => {
expect(
LoggingURLService.createDashboardLink(
'opensearch',
'https://kibana-test.com',
'test-namespace'
)
LoggingURLService.createDashboardLink({
provider: 'opensearch',
baseURL: 'https://opensearch-test.com',
namespace: 'test-namespace',
})
).toEqual(
"https://kibana-test.com/app/discover#/?_g=()&_a=(columns:!(log),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,key:kubernetes.namespace_name,negate:!f,params:(query:test-namespace),type:phrase),query:(match_phrase:(kubernetes.namespace_name:test-namespace)))),interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc)))"
"https://opensearch-test.com/app/discover#/?_g=()&_a=(columns:!(log),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,key:kubernetes.namespace_name,negate:!f,params:(query:test-namespace),type:phrase),query:(match_phrase:(kubernetes.namespace_name:test-namespace)))),interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc)))"
);
});

it('should successfully create Datadog url', () => {
expect(
LoggingURLService.createDashboardLink({
provider: 'datadog',
baseURL: 'https://datadog-test.com',
namespace: 'test-namespace',
clusterName: 'test-cluster-name',
})
).toEqual(
'https://datadog-test.com/logs?query=cluster_name%3Atest-cluster-name%20kube_namespace%3Atest-namespace'
);
});

it('should successfully return baseURL if provider is unknown', () => {
expect(
LoggingURLService.createDashboardLink(
'some-provider',
'https://kibana-test.com',
'test-namespace'
)
).toEqual('https://kibana-test.com');
LoggingURLService.createDashboardLink({
provider: 'some-provider',
baseURL: 'https://opensearch-test.com',
namespace: 'test-namespace',
})
).toEqual('https://opensearch-test.com');
});
});
15 changes: 14 additions & 1 deletion src/services/link-creation/logging/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export const LoggingURLService = {
createDashboardLink: (provider: string, baseURL: string, namespace: string) => {
createDashboardLink: ({
provider,
baseURL,
namespace,
clusterName,
}: {
provider: string;
baseURL: string;
namespace: string;
clusterName?: string;
}) => {
if (!baseURL) {
return undefined;
}
Expand All @@ -8,6 +18,9 @@ export const LoggingURLService = {
case 'opensearch': {
return `${baseURL}/app/discover#/?_g=()&_a=(columns:!(log),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,key:kubernetes.namespace_name,negate:!f,params:(query:${namespace}),type:phrase),query:(match_phrase:(kubernetes.namespace_name:${namespace})))),interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc)))`;
}
case 'datadog': {
return `${baseURL}/logs?query=cluster_name%3A${clusterName}%20kube_namespace%3A${namespace}`;
}
default: {
return baseURL;
}
Expand Down
4 changes: 1 addition & 3 deletions src/services/link-creation/monitoring/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Utils } from '@kinvolk/headlamp-plugin/lib';
import { MONITORING_PROVIDERS } from '../../../k8s/groups/EDP/QuickLink/constants';
import { MonitoringURLService } from './index';

Expand All @@ -15,13 +14,12 @@ describe('testing link-creation MonitoringURLService', () => {
);
});
it('should successfully create datadog url based on given baseURL and namespace params', () => {
jest.spyOn(Utils, 'getCluster').mockReturnValue('test-cluster-name');

expect(
MonitoringURLService.createDashboardLink({
provider: MONITORING_PROVIDERS.DATADOG,
baseURL: 'https://datadog-test.com',
namespace: 'test-namespace',
clusterName: 'test-cluster-name',
})
).toEqual(
'https://datadog-test.com/dash/integration/Kubernetes%20-%20Pods?tpl_var_cluster=test-cluster-name&tpl_var_namespace=test-namespace'
Expand Down
4 changes: 2 additions & 2 deletions src/services/link-creation/monitoring/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Utils } from '@kinvolk/headlamp-plugin/lib';
import { MONITORING_PROVIDERS } from '../../../k8s/groups/EDP/QuickLink/constants';

export const MonitoringURLService = {
createDashboardLink: ({
provider,
baseURL,
namespace,
clusterName,
}: {
provider: string;
baseURL: string;
namespace: string;
clusterName?: string;
}) => {
if (!baseURL) {
return undefined;
Expand All @@ -25,7 +26,6 @@ export const MonitoringURLService = {
return `${baseURL}/d/85a562078cdf77779eaa1add43ccec1e/kubernetes-compute-resources-namespace-pods?orgId=1&refresh=10s&var-datasource=default&var-cluster=&var-namespace=${namespace}&theme=${theme}`;
}
case MONITORING_PROVIDERS.DATADOG: {
const clusterName = Utils.getCluster();
return `${baseURL}/dash/integration/Kubernetes%20-%20Pods?tpl_var_cluster=${clusterName}&tpl_var_namespace=${namespace}`;
}
default: {
Expand Down
Loading

0 comments on commit a66c29b

Please sign in to comment.