Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/app/src/components/catalog/EntityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
import {
Environments,
CellDiagram,
RuntimeLogs,
WorkflowsOverviewCard,
ProductionOverviewCard,
RuntimeHealthCard,
Expand All @@ -76,6 +75,7 @@ import {
ObservabilityMetrics,
ObservabilityTraces,
ObservabilityRCA,
ObservabilityRuntimeLogs,
} from '@openchoreo/backstage-plugin-openchoreo-observability';

import { FeatureGate } from '@openchoreo/backstage-plugin-react';
Expand Down Expand Up @@ -178,7 +178,7 @@ const serviceEntityPage = (

<EntityLayout.Route path="/runtime-logs" title="Runtime Logs">
<FeatureGatedContent feature="observability">
<RuntimeLogs />
<ObservabilityRuntimeLogs />
</FeatureGatedContent>
</EntityLayout.Route>

Expand Down Expand Up @@ -252,7 +252,7 @@ const websiteEntityPage = (

<EntityLayout.Route path="/runtime-logs" title="Runtime Logs">
<FeatureGatedContent feature="observability">
<RuntimeLogs />
<ObservabilityRuntimeLogs />
</FeatureGatedContent>
</EntityLayout.Route>

Expand Down
7 changes: 0 additions & 7 deletions plugins/openchoreo-backend/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CellDiagramInfoService } from './services/CellDiagramService/CellDiagra
import { BuildInfoService } from './services/BuildService/BuildInfoService';
import { ComponentInfoService } from './services/ComponentService/ComponentInfoService';
import { ProjectInfoService } from './services/ProjectService/ProjectInfoService';
import { RuntimeLogsInfoService } from './services/RuntimeLogsService/RuntimeLogsService';
import { WorkloadInfoService } from './services/WorkloadService/WorkloadInfoService';
import { DashboardInfoService } from './services/DashboardService/DashboardInfoService';
import { TraitInfoService } from './services/TraitService/TraitInfoService';
Expand Down Expand Up @@ -85,11 +84,6 @@ export const choreoPlugin = createBackendPlugin({

const projectInfoService = new ProjectInfoService(logger, baseUrl);

const runtimeLogsInfoService = new RuntimeLogsInfoService(
logger,
baseUrl,
);

const workloadInfoService = new WorkloadInfoService(logger, baseUrl);

const dashboardInfoService = new DashboardInfoService(logger, baseUrl);
Expand Down Expand Up @@ -144,7 +138,6 @@ export const choreoPlugin = createBackendPlugin({
buildInfoService,
componentInfoService,
projectInfoService,
runtimeLogsInfoService,
workloadInfoService,
dashboardInfoService,
traitInfoService,
Expand Down
90 changes: 0 additions & 90 deletions plugins/openchoreo-backend/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import {
} from './types';
import { ComponentInfoService } from './services/ComponentService/ComponentInfoService';
import { ProjectInfoService } from './services/ProjectService/ProjectInfoService';
import {
RuntimeLogsInfoService,
ObservabilityNotConfiguredError as RuntimeObservabilityNotConfiguredError,
} from './services/RuntimeLogsService/RuntimeLogsService';
import { DashboardInfoService } from './services/DashboardService/DashboardInfoService';
import { TraitInfoService } from './services/TraitService/TraitInfoService';
import { AuthzService } from './services/AuthzService/AuthzService';
Expand All @@ -33,7 +29,6 @@ export async function createRouter({
buildInfoService,
componentInfoService,
projectInfoService,
runtimeLogsInfoService,
workloadInfoService,
dashboardInfoService,
traitInfoService,
Expand All @@ -47,7 +42,6 @@ export async function createRouter({
buildInfoService: BuildInfoService;
componentInfoService: ComponentInfoService;
projectInfoService: ProjectInfoService;
runtimeLogsInfoService: RuntimeLogsInfoService;
workloadInfoService: WorkloadService;
dashboardInfoService: DashboardInfoService;
traitInfoService: TraitInfoService;
Expand Down Expand Up @@ -463,90 +457,6 @@ export async function createRouter({
}
});

// Runtime logs
router.post(
'/logs/component/:componentName',
async (req: express.Request, res: express.Response) => {
const { componentName } = req.params;
const { orgName, projectName } = req.query;
const {
componentId,
environmentName,
environmentId,
logLevels,
startTime,
endTime,
limit,
} = req.body;

if (
!componentName ||
!componentId ||
!environmentName ||
!environmentId
) {
return res.status(422).json({
error: 'Missing Parameter',
message:
'Component Name, Component ID or Environment Name or Environment ID is missing from request',
});
}

const userToken = getUserTokenFromRequest(req);

try {
const result = await runtimeLogsInfoService.fetchRuntimeLogs(
{
componentId,
componentName,
environmentId,
environmentName,
logLevels,
startTime,
endTime,
limit,
},
orgName as string,
projectName as string,
userToken,
);

return res.json(result);
} catch (error: unknown) {
if (error instanceof RuntimeObservabilityNotConfiguredError) {
return res.status(200).json({
message: 'observability is disabled',
});
}

const errorMessage =
error instanceof Error ? error.message : 'Unknown error occurred';

// Check if it's a fetch error with status code info
if (errorMessage.includes('Failed to fetch runtime logs: ')) {
const statusMatch = errorMessage.match(
/Failed to fetch runtime logs: (\d+)/,
);
if (statusMatch) {
const statusCode = parseInt(statusMatch[1], 10);
return res
.status(statusCode >= 400 && statusCode < 600 ? statusCode : 500)
.json({
error: 'Failed to fetch runtime logs',
message: errorMessage,
});
}
}

// Default to 500 for other errors
return res.status(500).json({
error: 'Internal server error',
message: errorMessage,
});
}
},
);

router.get('/workload', async (req, res) => {
const { componentName, projectName, organizationName } = req.query;

Expand Down
7 changes: 7 additions & 0 deletions plugins/openchoreo-observability-backend/src/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ describe('plugin', () => {
reports: [],
}),
fetchRCAReportByAlert: jest.fn().mockResolvedValue({}),
fetchRuntimeLogsByComponent: jest.fn().mockResolvedValue({
logs: [],
totalCount: 0,
}),
}),
}),
],
Expand Down Expand Up @@ -114,6 +118,9 @@ describe('plugin', () => {
fetchRCAReportByAlert: jest
.fn()
.mockRejectedValue(new Error('Failed to fetch RCA report')),
fetchRuntimeLogsByComponent: jest
.fn()
.mockRejectedValue(new Error('Failed to fetch runtime logs')),
}),
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('createRouter', () => {
fetchTracesByProject: jest.fn(),
fetchRCAReportsByProject: jest.fn(),
fetchRCAReportByAlert: jest.fn(),
fetchRuntimeLogsByComponent: jest.fn(),
};
tokenService = {
getUserToken: jest.fn().mockReturnValue(undefined),
Expand Down
27 changes: 27 additions & 0 deletions plugins/openchoreo-observability-backend/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ export async function createRouter({
}
});

router.post('/logs/component/:componentName', async (_req, res) => {
// Only enforce user auth when auth feature is enabled
// When auth is disabled (guest mode), skip httpAuth check
if (authEnabled) {
await httpAuth.credentials(_req, { allow: ['user'] });
}
const userToken = getUserTokenFromRequest(_req);
try {
const logs = await observabilityService.fetchRuntimeLogsByComponent(
_req.body.componentId,
_req.body.projectId,
_req.body.environmentId,
_req.body.orgName,
_req.body.projectName,
_req.body.environmentName,
_req.body.componentName,
_req.body.options,
userToken,
);
return res.status(200).json(logs);
} catch (error) {
return res.status(500).json({
error: error instanceof Error ? error.message : 'Failed to fetch logs',
});
}
});

router.get('/environments', async (req, res) => {
// Only enforce user auth when auth feature is enabled
if (authEnabled) {
Expand Down
Loading