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
20 changes: 16 additions & 4 deletions portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ import api from "../../../../common/api";
import TableWrapper from "../../Common/TableWrapper/TableWrapper";
import FilterInputWrapper from "../../Common/FormComponents/FilterInputWrapper/FilterInputWrapper";
import DateTimePickerWrapper from "../../Common/FormComponents/DateTimePickerWrapper/DateTimePickerWrapper";
import { AppState } from "../../../../store";

interface ILogSearchProps {
classes: any;
features: string[] | null;
setErrorSnackMessage: typeof setErrorSnackMessage;
}

Expand Down Expand Up @@ -118,7 +120,11 @@ const styles = (theme: Theme) =>
...containerForHeader(theme.spacing(4)),
});

const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
const LogsSearchMain = ({
classes,
features,
setErrorSnackMessage,
}: ILogSearchProps) => {
const [loading, setLoading] = useState<boolean>(true);
const [timeStart, setTimeStart] = useState<any>(null);
const [timeEnd, setTimeEnd] = useState<any>(null);
Expand Down Expand Up @@ -147,9 +153,10 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
const [alreadyFetching, setAlreadyFetching] = useState<boolean>(false);

let recordsResp: any = null;
const logSearchEnabled = features && features.includes("log-search");

const fetchRecords = useCallback(() => {
if (!alreadyFetching) {
if (!alreadyFetching && logSearchEnabled) {
setAlreadyFetching(true);
let queryParams = `${bucket !== "" ? `&fp=bucket:${bucket}` : ""}${
object !== "" ? `&fp=object:${object}` : ""
Expand Down Expand Up @@ -196,6 +203,8 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
});
}
}, [
alreadyFetching,
logSearchEnabled,
bucket,
object,
apiName,
Expand All @@ -206,7 +215,6 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
sortOrder,
timeStart,
timeEnd,
alreadyFetching,
records,
recordsResp,
setErrorSnackMessage,
Expand Down Expand Up @@ -429,10 +437,14 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
);
};

const mapState = (state: AppState) => ({
features: state.console.session.features,
});

const mapDispatchToProps = {
setErrorSnackMessage,
};

const connector = connect(null, mapDispatchToProps);
const connector = connect(mapState, mapDispatchToProps);

export default withStyles(styles)(connector(LogsSearchMain));
95 changes: 44 additions & 51 deletions portal-ui/src/screens/Console/Logs/LogsMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import React, { Fragment, useState, useEffect } from "react";
import { connect } from "react-redux";
import PageHeader from "../Common/PageHeader/PageHeader";
import { Grid, LinearProgress } from "@material-ui/core";
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
Expand All @@ -24,9 +25,11 @@ import { containerForHeader } from "../Common/FormComponents/common/styleLibrary
import ErrorLogs from "./ErrorLogs/ErrorLogs";
import LogsSearchMain from "./LogSearch/LogsSearchMain";
import api from "../../../common/api";
import { AppState } from "../../../store";

interface ILogsMainProps {
classes: any;
features: string[] | null;
}

const styles = (theme: Theme) =>
Expand All @@ -40,68 +43,58 @@ const styles = (theme: Theme) =>
...containerForHeader(theme.spacing(4)),
});

const LogsMain = ({ classes }: ILogsMainProps) => {
const LogsMain = ({ classes, features }: ILogsMainProps) => {
const [currentTab, setCurrentTab] = useState<number>(0);
const [loading, setLoading] = useState<boolean>(true);
const [showLogSearch, setShowLogSearch] = useState<boolean>(false);

useEffect(() => {
api
.invoke("GET", `/api/v1/logs/search?q=reqinfo&pageSize=10&pageNo=0`)
.then(() => {
setShowLogSearch(true);
setLoading(false);
})
.catch((err: any) => {
setLoading(false);
console.info("Log Search API not available.");
});
}, [loading]);
const logSearchEnabled = features && features.includes("log-search");

return (
<Fragment>
<PageHeader label="Logs" />
<Grid container>
<Grid item xs={12} className={classes.container}>
{!loading ? (
<Fragment>
<Grid item xs={12} className={classes.headerLabel}>
All Logs
</Grid>
<Tabs
value={currentTab}
onChange={(e: React.ChangeEvent<{}>, newValue: number) => {
setCurrentTab(newValue);
}}
indicatorColor="primary"
textColor="primary"
aria-label="cluster-tabs"
variant="scrollable"
scrollButtons="auto"
>
<Tab label="Error Logs" />
{showLogSearch && <Tab label="Logs Search" />}
</Tabs>
<Grid item xs={12}>
{currentTab === 0 && (
<Grid item xs={12}>
<ErrorLogs />
</Grid>
)}
{currentTab === 1 && showLogSearch && (
<Grid item xs={12}>
<LogsSearchMain />
</Grid>
)}
</Grid>
</Fragment>
) : (
<LinearProgress />
)}
<Fragment>
<Grid item xs={12} className={classes.headerLabel}>
All Logs
</Grid>
<Tabs
value={currentTab}
onChange={(e: React.ChangeEvent<{}>, newValue: number) => {
setCurrentTab(newValue);
}}
indicatorColor="primary"
textColor="primary"
aria-label="cluster-tabs"
variant="scrollable"
scrollButtons="auto"
>
<Tab label="Error Logs" />
{logSearchEnabled && <Tab label="Logs Search" />}
</Tabs>
<Grid item xs={12}>
{currentTab === 0 && (
<Grid item xs={12}>
<ErrorLogs />
</Grid>
)}
{currentTab === 1 &&
logSearchEnabled && (
<Grid item xs={12}>
<LogsSearchMain />
</Grid>
)}
</Grid>
</Fragment>
</Grid>
</Grid>
</Fragment>
);
};

export default withStyles(styles)(LogsMain);
const mapState = (state: AppState) => ({
features: state.console.session.features,
});

const connector = connect(mapState, null);

export default withStyles(styles)(connector(LogsMain));
2 changes: 1 addition & 1 deletion restapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func getLogSearchAPIToken() string {
}

func getLogSearchURL() string {
return env.Get(ConsoleLogQueryURL, "http://localhost:8080")
return env.Get(ConsoleLogQueryURL, "")
}

func getPrometheusURL() string {
Expand Down
8 changes: 7 additions & 1 deletion restapi/user_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,19 @@ func getSessionResponse(session *models.Principal) (*models.SessionResponse, *mo
Features: getListOfEnabledFeatures(),
Status: models.SessionResponseStatusOk,
Operator: acl.GetOperatorMode(),
DistributedMode: validateDistributedMode(session), // TODO: Review why this function is always returning false
DistributedMode: validateDistributedMode(session),
}
return sessionResp, nil
}

// getListOfEnabledFeatures returns a list of features
func getListOfEnabledFeatures() []string {
var features []string
logSearchURL := getLogSearchURL()

if logSearchURL != "" {
features = append(features, "log-search")
}

return features
}