/* 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 { RouteComponentProps } from "react-router-dom"; import Breadcrumb from "components/Breadcrumb"; import LoadingText from "components/LoadingText"; import HeaderPanel from "components/HeaderPanel"; import ValueWithLabel from "components/ValueWithLabel"; import ExtLink from "components/ExtLink"; import { AntTabs, AntTab, TabPanel } from "components/Tab"; import Overview from "./detail/Overview"; import Lifecycle from "./detail/Lifecycle"; import Tags from "./detail/Tags"; import { appSyncRequestQuery } from "assets/js/request"; import { getServicePipeline } from "graphql/queries"; import { DestinationType, Parameter, ServicePipeline, ServiceType, Tag, } from "API"; import { buildCloudFrontLink, buildConfigLink, buildELBLink, buildESLink, buildLambdaLink, buildRDSLink, buildS3Link, buildTrailLink, buildVPCLink, buildWAFLink, formatLocalTime, } from "assets/js/utils"; import { AmplifyConfigType, CWLSourceType } from "types"; import { useSelector } from "react-redux"; import { AppStateProps } from "reducer/appReducer"; import { ServiceTypeMap, ServiceTypeMapMidSuffix } from "assets/js/const"; import HelpPanel from "components/HelpPanel"; import SideMenu from "components/SideMenu"; import { useTranslation } from "react-i18next"; import AccountName from "pages/comps/account/AccountName"; interface MatchParams { id: string; } export interface ServiceLogDetailProps { type: string; // bucketName: string; source: string; esName: string; esIndex: string; logLocation: string; createSampleData: string; createTime: string; warmAge: number | string; coldAge: number | string; retainAge: number | string; warnRetention: number | string; coldRetention: number | string; logRetention: number | string; shardNumbers: number | string; replicaNumbers: number | string; logSourceAccountId: string; destinationType: string; samplingRate: string; minCapacity: string; maxCapacity: string; enableAutoScaling: string; rolloverSize: string; indexSuffix: string; codec: string; fieldNames: string; tags: (Tag | null)[] | null | undefined; } const ServiceLogDetail: React.FC> = ( props: RouteComponentProps ) => { const id: string = props.match.params.id; const { t } = useTranslation(); const breadCrumbList = [ { name: t("name"), link: "/" }, { name: t("servicelog:name"), link: "/log-pipeline/service-log", }, { name: id, }, ]; const amplifyConfig: AmplifyConfigType = useSelector( (state: AppStateProps) => state.amplifyConfig ); const [loadingData, setLoadingData] = useState(true); const [curPipeline, setCurPipeline] = useState< ServiceLogDetailProps | undefined >(); const [activeTab, setActiveTab] = useState(0); const changeTab = (event: any, newTab: number) => { console.info("newTab:", newTab); setActiveTab(newTab); }; const getParamValueByKey = ( dataList: (Parameter | null)[] | null | undefined, key: string ) => { if (dataList) { return ( dataList.find((element) => element?.parameterKey === key) ?.parameterValue || "" ); } return "-"; }; const getPipelineById = async () => { try { setLoadingData(true); const resData: any = await appSyncRequestQuery(getServicePipeline, { id: id, }); const dataPipelne: ServicePipeline = resData.data.getServicePipeline; let tmpLogLocation = ""; if ( dataPipelne.type === ServiceType.S3 || dataPipelne.type === ServiceType.CloudTrail || dataPipelne.type === ServiceType.CloudFront || dataPipelne.type === ServiceType.ELB || dataPipelne.type === ServiceType.WAF || dataPipelne.type === ServiceType.VPC || dataPipelne.type === ServiceType.Config ) { tmpLogLocation = `s3://${getParamValueByKey( dataPipelne.parameters, "logBucketName" )}/${getParamValueByKey(dataPipelne.parameters, "logBucketPrefix")}`; } if ( dataPipelne.type === ServiceType.Lambda || dataPipelne.type === ServiceType.RDS ) { tmpLogLocation = `${getParamValueByKey( dataPipelne.parameters, "logGroupNames" )}`; } if (dataPipelne.destinationType === DestinationType.CloudWatch) { tmpLogLocation = `${getParamValueByKey( dataPipelne.parameters, "logSource" )}`; } setCurPipeline({ type: dataPipelne.type, source: dataPipelne.source || "", esName: getParamValueByKey(dataPipelne.parameters, "domainName"), esIndex: getParamValueByKey(dataPipelne.parameters, "indexPrefix"), logLocation: tmpLogLocation, createSampleData: getParamValueByKey( dataPipelne.parameters, "createDashboard" ), createTime: formatLocalTime(dataPipelne?.createdDt || ""), warnRetention: getParamValueByKey(dataPipelne.parameters, "daysToWarm"), coldRetention: getParamValueByKey(dataPipelne.parameters, "daysToCold"), logRetention: getParamValueByKey( dataPipelne.parameters, "daysToRetain" ), warmAge: getParamValueByKey(dataPipelne.parameters, "warmAge"), coldAge: getParamValueByKey(dataPipelne.parameters, "coldAge"), retainAge: getParamValueByKey(dataPipelne.parameters, "retainAge"), shardNumbers: getParamValueByKey( dataPipelne.parameters, "shardNumbers" ), replicaNumbers: getParamValueByKey( dataPipelne.parameters, "replicaNumbers" ), logSourceAccountId: getParamValueByKey( dataPipelne.parameters, "logSourceAccountId" ), destinationType: dataPipelne.destinationType || "", samplingRate: getParamValueByKey( dataPipelne.parameters, "samplingRate" ), minCapacity: getParamValueByKey(dataPipelne.parameters, "minCapacity"), maxCapacity: getParamValueByKey(dataPipelne.parameters, "maxCapacity"), enableAutoScaling: getParamValueByKey( dataPipelne.parameters, "enableAutoScaling" ), rolloverSize: getParamValueByKey( dataPipelne.parameters, "rolloverSize" ), indexSuffix: getParamValueByKey(dataPipelne.parameters, "indexSuffix"), codec: getParamValueByKey(dataPipelne.parameters, "codec"), fieldNames: getParamValueByKey(dataPipelne.parameters, "fieldNames"), tags: dataPipelne.tags, }); setLoadingData(false); } catch (error) { setLoadingData(false); console.error(error); } }; useEffect(() => { getPipelineById(); }, []); return (
{loadingData ? ( ) : (
<>
{ServiceTypeMap[curPipeline?.type || ""]}
{curPipeline?.logSourceAccountId && ( )} {curPipeline?.type === ServiceType.CloudFront && ( <> {curPipeline?.destinationType === DestinationType.KDS ? t("servicelog:cloudfront.realtimeLogs") : t("servicelog:cloudfront.standardLogs")} {curPipeline.destinationType === DestinationType.KDS && ( {curPipeline?.samplingRate ? curPipeline?.samplingRate + "%" : "-"} )} )} {curPipeline?.type === ServiceType.CloudTrail && ( <> {curPipeline?.destinationType === DestinationType.CloudWatch ? CWLSourceType.CWL : CWLSourceType.S3} )}
{curPipeline?.type === ServiceType.Lambda && ( {curPipeline?.source} )} {curPipeline?.type === ServiceType.S3 && ( {curPipeline?.source} )} {curPipeline?.type === ServiceType.CloudFront && ( <> {curPipeline?.source} {curPipeline.destinationType === DestinationType.KDS && ( <> {curPipeline?.minCapacity ? curPipeline?.minCapacity : "-"} {curPipeline?.enableAutoScaling ? curPipeline?.enableAutoScaling : "-"} {curPipeline?.maxCapacity ? curPipeline?.maxCapacity : "-"} )} )} {curPipeline?.type === ServiceType.ELB && ( {curPipeline?.source} )} {(curPipeline?.type === ServiceType.WAF || curPipeline?.type === ServiceType.WAFSampled) && ( {curPipeline?.source} )} {curPipeline?.type === ServiceType.VPC && ( {curPipeline?.source} )} {curPipeline?.type === ServiceType.CloudTrail && ( {curPipeline?.source} )} {curPipeline?.type === ServiceType.Config && ( {curPipeline?.source} )} {curPipeline?.type === ServiceType.RDS && ( {curPipeline?.source} )}
{curPipeline?.esName} {curPipeline?.rolloverSize && ( {curPipeline?.rolloverSize?.toUpperCase()} )} {curPipeline?.codec && ( {curPipeline?.codec} )}
{`${curPipeline?.esIndex}${ ServiceTypeMapMidSuffix[curPipeline?.type || ""] }`}
{curPipeline?.indexSuffix && ( {curPipeline?.indexSuffix} )}
{curPipeline?.type === ServiceType.CloudFront && curPipeline.destinationType === DestinationType.KDS && (
{curPipeline?.fieldNames}
)}
{ changeTab(event, newTab); }} >
)}
); }; export default ServiceLogDetail;