Add project field to product cost api calls

This commit is contained in:
Brenda Sukh
2020-10-07 14:52:26 -04:00
parent 55602200a3
commit 0181b365e4
2 changed files with 46 additions and 3 deletions
@@ -23,6 +23,7 @@ import {
Project,
ProductCost,
Group,
Maybe,
} from '@backstage/plugin-cost-insights';
export class ExampleCostInsightsClient implements CostInsightsApi {
@@ -122,9 +123,38 @@ export class ExampleCostInsightsClient implements CostInsightsApi {
product: string,
group: string,
duration: Duration,
project: Maybe<string>,
): Promise<ProductCost> {
const projectProductInsights = await this.request(
{ product, group, duration, project },
{
aggregation: [80_000, 110_000],
change: {
ratio: 0.375,
amount: 30_000,
},
entities: [
{
id: null, // entities with null ids will be appear as "Unlabeled" in product panels
aggregation: [45_000, 50_000],
},
{
id: 'entity-a',
aggregation: [15_000, 20_000],
},
{
id: 'entity-b',
aggregation: [20_000, 30_000],
},
{
id: 'entity-e',
aggregation: [0, 10_000],
},
],
},
);
const productInsights: ProductCost = await this.request(
{ product, group, duration },
{ product, group, duration, project },
{
aggregation: [200_000, 250_000],
change: {
@@ -172,7 +202,7 @@ export class ExampleCostInsightsClient implements CostInsightsApi {
},
);
return productInsights;
return project ? projectProductInsights : productInsights;
}
async getAlerts(group: string): Promise<Alert[]> {
@@ -15,7 +15,15 @@
*/
import { createApiRef } from '@backstage/core';
import { Alert, Cost, Duration, Group, Project, ProductCost } from '../types';
import {
Alert,
Cost,
Duration,
Group,
Project,
ProductCost,
Maybe,
} from '../types';
export type CostInsightsApi = {
/**
@@ -87,6 +95,9 @@ export type CostInsightsApi = {
* in this product. The type of entity depends on the product - it may be deployed services,
* storage buckets, managed database instances, etc.
*
* If project is supplied, this should only return product costs for the given billing entity
* (project in GCP).
*
* The time period is supplied as a Duration rather than intervals, since this is always expected
* to return data for two bucketed time period (e.g. month vs month, or quarter vs quarter).
*
@@ -94,11 +105,13 @@ export type CostInsightsApi = {
* @param group
* @param duration A time duration, such as P1M. See the Duration type for a detailed explanation
* of how the durations are interpreted in Cost Insights.
* @param project (optional) The project id from getGroupProjects or query parameters
*/
getProductInsights(
product: string,
group: string,
duration: Duration,
project: Maybe<string>,
): Promise<ProductCost>;
/**