Update getProductInsights to accept a single object with fields
This commit is contained in:
@@ -26,6 +26,34 @@ import {
|
||||
MetricData,
|
||||
} from '../types';
|
||||
|
||||
export type ProductInsightsOptions = {
|
||||
/**
|
||||
* The product from the cost-insights configuration in app-config.yaml
|
||||
*/
|
||||
product: string;
|
||||
|
||||
/**
|
||||
* The group id from getUserGroups or query parameters
|
||||
*/
|
||||
group: string;
|
||||
|
||||
/**
|
||||
* A time duration, such as P1M. See the Duration type for a detailed explanation
|
||||
* of how the durations are interpreted in Cost Insights.
|
||||
*/
|
||||
duration: Duration;
|
||||
|
||||
/**
|
||||
* The most current date for which billing data is complete, in YYYY-MM-DD format.
|
||||
*/
|
||||
lastCompleteBillingDate: string;
|
||||
|
||||
/**
|
||||
* (optional) The project id from getGroupProjects or query parameters
|
||||
*/
|
||||
project: Maybe<string>;
|
||||
};
|
||||
|
||||
export type CostInsightsApi = {
|
||||
/**
|
||||
* Get the most current date for which billing data is complete, in YYYY-MM-DD format. This helps
|
||||
@@ -108,21 +136,9 @@ export type CostInsightsApi = {
|
||||
* 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).
|
||||
*
|
||||
* @param product The product from the cost-insights configuration in app-config.yaml
|
||||
* @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 lastBillingDate The most current date for which billing data is complete, in YYYY-MM-DD format.
|
||||
* @param project (optional) The project id from getGroupProjects or query parameters
|
||||
* @param options Options to use when fetching insights for a particular cloud product and interval timeframe.
|
||||
*/
|
||||
getProductInsights(
|
||||
product: string,
|
||||
group: string,
|
||||
duration: Duration,
|
||||
lastBillingDate: string,
|
||||
project: Maybe<string>,
|
||||
): Promise<ProductCost>;
|
||||
|
||||
getProductInsights(options: ProductInsightsOptions): Promise<ProductCost>;
|
||||
/**
|
||||
* Get current cost alerts for a given group. These show up as Action Items for the group on the
|
||||
* Cost Insights page. Alerts may include cost-saving recommendations, such as infrastructure
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import regression, { DataPoint } from 'regression';
|
||||
import { CostInsightsApi } from '../src/api';
|
||||
import { CostInsightsApi, ProductInsightsOptions } from '../src/api';
|
||||
import {
|
||||
Alert,
|
||||
ChangeStatistic,
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
DEFAULT_DATE_FORMAT,
|
||||
Duration,
|
||||
Group,
|
||||
Maybe,
|
||||
MetricData,
|
||||
ProductCost,
|
||||
Project,
|
||||
@@ -194,42 +193,35 @@ export class ExampleCostInsightsClient implements CostInsightsApi {
|
||||
}
|
||||
|
||||
async getProductInsights(
|
||||
product: string,
|
||||
group: string,
|
||||
duration: Duration,
|
||||
lastBillingDate: string,
|
||||
project: Maybe<string>,
|
||||
productInsightsOptions: ProductInsightsOptions,
|
||||
): Promise<ProductCost> {
|
||||
const projectProductInsights = await this.request(
|
||||
{ product, group, duration, lastBillingDate, 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 projectProductInsights = await this.request(productInsightsOptions, {
|
||||
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, project },
|
||||
productInsightsOptions,
|
||||
{
|
||||
aggregation: [200_000, 250_000],
|
||||
change: {
|
||||
@@ -277,7 +269,9 @@ export class ExampleCostInsightsClient implements CostInsightsApi {
|
||||
},
|
||||
);
|
||||
|
||||
return project ? projectProductInsights : productInsights;
|
||||
return productInsightsOptions.project
|
||||
? projectProductInsights
|
||||
: productInsights;
|
||||
}
|
||||
|
||||
async getAlerts(group: string): Promise<Alert[]> {
|
||||
|
||||
@@ -82,13 +82,13 @@ export const ProductInsightsCard = ({ product }: ProductInsightsCardProps) => {
|
||||
async function load() {
|
||||
if (loadingProduct) {
|
||||
try {
|
||||
const p: ProductCost = await client.getProductInsights(
|
||||
product.kind,
|
||||
group!,
|
||||
productFilter!.duration,
|
||||
const p: ProductCost = await client.getProductInsights({
|
||||
product: product.kind,
|
||||
group: group!,
|
||||
duration: productFilter!.duration,
|
||||
lastCompleteBillingDate,
|
||||
project,
|
||||
);
|
||||
});
|
||||
setResource(p);
|
||||
} catch (e) {
|
||||
setError(e);
|
||||
|
||||
@@ -18,7 +18,7 @@ export { plugin } from './plugin';
|
||||
export * from './client';
|
||||
export * from './api';
|
||||
export * from './components';
|
||||
export { useCurrency, CurrencyContext } from './hooks';
|
||||
export { useCurrency } from './hooks';
|
||||
export * from './types';
|
||||
export * from './utils/tests';
|
||||
export * from './utils/duration';
|
||||
|
||||
Reference in New Issue
Block a user