Skip to content

Commit

Permalink
#126 Application Log available in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ymolodkov committed Mar 3, 2025
1 parent 2d9c48b commit dcfc1ea
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 4 deletions.
6 changes: 4 additions & 2 deletions datanode-ui/public/translations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"users": "Users",
"databases": "Databases",
"envs": "Environments",
"system_settings": "System Settings"
"system_settings": "System Settings",
"application_log": "Application log"
},
"pages": {
"login": {
Expand All @@ -28,7 +29,8 @@
"databases": "Databases",
"users": "Users",
"envs": "Environments",
"system_settings": "System Settings"
"system_settings": "System Settings",
"application_log": "Application log"
},
"users": {
"header": "Users",
Expand Down
3 changes: 2 additions & 1 deletion datanode-ui/src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { api } from ".";
import { UserDTOSearchInterface } from "../libs/types";
import {UserDTOInterface, UserDTOSearchInterface} from "../libs/types";

export const getUsers = (): Promise<UserDTOSearchInterface[]> =>
api.get("/admin/admins");
Expand All @@ -34,3 +34,4 @@ export const systemSettings = (): Promise<any> => api.get("/admin/system-setting

export const updateSystemSettings = (value): Promise<any> => api.post("/admin/system-settings", value);

export const getApplicationLog = (): Promise<string> => api.get(`/application/logs/`);
4 changes: 4 additions & 0 deletions datanode-ui/src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,8 @@ export const tabsAdmin = (t: any): TabsInterface[] => [
value: "system-settings",
title: t("pages.administration.tabs.system_settings"),
},
{
value: "application-log",
title: t("pages.administration.tabs.application_log"),
}
];
3 changes: 2 additions & 1 deletion datanode-ui/src/libs/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export * from "./useList";
export * from "./useModal";
export * from "./useInterval";
export * from "./useSystemSettings";
export * from "./useSubmissionLog";
export * from "./useSubmissionLog";
export * from "./useApplicaionLog";
1 change: 1 addition & 0 deletions datanode-ui/src/libs/hooks/useApplicaionLog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./useApplicationLog";
32 changes: 32 additions & 0 deletions datanode-ui/src/libs/hooks/useApplicaionLog/useApplicationLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useState, useEffect } from 'react';
import { getApplicationLog } from "../../../api/admin";
import { useInterval } from '../useInterval';

export const useApplicationLog = () => {
const [logs, setLogs] = useState<string>('');
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);

const fetchLogs = async () => {
try {
const response = await getApplicationLog();
setLogs(response);
setError(null);
} catch (err) {
setError('Error fetching logs');
} finally {
setLoading(false);
}
};

useInterval(() => {
fetchLogs();
}, 10000);

useEffect(() => {
fetchLogs();
}, []);

return { logs, loading, error };
};

4 changes: 4 additions & 0 deletions datanode-ui/src/modules/Admin/Admin.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const tabsAdmin: TabsInterface[] = [
value: "environments",
title: "Enviroments",
},
{
value: 'application-log',
title: 'Application log',
},
{
value: "system-settings",
title: "System settings",
Expand Down
52 changes: 52 additions & 0 deletions datanode-ui/src/modules/Admin/ApplicationLog/ApplicationLog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, {useEffect} from "react";
import {Grid, Paper} from "@mui/material";
import {useTranslation} from "react-i18next";
import {CodeEditor} from "../../../libs/components";
import {useDispatch} from "react-redux";
import {setBreadcrumbs} from "../../../store/modules";
import {useApplicationLog} from "../../../libs/hooks";

export const ApplicationLog: React.FC = () => {
const {logs, loading, error} = useApplicationLog();
const dispatch = useDispatch();
const {t} = useTranslation();

useEffect(() => {
dispatch(
setBreadcrumbs([
{
name: t("breadcrumbs.admin"),
path: "/administration",
},
{
name: t("breadcrumbs.application_log"),
path: "/application-log",
},
])
);
}, [dispatch, t]);

return (
<Paper elevation={0} sx={{p: 2, width:'100%'}}>
{loading ? (
<div>Loading...</div>
) : error ? (
<div>{error}</div>
) : logs ? (
<CodeEditor
data={logs || ""}
height={"73vh"}
containerStyles={{padding: 0}}
enableDownload={true}
enableCopy
readOnly
consoleMode
/>
) : (
<Grid item xs={12}>
<div>No available logs</div>
</Grid>
)}
</Paper>
);
};
18 changes: 18 additions & 0 deletions datanode-ui/src/modules/Admin/ApplicationLog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
*
* Copyright 2023 Odysseus Data Services, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

export * from "./ApplicationLog";
2 changes: 2 additions & 0 deletions datanode-ui/src/modules/Admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Databases } from "./Databases";
import { Users } from "./Users";
import { SystemSettings } from "./SystemSettings";
import { EnviromentsList } from "./Enviroments";
import { ApplicationLog } from "./ApplicationLog";
import { tabsAdmin } from "../../config";

export const IndexAdmin: React.FC = () => {
Expand Down Expand Up @@ -66,6 +67,7 @@ export const IndexAdmin: React.FC = () => {
<Route path="users/*" element={<Users />} />
<Route path="environments/*" element={<EnviromentsList />} />
<Route path="system-settings/*" element={<SystemSettings />} />
<Route path="application-log/*" element={<ApplicationLog />} />
</Routes>
</Grid>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.odysseusinc.arachne.datanode.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

@Controller
public class LogController {

@Value("${logging.file.name}")
private String logFilePath;

@RequestMapping(method = RequestMethod.GET, value = "/api/v1/application/logs/")
public ResponseEntity<String> getLogs() throws IOException {
String logs = new String(Files.readAllBytes(Paths.get(logFilePath)));
return ResponseEntity.ok(logs);
}
}
2 changes: 2 additions & 0 deletions datanode/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ security:
validityInSeconds: ${datanode.jwt.expiration}

logging:
file:
name: logs/arachne.log
level:
root: INFO
org.springframework.web.servlet.PageNotFound: ERROR

0 comments on commit dcfc1ea

Please sign in to comment.