Removed log search error message in console logs (#890)

Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
Alex
2021-07-21 18:13:23 -05:00
committed by GitHub
parent 2e1e4e4e80
commit d88146459a
4 changed files with 68 additions and 57 deletions

View File

@@ -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<boolean>(true);
const [timeStart, setTimeStart] = useState<any>(null);
const [timeEnd, setTimeEnd] = useState<any>(null);
@@ -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}` : ""
@@ -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));

View File

@@ -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";
@@ -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<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));

View File

@@ -230,7 +230,7 @@ func getLogSearchAPIToken() string {
}
func getLogSearchURL() string {
return env.Get(ConsoleLogQueryURL, "http://localhost:8080")
return env.Get(ConsoleLogQueryURL, "")
}
func getPrometheusURL() string {

View File

@@ -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
}