From 171be275aebce12473ae653084fa39df03be46d7 Mon Sep 17 00:00:00 2001 From: Julio Zynger Date: Tue, 1 Mar 2022 10:28:53 +0100 Subject: [PATCH] Rename locations -> instances Signed-off-by: Julio Zynger --- plugins/periskop-backend/src/api/index.ts | 23 +++++++------ .../src/service/router.test.ts | 2 +- plugins/periskop-backend/src/types.ts | 2 +- plugins/periskop/README.md | 11 +++--- plugins/periskop/config.d.ts | 2 +- plugins/periskop/src/api/index.ts | 29 ++++++++-------- .../PeriskopErrorsTable.tsx | 34 +++++++++---------- plugins/periskop/src/types.ts | 2 +- 8 files changed, 54 insertions(+), 51 deletions(-) diff --git a/plugins/periskop-backend/src/api/index.ts b/plugins/periskop-backend/src/api/index.ts index f2b15f58fb..ff0f1e8b5d 100644 --- a/plugins/periskop-backend/src/api/index.ts +++ b/plugins/periskop-backend/src/api/index.ts @@ -15,24 +15,24 @@ */ import { Config } from '@backstage/config'; -import { AggregatedError, NotFoundInLocation } from '../types'; +import { AggregatedError, NotFoundInInstance } from '../types'; import fetch from 'node-fetch'; export type Options = { config: Config; }; -type PeriskopLocation = { +type PeriskopInstance = { name: string; host: string; }; export class PeriskopApi { - private readonly locations: PeriskopLocation[]; + private readonly instances: PeriskopInstance[]; constructor(options: Options) { - this.locations = options.config - .getConfigArray('periskop.locations') + this.instances = options.config + .getConfigArray('periskop.instances') .flatMap(locConf => { const name = locConf.getString('name'); const host = locConf.getString('host'); @@ -40,18 +40,19 @@ export class PeriskopApi { }); } - private getApiUrl(locationName: string): string | undefined { - return this.locations.find(loc => loc.name === locationName)?.host; + private getApiUrl(instanceName: string): string | undefined { + return this.instances.find(instance => instance.name === instanceName) + ?.host; } async getErrors( - locationName: string, + instanceName: string, serviceName: string, - ): Promise { - const apiUrl = this.getApiUrl(locationName); + ): Promise { + const apiUrl = this.getApiUrl(instanceName); if (!apiUrl) { throw new Error( - `failed to fetch data, no periskop location with name ${locationName}`, + `failed to fetch data, no periskop instance with name ${instanceName}`, ); } const response = await fetch(`${apiUrl}/services/${serviceName}/errors/`); diff --git a/plugins/periskop-backend/src/service/router.test.ts b/plugins/periskop-backend/src/service/router.test.ts index efc326280a..f071ab901f 100644 --- a/plugins/periskop-backend/src/service/router.test.ts +++ b/plugins/periskop-backend/src/service/router.test.ts @@ -29,7 +29,7 @@ describe('createRouter', () => { logger: getVoidLogger(), config: new ConfigReader({ periskop: { - locations: [ + instances: [ { name: 'db', host: 'http://periskop-db', diff --git a/plugins/periskop-backend/src/types.ts b/plugins/periskop-backend/src/types.ts index e6ee09f97c..084ba52620 100644 --- a/plugins/periskop-backend/src/types.ts +++ b/plugins/periskop-backend/src/types.ts @@ -43,6 +43,6 @@ export interface RequestHeaders { [k: string]: string; } -export interface NotFoundInLocation { +export interface NotFoundInInstance { body: string; } diff --git a/plugins/periskop/README.md b/plugins/periskop/README.md index e937ee17ad..ad71529b70 100644 --- a/plugins/periskop/README.md +++ b/plugins/periskop/README.md @@ -20,15 +20,16 @@ annotations: periskop.io/name: '' ``` -### Locations +### Instances -The periskop plugin can be configured to fetch aggregated errors from multiple deployment locations. This is especially useful if you have a multi-zone deployment, or a federated setup and would like to drill deeper into a single instance of the federation. Each of the configured locations will be included in the plugin's UI via a dropdown on the errors table. +The periskop plugin can be configured to fetch aggregated errors from multiple deployment instances. +This is especially useful if you have a multi-zone deployment, or a federated setup and would like to drill deeper into a single instance of the federation. Each of the configured instances will be included in the plugin's UI via a dropdown on the errors table. The plugin requires to configure _at least one_ Periskop API location in the [app-config.yaml](https://github.com/backstage/backstage/blob/master/app-config.yaml): ```yaml periskop: - locations: - - name: - host: + instances: + - name: + host: ``` diff --git a/plugins/periskop/config.d.ts b/plugins/periskop/config.d.ts index 81e831c54f..31ab363a15 100644 --- a/plugins/periskop/config.d.ts +++ b/plugins/periskop/config.d.ts @@ -23,7 +23,7 @@ export interface Config { * Integration configuration for the periskop servers * @visibility frontend */ - locations: Array<{ + instances: Array<{ /** * The name of the given Periskop instance * @visibility frontend diff --git a/plugins/periskop/src/api/index.ts b/plugins/periskop/src/api/index.ts index 8683d636e4..c35de9bcd3 100644 --- a/plugins/periskop/src/api/index.ts +++ b/plugins/periskop/src/api/index.ts @@ -15,14 +15,14 @@ */ import { ConfigApi, DiscoveryApi } from '@backstage/core-plugin-api'; -import { AggregatedError, NotFoundInLocation } from '../types'; +import { AggregatedError, NotFoundInInstance } from '../types'; type Options = { discoveryApi: DiscoveryApi; configApi: ConfigApi; }; -type PeriskopLocation = { +type PeriskopInstance = { name: string; host: string; }; @@ -34,12 +34,12 @@ type PeriskopLocation = { */ export class PeriskopApi { private readonly discoveryApi: DiscoveryApi; - private readonly locations: PeriskopLocation[]; + private readonly instances: PeriskopInstance[]; constructor(options: Options) { this.discoveryApi = options.discoveryApi; - this.locations = options.configApi - .getConfigArray('periskop.locations') + this.instances = options.configApi + .getConfigArray('periskop.instances') .flatMap(locConf => { const name = locConf.getString('name'); const host = locConf.getString('host'); @@ -47,31 +47,32 @@ export class PeriskopApi { }); } - private getApiUrl(locationName: string): string | undefined { - return this.locations.find(loc => loc.name === locationName)?.host; + private getApiUrl(instanceName: string): string | undefined { + return this.instances.find(instance => instance.name === instanceName) + ?.host; } - getLocationNames(): string[] { - return this.locations.map(e => e.name); + getInstanceNames(): string[] { + return this.instances.map(e => e.name); } getErrorInstanceUrl( - locationName: string, + instanceName: string, serviceName: string, error: AggregatedError, ): string { return `${this.getApiUrl( - locationName, + instanceName, )}/#/${serviceName}/errors/${encodeURIComponent(error.aggregation_key)}`; } async getErrors( - locationName: string, + instanceName: string, serviceName: string, - ): Promise { + ): Promise { const apiUrl = `${await this.discoveryApi.getBaseUrl( 'periskop', - )}/${locationName}/${serviceName}`; + )}/${instanceName}/${serviceName}`; const response = await fetch(apiUrl); if (!response.ok) { diff --git a/plugins/periskop/src/components/PeriskopErrorsTable/PeriskopErrorsTable.tsx b/plugins/periskop/src/components/PeriskopErrorsTable/PeriskopErrorsTable.tsx index adb831bb65..54f97b0700 100644 --- a/plugins/periskop/src/components/PeriskopErrorsTable/PeriskopErrorsTable.tsx +++ b/plugins/periskop/src/components/PeriskopErrorsTable/PeriskopErrorsTable.tsx @@ -35,7 +35,7 @@ import { import Alert from '@material-ui/lab/Alert'; import useAsync from 'react-use/lib/useAsync'; import { periskopApiRef } from '../..'; -import { AggregatedError, NotFoundInLocation } from '../../types'; +import { AggregatedError, NotFoundInInstance } from '../../types'; /** * Constant storing Periskop project name. @@ -72,10 +72,10 @@ const renderLastOccurrence = (error: AggregatedError): React.ReactNode => { return moment(new Date(error.latest_errors[0].timestamp * 1000)).fromNow(); }; -function isNotFoundInLocation( - apiResult: AggregatedError[] | NotFoundInLocation | undefined, -): apiResult is NotFoundInLocation { - return (apiResult as NotFoundInLocation)?.body !== undefined; +function isNotFoundInInstance( + apiResult: AggregatedError[] | NotFoundInInstance | undefined, +): apiResult is NotFoundInInstance { + return (apiResult as NotFoundInInstance)?.body !== undefined; } export const PeriskopErrorsTable = () => { @@ -86,17 +86,17 @@ export const PeriskopErrorsTable = () => { | undefined) ?? entity.metadata.name; const periskopApi = useApi(periskopApiRef); - const locations = periskopApi.getLocationNames(); - const [locationOption, setLocationOption] = React.useState( - locations[0], + const instanceNames = periskopApi.getInstanceNames(); + const [instanceOption, setInstanceOption] = React.useState( + instanceNames[0], ); const { value: aggregatedErrors, loading, error, - } = useAsync(async (): Promise => { - return periskopApi.getErrors(locationOption, entityPeriskopName); - }, [locationOption]); + } = useAsync(async (): Promise => { + return periskopApi.getErrors(instanceOption, entityPeriskopName); + }, [instanceOption]); if (loading) { return ; @@ -112,7 +112,7 @@ export const PeriskopErrorsTable = () => { sorting: false, render: aggregatedError => { const errorUrl = periskopApi.getErrorInstanceUrl( - locationOption, + instanceOption, entityPeriskopName, aggregatedError, ); @@ -138,13 +138,13 @@ export const PeriskopErrorsTable = () => { const sortingSelect = (