Skip to content

Commit d881464

Browse files
bexsoftBenjamin Perez
andauthored
Removed log search error message in console logs (#890)
Co-authored-by: Benjamin Perez <[email protected]>
1 parent 2e1e4e4 commit d881464

File tree

4 files changed

+68
-57
lines changed

4 files changed

+68
-57
lines changed

portal-ui/src/screens/Console/Logs/LogSearch/LogsSearchMain.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ import api from "../../../../common/api";
3434
import TableWrapper from "../../Common/TableWrapper/TableWrapper";
3535
import FilterInputWrapper from "../../Common/FormComponents/FilterInputWrapper/FilterInputWrapper";
3636
import DateTimePickerWrapper from "../../Common/FormComponents/DateTimePickerWrapper/DateTimePickerWrapper";
37+
import { AppState } from "../../../../store";
3738

3839
interface ILogSearchProps {
3940
classes: any;
41+
features: string[] | null;
4042
setErrorSnackMessage: typeof setErrorSnackMessage;
4143
}
4244

@@ -118,7 +120,11 @@ const styles = (theme: Theme) =>
118120
...containerForHeader(theme.spacing(4)),
119121
});
120122

121-
const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
123+
const LogsSearchMain = ({
124+
classes,
125+
features,
126+
setErrorSnackMessage,
127+
}: ILogSearchProps) => {
122128
const [loading, setLoading] = useState<boolean>(true);
123129
const [timeStart, setTimeStart] = useState<any>(null);
124130
const [timeEnd, setTimeEnd] = useState<any>(null);
@@ -147,9 +153,10 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
147153
const [alreadyFetching, setAlreadyFetching] = useState<boolean>(false);
148154

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

151158
const fetchRecords = useCallback(() => {
152-
if (!alreadyFetching) {
159+
if (!alreadyFetching && logSearchEnabled) {
153160
setAlreadyFetching(true);
154161
let queryParams = `${bucket !== "" ? `&fp=bucket:${bucket}` : ""}${
155162
object !== "" ? `&fp=object:${object}` : ""
@@ -196,6 +203,8 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
196203
});
197204
}
198205
}, [
206+
alreadyFetching,
207+
logSearchEnabled,
199208
bucket,
200209
object,
201210
apiName,
@@ -206,7 +215,6 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
206215
sortOrder,
207216
timeStart,
208217
timeEnd,
209-
alreadyFetching,
210218
records,
211219
recordsResp,
212220
setErrorSnackMessage,
@@ -429,10 +437,14 @@ const LogsSearchMain = ({ classes, setErrorSnackMessage }: ILogSearchProps) => {
429437
);
430438
};
431439

440+
const mapState = (state: AppState) => ({
441+
features: state.console.session.features,
442+
});
443+
432444
const mapDispatchToProps = {
433445
setErrorSnackMessage,
434446
};
435447

436-
const connector = connect(null, mapDispatchToProps);
448+
const connector = connect(mapState, mapDispatchToProps);
437449

438450
export default withStyles(styles)(connector(LogsSearchMain));

portal-ui/src/screens/Console/Logs/LogsMain.tsx

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { Fragment, useState, useEffect } from "react";
18+
import { connect } from "react-redux";
1819
import PageHeader from "../Common/PageHeader/PageHeader";
1920
import { Grid, LinearProgress } from "@material-ui/core";
2021
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
@@ -24,9 +25,11 @@ import { containerForHeader } from "../Common/FormComponents/common/styleLibrary
2425
import ErrorLogs from "./ErrorLogs/ErrorLogs";
2526
import LogsSearchMain from "./LogSearch/LogsSearchMain";
2627
import api from "../../../common/api";
28+
import { AppState } from "../../../store";
2729

2830
interface ILogsMainProps {
2931
classes: any;
32+
features: string[] | null;
3033
}
3134

3235
const styles = (theme: Theme) =>
@@ -40,68 +43,58 @@ const styles = (theme: Theme) =>
4043
...containerForHeader(theme.spacing(4)),
4144
});
4245

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

48-
useEffect(() => {
49-
api
50-
.invoke("GET", `/api/v1/logs/search?q=reqinfo&pageSize=10&pageNo=0`)
51-
.then(() => {
52-
setShowLogSearch(true);
53-
setLoading(false);
54-
})
55-
.catch((err: any) => {
56-
setLoading(false);
57-
console.info("Log Search API not available.");
58-
});
59-
}, [loading]);
49+
const logSearchEnabled = features && features.includes("log-search");
6050

6151
return (
6252
<Fragment>
6353
<PageHeader label="Logs" />
6454
<Grid container>
6555
<Grid item xs={12} className={classes.container}>
66-
{!loading ? (
67-
<Fragment>
68-
<Grid item xs={12} className={classes.headerLabel}>
69-
All Logs
70-
</Grid>
71-
<Tabs
72-
value={currentTab}
73-
onChange={(e: React.ChangeEvent<{}>, newValue: number) => {
74-
setCurrentTab(newValue);
75-
}}
76-
indicatorColor="primary"
77-
textColor="primary"
78-
aria-label="cluster-tabs"
79-
variant="scrollable"
80-
scrollButtons="auto"
81-
>
82-
<Tab label="Error Logs" />
83-
{showLogSearch && <Tab label="Logs Search" />}
84-
</Tabs>
85-
<Grid item xs={12}>
86-
{currentTab === 0 && (
87-
<Grid item xs={12}>
88-
<ErrorLogs />
89-
</Grid>
90-
)}
91-
{currentTab === 1 && showLogSearch && (
92-
<Grid item xs={12}>
93-
<LogsSearchMain />
94-
</Grid>
95-
)}
96-
</Grid>
97-
</Fragment>
98-
) : (
99-
<LinearProgress />
100-
)}
56+
<Fragment>
57+
<Grid item xs={12} className={classes.headerLabel}>
58+
All Logs
59+
</Grid>
60+
<Tabs
61+
value={currentTab}
62+
onChange={(e: React.ChangeEvent<{}>, newValue: number) => {
63+
setCurrentTab(newValue);
64+
}}
65+
indicatorColor="primary"
66+
textColor="primary"
67+
aria-label="cluster-tabs"
68+
variant="scrollable"
69+
scrollButtons="auto"
70+
>
71+
<Tab label="Error Logs" />
72+
{logSearchEnabled && <Tab label="Logs Search" />}
73+
</Tabs>
74+
<Grid item xs={12}>
75+
{currentTab === 0 && (
76+
<Grid item xs={12}>
77+
<ErrorLogs />
78+
</Grid>
79+
)}
80+
{currentTab === 1 &&
81+
logSearchEnabled && (
82+
<Grid item xs={12}>
83+
<LogsSearchMain />
84+
</Grid>
85+
)}
86+
</Grid>
87+
</Fragment>
10188
</Grid>
10289
</Grid>
10390
</Fragment>
10491
);
10592
};
10693

107-
export default withStyles(styles)(LogsMain);
94+
const mapState = (state: AppState) => ({
95+
features: state.console.session.features,
96+
});
97+
98+
const connector = connect(mapState, null);
99+
100+
export default withStyles(styles)(connector(LogsMain));

restapi/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func getLogSearchAPIToken() string {
230230
}
231231

232232
func getLogSearchURL() string {
233-
return env.Get(ConsoleLogQueryURL, "http://localhost:8080")
233+
return env.Get(ConsoleLogQueryURL, "")
234234
}
235235

236236
func getPrometheusURL() string {

restapi/user_session.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ func getSessionResponse(session *models.Principal) (*models.SessionResponse, *mo
7373
Features: getListOfEnabledFeatures(),
7474
Status: models.SessionResponseStatusOk,
7575
Operator: acl.GetOperatorMode(),
76-
DistributedMode: validateDistributedMode(session), // TODO: Review why this function is always returning false
76+
DistributedMode: validateDistributedMode(session),
7777
}
7878
return sessionResp, nil
7979
}
8080

8181
// getListOfEnabledFeatures returns a list of features
8282
func getListOfEnabledFeatures() []string {
8383
var features []string
84+
logSearchURL := getLogSearchURL()
85+
86+
if logSearchURL != "" {
87+
features = append(features, "log-search")
88+
}
89+
8490
return features
8591
}

0 commit comments

Comments
 (0)