/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed 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 React, { useState, useEffect } from "react"; import SideMenu from "components/SideMenu"; import Breadcrumb from "components/Breadcrumb"; import { useTranslation } from "react-i18next"; import { Link, useParams } from "react-router-dom"; import LoadingText from "components/LoadingText"; import HeaderPanel from "components/HeaderPanel"; import ValueWithLabel from "components/ValueWithLabel"; import { AntTab, AntTabs, TabPanel } from "components/Tab"; import { appSyncRequestQuery } from "assets/js/request"; import { getAppLogIngestion, getAppPipeline, getLogSource, } from "graphql/queries"; import { AppLogIngestion, AppPipeline, BufferType, LogSource, LogSourceType, } from "API"; import { buildKDSLink, buildS3Link, formatLocalTime, splitStringToBucketAndPrefix, } from "assets/js/utils"; import ExtLink from "components/ExtLink"; import { AmplifyConfigType } from "types"; import { AppStateProps } from "reducer/appReducer"; import { useSelector } from "react-redux"; import Tags from "./comps/Tags"; import LogConfig from "./comps/LogConfig"; import AccountName from "pages/comps/account/AccountName"; import { getParamValueByKey, getSourceInfoValueByKey } from "assets/js/applog"; import CopyText from "components/CopyText"; import SyslogGuide from "./comps/SyslogGuide"; interface MatchParams { id: string; } const AppIngestionDetail: React.FC = () => { const { t } = useTranslation(); const amplifyConfig: AmplifyConfigType = useSelector( (state: AppStateProps) => state.amplifyConfig ); const { id }: MatchParams = useParams(); const [loadingData, setLoadingData] = useState(true); const [activeTab, setActiveTab] = useState(0); const [appIngestionData, setAppIngestionData] = useState(); const [appPipelineData, setAppPipelineData] = useState(); const [sourceInfo, setSourceInfo] = useState(); const breadCrumbList = [ { name: t("name"), link: "/" }, { name: t("menu.appLog"), link: "/log-pipeline/application-log", }, { name: appIngestionData?.appPipelineId || "", link: "/log-pipeline/application-log/detail/" + appPipelineData?.id, }, { name: id }, ]; const changeTab = (event: any, newTab: number) => { console.info("newTab:", newTab); setActiveTab(newTab); }; const getAppPiplelineInfoById = async (pipelineId: string) => { try { const resPipelineData: any = await appSyncRequestQuery(getAppPipeline, { id: pipelineId, }); setLoadingData(false); const tmpPipelinenData: AppPipeline = resPipelineData?.data?.getAppPipeline; setAppPipelineData(tmpPipelinenData); } catch (error) { console.error(error); } }; const getAppLogIngestionById = async () => { setLoadingData(true); try { const resIngestionData: any = await appSyncRequestQuery( getAppLogIngestion, { id: id, } ); const tmpIngestionData: AppLogIngestion = resIngestionData?.data?.getAppLogIngestion; if (tmpIngestionData && tmpIngestionData.appPipelineId) { if (tmpIngestionData.sourceType === LogSourceType.Syslog) { const sourceData = await appSyncRequestQuery(getLogSource, { sourceType: tmpIngestionData.sourceType, id: tmpIngestionData.sourceId, }); setSourceInfo(sourceData.data.getLogSource); } getAppPiplelineInfoById(tmpIngestionData.appPipelineId); } setAppIngestionData(tmpIngestionData); } catch (error) { console.error(error); } }; useEffect(() => { getAppLogIngestionById(); }, []); return (
{loadingData ? ( ) : (
{appPipelineData?.aosParams?.indexPrefix}
{appIngestionData?.accountId && ( )}
<> {appPipelineData?.bufferType === BufferType.KDS && (
{appPipelineData?.bufferResourceName || "-"} {getParamValueByKey( "enableAutoScaling", appPipelineData.bufferParams ) === "true" ? t("applog:detail.autoScaling") : ""}
)} {appPipelineData?.bufferType === BufferType.S3 && (
{appPipelineData?.bufferResourceName || "-"}
)} {appPipelineData?.bufferType === BufferType.None && (
{t("none")}
)}
{appIngestionData?.sourceType === LogSourceType.S3 && appIngestionData?.logPath ? ( {appIngestionData?.logPath} ) : ( "" )} {appIngestionData?.sourceType === LogSourceType.EC2 && appIngestionData?.sourceId ? ( {appIngestionData?.sourceId} ) : ( "" )} {appIngestionData?.sourceType === LogSourceType.Syslog && ( {getSourceInfoValueByKey( "syslogNlbDNSName", sourceInfo?.sourceInfo ) || ""} )}
{appIngestionData?.sourceType === LogSourceType.Syslog && ( <>
{getSourceInfoValueByKey( "syslogProtocol", sourceInfo?.sourceInfo )}
)}
{appIngestionData?.sourceType === LogSourceType.Syslog && ( <>
{getSourceInfoValueByKey( "syslogPort", sourceInfo?.sourceInfo )}
)}
{formatLocalTime(appIngestionData?.createdDt || "")}
{ changeTab(event, newTab); }} > {appIngestionData?.sourceType === LogSourceType.Syslog && ( )} {appIngestionData?.sourceType === LogSourceType.Syslog && ( )}
)}
); }; export default AppIngestionDetail;