add client template

Signed-off-by: Ryan Vazquez <ryanv@spotify.com>
This commit is contained in:
Ryan Vazquez
2021-05-11 10:56:55 -04:00
committed by Fredrik Adelöw
parent 937e88769d
commit 5914a76d5e
3 changed files with 110 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-cost-insights': patch
---
Added example client
+4 -4
View File
@@ -25,9 +25,7 @@ yarn add @backstage/plugin-cost-insights
1. Configure `app-config.yaml`. See [Configuration](#configuration).
2. Create a CostInsights client. Clients must implement the CostInsightsApi interface. See the [API file](https://github.com/backstage/backstage/blob/master/plugins/cost-insights/src/api/CostInsightsApi.ts) for required methods and documentation.
**Note:** We've briefly explored using the AWS Cost Explorer API to implement a CostInsights client. Learn more about our findings [here](https://github.com/backstage/backstage/blob/master/plugins/cost-insights/contrib/aws-cost-explorer-api.md).
2. Create a CostInsights client. Clients must implement the [CostInsightsApi](https://github.com/backstage/backstage/blob/master/plugins/cost-insights/src/api/CostInsightsApi.ts) interface. Create your own or [use a template](https://github.com/backstage/backstage/blob/master/plugins/cost-insights/src/example/templates/CostInsightsClient.ts) to get started.
```ts
// path/to/CostInsightsClient.ts
@@ -36,7 +34,9 @@ import { CostInsightsApi } from '@backstage/plugin-cost-insights';
export class CostInsightsClient implements CostInsightsApi { ... }
```
3. Import the client and the CostInsights plugin API to your Backstage instance.
**Note:** We've briefly explored using the AWS Cost Explorer API to implement a Cost Insights client. Learn more about our findings [here](https://github.com/backstage/backstage/blob/master/plugins/cost-insights/contrib/aws-cost-explorer-api.md).
3. Import the client and the Cost Insights plugin API to your Backstage instance.
```ts
// packages/app/src/api.ts
@@ -0,0 +1,101 @@
/*
* Copyright 2020 Spotify AB
*
* 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.
*/
/*
This is a copy-pastable client template to get up and running quickly.
API Reference:
https://github.com/backstage/backstage/blob/master/plugins/cost-insights/src/api/CostInsightsApi.ts
*/
// IMPORTANT: Remove the lines below to enable type checking and linting
// @ts-nocheck
/* eslint-disable import/no-extraneous-dependencies */
import {
CostInsightsApi,
ProductInsightsOptions,
Alert,
Cost,
Entity,
Group,
MetricData,
Project,
} from '@backstage/plugin-cost-insights';
export class CostInsightsClient implements CostInsightsApi {
async getLastCompleteBillingDate(): Promise<string> {
return '2021-01-01'; // YYYY-MM-DD
}
async getUserGroups(userId: string): Promise<Group[]> {
return [];
}
async getGroupProjects(group: string): Promise<Project[]> {
return [];
}
async getAlerts(group: string): Promise<Alert[]> {
return [];
}
async getDailyMetricData(metric: string, intervals: string): Promise<MetricData> {
return {
id: 'remove-me',
format: 'number',
aggregation: [],
change: {
ratio: 0,
amount: 0
}
}
}
async getGroupDailyCost(group: string, intervals: string): Promise<Cost> {
return {
id: 'remove-me',
aggregation: [],
change: {
ratio: 0,
amount: 0
}
}
}
async getProjectDailyCost(project: string, intervals: string): Promise<Cost> {
return {
id: 'remove-me',
aggregation: [],
change: {
ratio: 0,
amount: 0
}
}
}
async getProductInsights(options: ProductInsightsOptions): Promise<Entity> {
return {
id: 'remove-me',
aggregation: [0, 0],
change: {
ratio: 0,
amount: 0
},
entities: {}
}
}
}