Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#126 Application Log available in UI #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 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
7 changes: 6 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,8 @@ 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 = (range: string): Promise<string> => {
return api.get(`/application/logs/`, {
headers: { 'Range': range }
});
};
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";
35 changes: 35 additions & 0 deletions datanode-ui/src/libs/hooks/useApplicaionLog/useApplicationLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 MB = 1024 * 1024;

const fetchLogs = async () => {
try {
const response = await getApplicationLog(`bytes=-${MB}`);
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,31 @@
package com.odysseusinc.arachne.datanode.controller;

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

@Controller
public class LogController {

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


/**
* This method handles requests to retrieve logs.
* It supports Range queries (e.g., "Range: bytes=-1048576" for the last 1 MB of the file).
*
* @return ResponseEntity<Resource> containing the log file content.
*/
@RequestMapping(method = RequestMethod.GET, value = "/api/v1/application/logs/")
public ResponseEntity<Resource> getLogs() {
return ResponseEntity.ok().body(
new FileSystemResource(logFilePath)
);
}

}
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