Rename locations -> instances

Signed-off-by: Julio Zynger <julio.zynger@soundcloud.com>
This commit is contained in:
Julio Zynger
2022-03-01 10:28:53 +01:00
committed by Fredrik Adelöw
parent f6e22fb230
commit 171be275ae
8 changed files with 54 additions and 51 deletions
+12 -11
View File
@@ -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<AggregatedError[] | NotFoundInLocation> {
const apiUrl = this.getApiUrl(locationName);
): Promise<AggregatedError[] | NotFoundInInstance> {
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/`);
@@ -29,7 +29,7 @@ describe('createRouter', () => {
logger: getVoidLogger(),
config: new ConfigReader({
periskop: {
locations: [
instances: [
{
name: 'db',
host: 'http://periskop-db',
+1 -1
View File
@@ -43,6 +43,6 @@ export interface RequestHeaders {
[k: string]: string;
}
export interface NotFoundInLocation {
export interface NotFoundInInstance {
body: string;
}