feat(dynatrace): add view recent synthetic monitor activity

Signed-off-by: Isaiah Thiessen <isaiah.thiessen@telus.com>
This commit is contained in:
Isaiah Thiessen
2022-06-23 12:46:27 -07:00
parent 3e9b0cbcd9
commit 4e34828773
10 changed files with 200 additions and 12 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ title: Dynatrace
author: TELUS
authorUrl: https://github.com/telus
category: Monitoring
description: View monitoring info from dynatrace for services in your software catalog.
description: View monitoring info from Dynatrace for services in your software catalog.
documentation: https://github.com/backstage/backstage/tree/master/plugins/dynatrace
iconUrl: img/dynatrace.svg
npmPackageName: '@backstage/plugin-dynatrace'
+20
View File
@@ -35,8 +35,25 @@ export type DynatraceProblem = {
affectedEntities: Array<DynatraceEntity>;
};
type SyntheticRequestResults = {
startTimestamp: number;
};
export type DynatraceSyntheticResults = {
monitorId: string;
locationsExecutionResults: [
{
locationId: number;
executionId: string;
requestResults: Array<SyntheticRequestResults>;
},
];
};
export interface DynatraceProblems {
problems: Array<DynatraceProblem>;
totalCount: number;
pageSize: number;
}
export const dynatraceApiRef = createApiRef<DynatraceApi>({
@@ -47,4 +64,7 @@ export type DynatraceApi = {
getDynatraceProblems(
dynatraceEntityId: string,
): Promise<DynatraceProblems | undefined>;
getDynatraceSyntheticFailures(
syntheticId: string,
): Promise<DynatraceSyntheticResults | undefined>;
};
+16 -2
View File
@@ -13,7 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DynatraceProblems, DynatraceApi } from './DynatraceApi';
import {
DynatraceProblems,
DynatraceApi,
DynatraceSyntheticResults,
} from './DynatraceApi';
import { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';
export class DynatraceClient implements DynatraceApi {
@@ -52,11 +56,21 @@ export class DynatraceClient implements DynatraceApi {
);
}
async getDynatraceSyntheticFailures(
syntheticId: string,
): Promise<DynatraceSyntheticResults | undefined> {
if (!syntheticId) {
throw new Error('Dynatrace synthetic Id is required');
}
return this.callApi(`synthetic/execution/${syntheticId}/FAILED`, {});
}
async getDynatraceProblems(
dynatraceEntityId: string,
): Promise<DynatraceProblems | undefined> {
if (!dynatraceEntityId) {
throw new Error('Dynatrace entity ID is required');
throw new Error('Dynatrace entity Id is required');
}
return this.callApi('problems', {
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="282" height="173" fill="none" viewBox="0 0 282 173"><path fill="#000" fill-opacity=".05" fill-rule="evenodd" d="M16.4571 45.1637C11.0514 46.1711 7.48574 51.3699 8.49306 56.7756C9.50039 62.1814 14.6992 65.747 20.105 64.7397L27.5528 63.3518C25.4791 65.5835 24.4525 68.7347 25.0535 71.9596C26.0608 77.3653 31.2596 80.931 36.6654 79.9236L89.691 70.0427C89.7016 70.1067 89.7129 70.1708 89.7249 70.2349C90.3258 73.4598 92.4185 76.0298 95.1569 77.3647L91.9031 77.971C86.4974 78.9784 82.9318 84.1772 83.9391 89.583C84.9464 94.9887 90.1452 98.5543 95.551 97.547L250.098 68.7482C255.504 67.7409 259.069 62.5421 258.062 57.1363C257.461 53.9114 255.368 51.3414 252.63 50.0065L257.835 49.0366C263.241 48.0292 266.807 42.8304 265.799 37.4247C264.792 32.0189 259.593 28.4533 254.187 29.4606L161.492 46.7338C161.481 46.6697 161.47 46.6056 161.458 46.5415C160.857 43.3166 158.764 40.7466 156.026 39.4117L165.025 37.7347C170.431 36.7274 173.997 31.5286 172.989 26.1228C171.982 20.7171 166.783 17.1514 161.378 18.1588L16.4571 45.1637ZM24.3031 122.54C23.2958 117.134 26.8614 111.936 32.2672 110.928L190.856 81.3762C196.262 80.3688 201.461 83.9345 202.468 89.3402C203.476 94.746 199.91 99.9448 194.504 100.952L189.963 101.798C190.493 102.057 190.999 102.362 191.474 102.708L246.43 92.4677C251.835 91.4604 257.034 95.026 258.041 100.432C258.642 103.657 257.616 106.808 255.542 109.04L256.649 108.833C262.055 107.826 267.253 111.392 268.261 116.797C269.268 122.203 265.702 127.402 260.297 128.409L95.5591 159.107C90.1534 160.114 84.9545 156.549 83.9472 151.143C82.9399 145.737 86.5055 140.538 91.9113 139.531L103.94 137.29C103.41 137.031 102.904 136.726 102.429 136.38L29.1002 150.044C23.6944 151.051 18.4956 147.486 17.4882 142.08C16.4809 136.674 20.0465 131.475 25.4523 130.468L29.7352 129.67C26.9967 128.335 24.904 125.765 24.3031 122.54Z" clip-rule="evenodd"/><circle cx="188" cy="55" r="6" fill="#69DDC7"/><circle cx="91" cy="92" r="6" fill="#69DDC7"/><path fill="#69DDC7" d="M121 114L95.5 88L86.5 96L121 130L192.5 59L183.5 51L121 114Z"/></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

@@ -18,18 +18,24 @@ import { Grid } from '@material-ui/core';
import {
Page,
Content,
ContentHeader,
SupportButton,
MissingAnnotationEmptyState,
} from '@backstage/core-components';
import { useEntity } from '@backstage/plugin-catalog-react';
import { useApi, configApiRef } from '@backstage/core-plugin-api';
import { ProblemsList } from '../Problems/ProblemsList';
import { SyntheticsCard } from '../Synthetics/SyntheticsCard';
import { isDynatraceAvailable } from '../../plugin';
import { DYNATRACE_ID_ANNOTATION } from '../../constants';
import {
DYNATRACE_ID_ANNOTATION,
DYNATRACE_SYNTHETICS_ANNOTATION,
} from '../../constants';
export const DynatraceTab = () => {
const { entity } = useEntity();
const configApi = useApi(configApiRef);
const dynatraceBaseUrl = configApi.getString('dynatrace.baseUrl');
if (!isDynatraceAvailable(entity)) {
return <MissingAnnotationEmptyState annotation={DYNATRACE_ID_ANNOTATION} />;
}
@@ -37,18 +43,29 @@ export const DynatraceTab = () => {
const dynatraceEntityId: string =
entity?.metadata.annotations?.[DYNATRACE_ID_ANNOTATION]!;
const syntheticsIds: string =
entity?.metadata.annotations?.[DYNATRACE_SYNTHETICS_ANNOTATION]!;
return (
<Page themeId="tool">
<Content>
<ContentHeader title="Dynatrace">
<SupportButton>
Plugin to show information from Dynatrace
</SupportButton>
</ContentHeader>
<Grid container spacing={2}>
<Grid item xs={12} lg={12}>
<ProblemsList dynatraceEntityId={dynatraceEntityId} />
<ProblemsList
dynatraceEntityId={dynatraceEntityId}
dynatraceBaseUrl={dynatraceBaseUrl}
/>
</Grid>
{syntheticsIds ? (
<Grid item xs={12} lg={12}>
<SyntheticsCard
syntheticsIds={syntheticsIds}
dynatraceBaseUrl={dynatraceBaseUrl}
/>
</Grid>
) : (
<></>
)}
</Grid>
</Content>
</Page>
@@ -0,0 +1,15 @@
/*
* Copyright 2022 The Backstage Authors
*
* 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.
*/
@@ -0,0 +1,18 @@
/*
* Copyright 2022 The Backstage Authors
*
* 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 from 'react';
describe('SyntheticsCard', () => {});
@@ -0,0 +1,85 @@
/*
* Copyright 2022 The Backstage Authors
*
* 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 from 'react';
import useAsync from 'react-use/lib/useAsync';
import { Progress } from '@backstage/core-components';
import Alert from '@material-ui/lab/Alert';
import { InfoCard } from '@backstage/core-components';
import { useApi } from '@backstage/core-plugin-api';
import { Typography } from '@material-ui/core';
import { dynatraceApiRef } from '../../../api';
type SyntheticsCardProps = {
syntheticsIds: string;
dynatraceBaseUrl: string;
};
const dynatraceMonitorPrefixes = (idPrefix: string): string => {
switch (idPrefix) {
case 'HTTP_CHECK':
return 'ui/http-monitor';
case 'BROWSER_MONITOR':
return 'ui/browser-monitor';
case 'SYNTHETIC_TEST':
return 'ui/browser-monitor';
default:
throw new Error('Invalid synthetic Id');
}
};
export const SyntheticsCard = (props: SyntheticsCardProps) => {
const { syntheticsIds, dynatraceBaseUrl } = props;
const dynatraceApi = useApi(dynatraceApiRef);
const { value, loading, error } = useAsync(async () => {
return dynatraceApi.getDynatraceSyntheticFailures(syntheticsIds);
}, [dynatraceApi, syntheticsIds]);
if (loading) {
return <Progress />;
} else if (error) {
return <Alert severity="error">{error.message}</Alert>;
}
const deepLinkPrefix = dynatraceMonitorPrefixes(
`${syntheticsIds.match(/(.+)-/)![1]}`,
);
const timestamps = value?.locationsExecutionResults.map(l => {
return l.requestResults[0].startTimestamp;
});
return (
<InfoCard
title="Synthetics"
subheader="Recent Activity"
deepLink={{
title: 'View Synthetics in Dynatrace',
link: `${dynatraceBaseUrl}/${deepLinkPrefix}/${syntheticsIds}`,
}}
>
<Typography>
Locations: {JSON.stringify(value?.locationsExecutionResults.length)}
</Typography>
<Typography>
Last Failures:{' '}
{JSON.stringify(
timestamps?.map(t => {
return new Date(t).toString();
}),
)}
</Typography>
</InfoCard>
);
};
@@ -0,0 +1,16 @@
/*
* Copyright 2022 The Backstage Authors
*
* 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.
*/
export { SyntheticsCard } from './SyntheticsCard';
+2
View File
@@ -14,3 +14,5 @@
* limitations under the License.
*/
export const DYNATRACE_ID_ANNOTATION = 'dynatrace.com/dynatrace-entity-id';
export const DYNATRACE_SYNTHETICS_ANNOTATION =
'dynatrace.com/dynatrace-synthetics-ids';