You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/11/02 15:39:07 UTC

[GitHub] [pinot] jadami10 commented on a diff in pull request #9700: WIP UI: show segment debug details when segment is in bad state

jadami10 commented on code in PR #9700:
URL: https://github.com/apache/pinot/pull/9700#discussion_r1011959959


##########
pinot-controller/src/main/resources/app/components/SegmentStatusRenderer.tsx:
##########
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import {
+  Box,
+  Chip,
+  CircularProgress,
+  IconButton,
+  makeStyles,
+  Tooltip,
+} from "@material-ui/core";
+import { HelpOutlineOutlined } from "@material-ui/icons";
+import { DISPLAY_SEGMENT_STATUS, SegmentDebugDetails } from "Models";
+import React, { useContext, useEffect, useState } from "react";
+import { getSegmentLevelDebugDetails } from "../requests";
+import CustomCodemirror from "./CustomCodemirror";
+import CustomDialog from "./CustomDialog";
+import { NotificationContext } from "./Notification/NotificationContext";
+
+const useStyles = makeStyles((theme) => ({
+  error: {
+    color: theme.palette.error.main,
+    border: `1px solid ${theme.palette.error.main}`,
+  },
+  success: {
+    color: theme.palette.success.main,
+    border: `1px solid ${theme.palette.success.main}`,
+  },
+  info: {
+    color: theme.palette.info.main,
+    border: `1px solid ${theme.palette.info.main}`,
+  },
+  warning: {
+    color: theme.palette.warning.main,
+    border: `1px solid ${theme.palette.warning.main}`,
+  },
+  segmentDebugDetails: {
+    "& .CodeMirror": { fontSize: 14, height: "100%" },
+    maxHeight: 500,
+  },
+}));
+
+interface SegmentStatusRendererProps {
+  status: DISPLAY_SEGMENT_STATUS;
+  segmentName: string;
+  tableName: string;
+}
+
+export enum StatusVariant {
+  Error = "error",
+  Warning = "warning",
+  Info = "info",
+  Success = "success",
+}
+
+export const SegmentStatusRenderer = ({
+  status,
+  segmentName,
+  tableName,
+}: SegmentStatusRendererProps) => {
+  const [statusTooltipTitle, setStatusTooltipTitle] = useState<string>("");
+  const [statusVariant, setStatusVariant] = useState<StatusVariant | null>(
+    null
+  );
+  const segmentStatusRendererClasses = useStyles();
+  const [errorDetailsVisible, setErrorDetailsVisible] =
+    useState<boolean>(false);
+  const [segmentDebugDetails, setSegmentDebugDetails] =
+    useState<SegmentDebugDetails | null>(null);
+  const { dispatch: notify } = useContext(NotificationContext);
+
+  useEffect(() => {
+    initializeValues();
+  }, []);
+
+  const initializeValues = () => {
+    switch (status) {
+      case DISPLAY_SEGMENT_STATUS.GOOD: {
+        setStatusVariant(StatusVariant.Success);
+        setStatusTooltipTitle("Segment is in healthy state");
+
+        break;
+      }
+      case DISPLAY_SEGMENT_STATUS.BAD: {
+        setStatusVariant(StatusVariant.Error);
+        setStatusTooltipTitle("One or more server is in error state");
+
+        break;
+      }
+      case DISPLAY_SEGMENT_STATUS.PARTIAL: {
+        setStatusVariant(StatusVariant.Warning);
+        setStatusTooltipTitle("External view is in offline state");
+
+        break;
+      }
+    }
+  };
+
+  const fetchSegmentErrorDetails = async () => {
+    setSegmentDebugDetails(null);
+    try {
+      const segmentDebugDetails = await getSegmentLevelDebugDetails(
+        tableName,
+        segmentName
+      );
+      setSegmentDebugDetails(segmentDebugDetails);
+    } catch (error) {
+      notify({
+        type: "error",
+        message: "Error occurred while fetching segment debug details.",
+        show: true,
+      });
+      setSegmentDebugDetails({} as SegmentDebugDetails);
+    }
+  };
+
+  const handleShowErrorDetailsClick = () => {
+    setErrorDetailsVisible(true);
+    fetchSegmentErrorDetails();
+  };
+
+  const handleHideErrorDetails = () => {
+    setErrorDetailsVisible(false);
+  };
+
+  return (
+    <>
+      <Tooltip arrow title={statusTooltipTitle} placement="top">
+        <Chip
+          className={
+            statusVariant ? segmentStatusRendererClasses[statusVariant] : ""
+          }
+          label={status}
+          variant="outlined"
+        />
+      </Tooltip>
+
+      {/* Only show when segment status is bad */}
+      {status === DISPLAY_SEGMENT_STATUS.BAD && (
+        <>
+          <Tooltip
+            title="Click to show segment error details"
+            arrow
+            placement="top"
+          >
+            <IconButton onClick={handleShowErrorDetailsClick}>
+              <HelpOutlineOutlined fontSize="small" />
+            </IconButton>
+          </Tooltip>
+          <CustomDialog
+            title="Segment Debug Details"
+            open={errorDetailsVisible}
+            handleClose={handleHideErrorDetails}
+            showOkBtn={false}
+          >
+            {/* Loading */}
+            {!segmentDebugDetails && (
+              <Box display="flex" justifyContent="center"><CircularProgress /></Box>
+            )}
+            {segmentDebugDetails && (
+              <CustomCodemirror

Review Comment:
   can we add `shouldLineWrapToggler` similar to https://github.com/apache/pinot/blob/84478b645188174a9e56cf565f813dbf80a8acf3/pinot-controller/src/main/resources/app/pages/ZookeeperPage.tsx#L195? I imagine the errors specifically can get quite long



##########
pinot-controller/src/main/resources/app/utils/axios-config.ts:
##########
@@ -65,4 +65,11 @@ baseApi.interceptors.response.use(handleResponse, handleError);
 
 export const transformApi = axios.create({baseURL: '/', transformResponse: [data => data]});
 transformApi.interceptors.request.use(handleConfig, handleError);
-transformApi.interceptors.response.use(handleResponse, handleError);
\ No newline at end of file
+transformApi.interceptors.response.use(handleResponse, handleError);
+
+// baseApi axios instance does not throw an error when API fails hence the control will never go to catch block
+// changing the handleError method of baseApi will cause current UI to break (as UI might have not handle error properly)
+// creating a new axios instance baseApiV1 which can be used when adding new API's
+export const baseApiV1 = axios.create({ baseURL: '/' });

Review Comment:
   nit: let's maybe rename this more clearly to baseApiWithErrors so it's clear? but also, why did you need this? There's not any error handling being done above



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org