diff --git a/portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx b/portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx index cfcdcee251..dabfcf0335 100644 --- a/portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx +++ b/portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx @@ -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; } @@ -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(true); const [timeStart, setTimeStart] = useState(null); const [timeEnd, setTimeEnd] = useState(null); @@ -147,9 +153,10 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => { const [alreadyFetching, setAlreadyFetching] = useState(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}` : "" @@ -196,6 +203,8 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => { }); } }, [ + alreadyFetching, + logSearchEnabled, bucket, object, apiName, @@ -206,7 +215,6 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => { sortOrder, timeStart, timeEnd, - alreadyFetching, records, recordsResp, setErrorSnackMessage, @@ -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)); diff --git a/portal-ui/src/screens/Console/Logs/LogsMain.tsx b/portal-ui/src/screens/Console/Logs/LogsMain.tsx index 9d39b93e69..5395eabdb6 100644 --- a/portal-ui/src/screens/Console/Logs/LogsMain.tsx +++ b/portal-ui/src/screens/Console/Logs/LogsMain.tsx @@ -15,6 +15,7 @@ // along with this program. If not, see . 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"; @@ -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) => @@ -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(0); - const [loading, setLoading] = useState(true); - const [showLogSearch, setShowLogSearch] = useState(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 ( - {!loading ? ( - - - All Logs - - , newValue: number) => { - setCurrentTab(newValue); - }} - indicatorColor="primary" - textColor="primary" - aria-label="cluster-tabs" - variant="scrollable" - scrollButtons="auto" - > - - {showLogSearch && } - - - {currentTab === 0 && ( - - - - )} - {currentTab === 1 && showLogSearch && ( - - - - )} - - - ) : ( - - )} + + + All Logs + + , newValue: number) => { + setCurrentTab(newValue); + }} + indicatorColor="primary" + textColor="primary" + aria-label="cluster-tabs" + variant="scrollable" + scrollButtons="auto" + > + + {logSearchEnabled && } + + + {currentTab === 0 && ( + + + + )} + {currentTab === 1 && + logSearchEnabled && ( + + + + )} + + ); }; -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)); diff --git a/restapi/config.go b/restapi/config.go index 592a43376a..338096645d 100644 --- a/restapi/config.go +++ b/restapi/config.go @@ -230,7 +230,7 @@ func getLogSearchAPIToken() string { } func getLogSearchURL() string { - return env.Get(ConsoleLogQueryURL, "http://localhost:8080") + return env.Get(ConsoleLogQueryURL, "") } func getPrometheusURL() string { diff --git a/restapi/user_session.go b/restapi/user_session.go index ec94c31c3b..c3758e1b5e 100644 --- a/restapi/user_session.go +++ b/restapi/user_session.go @@ -73,7 +73,7 @@ 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 } @@ -81,5 +81,11 @@ func getSessionResponse(session *models.Principal) (*models.SessionResponse, *mo // getListOfEnabledFeatures returns a list of features func getListOfEnabledFeatures() []string { var features []string + logSearchURL := getLogSearchURL() + + if logSearchURL != "" { + features = append(features, "log-search") + } + return features }