From 5914a76d5e3bb9b3be152e8991148407824a2043 Mon Sep 17 00:00:00 2001 From: Ryan Vazquez Date: Tue, 11 May 2021 10:56:55 -0400 Subject: [PATCH] add client template Signed-off-by: Ryan Vazquez --- .changeset/short-schools-pay.md | 5 + plugins/cost-insights/README.md | 8 +- .../example/templates/CostInsightsClient.ts | 101 ++++++++++++++++++ 3 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 .changeset/short-schools-pay.md create mode 100644 plugins/cost-insights/src/example/templates/CostInsightsClient.ts diff --git a/.changeset/short-schools-pay.md b/.changeset/short-schools-pay.md new file mode 100644 index 0000000000..8466d31c3c --- /dev/null +++ b/.changeset/short-schools-pay.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-cost-insights': patch +--- + +Added example client diff --git a/plugins/cost-insights/README.md b/plugins/cost-insights/README.md index 3fee89e77a..2311937890 100644 --- a/plugins/cost-insights/README.md +++ b/plugins/cost-insights/README.md @@ -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 diff --git a/plugins/cost-insights/src/example/templates/CostInsightsClient.ts b/plugins/cost-insights/src/example/templates/CostInsightsClient.ts new file mode 100644 index 0000000000..f7e4686961 --- /dev/null +++ b/plugins/cost-insights/src/example/templates/CostInsightsClient.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 { + return '2021-01-01'; // YYYY-MM-DD + } + + async getUserGroups(userId: string): Promise { + return []; + } + + async getGroupProjects(group: string): Promise { + return []; + } + + async getAlerts(group: string): Promise { + return []; + } + + async getDailyMetricData(metric: string, intervals: string): Promise { + return { + id: 'remove-me', + format: 'number', + aggregation: [], + change: { + ratio: 0, + amount: 0 + } + } + } + + async getGroupDailyCost(group: string, intervals: string): Promise { + return { + id: 'remove-me', + aggregation: [], + change: { + ratio: 0, + amount: 0 + } + } + } + + async getProjectDailyCost(project: string, intervals: string): Promise { + return { + id: 'remove-me', + aggregation: [], + change: { + ratio: 0, + amount: 0 + } + } + } + + async getProductInsights(options: ProductInsightsOptions): Promise { + return { + id: 'remove-me', + aggregation: [0, 0], + change: { + ratio: 0, + amount: 0 + }, + entities: {} + } + } +}