From 590cd3b26c6c58687930c997779019cf8dfef573 Mon Sep 17 00:00:00 2001 From: Federico Zambelli Date: Fri, 26 Apr 2024 15:00:35 +0200 Subject: [PATCH 1/2] fix: make construct work properly in python --- API.md | 127 +++++++++++++++++++++++++++-- src/application-cost-monitoring.ts | 12 ++- src/index.ts | 1 + 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index 9bec43b..835caac 100644 --- a/API.md +++ b/API.md @@ -311,13 +311,13 @@ Return default SNS topic only if the defultTopic prop has been passed when insta ```typescript import { ApplicationCostMonitoring } from 'cost-monitoring-construct' -new ApplicationCostMonitoring(stack: Stack, props: IApplicationCostMonitoringProps) +new ApplicationCostMonitoring(stack: Stack, props: ApplicationCostMonitoringProps) ``` | **Name** | **Type** | **Description** | | --- | --- | --- | | stack | aws-cdk-lib.Stack | - default stack to track its resources and it will be used to define Budget resources in it. | -| props | IApplicationCostMonitoringProps | *No description.* | +| props | ApplicationCostMonitoringProps | *No description.* | --- @@ -331,7 +331,7 @@ default stack to track its resources and it will be used to define Budget resour ##### `props`Required -- *Type:* IApplicationCostMonitoringProps +- *Type:* ApplicationCostMonitoringProps --- @@ -445,6 +445,123 @@ public readonly applicationName: string; --- +### ApplicationCostMonitoringProps + +- *Implements:* IApplicationCostMonitoringProps + +#### Initializers + +```typescript +import { ApplicationCostMonitoringProps } from 'cost-monitoring-construct' + +new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollars: number, otherStacksIncludedInBudget?: Stack[], defaultTopic?: string, subscribers?: string[]) +``` + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| applicationName | string | *No description.* | +| monthlyLimitInDollars | number | *No description.* | +| otherStacksIncludedInBudget | aws-cdk-lib.Stack[] | *No description.* | +| defaultTopic | string | *No description.* | +| subscribers | string[] | *No description.* | + +--- + +##### `applicationName`Required + +- *Type:* string + +--- + +##### `monthlyLimitInDollars`Required + +- *Type:* number + +--- + +##### `otherStacksIncludedInBudget`Optional + +- *Type:* aws-cdk-lib.Stack[] + +--- + +##### `defaultTopic`Optional + +- *Type:* string + +--- + +##### `subscribers`Optional + +- *Type:* string[] + +--- + + + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| applicationName | string | *No description.* | +| monthlyLimitInDollars | number | *No description.* | +| defaultTopic | string | *No description.* | +| otherStacksIncludedInBudget | aws-cdk-lib.Stack[] | *No description.* | +| subscribers | string[] | *No description.* | + +--- + +##### `applicationName`Required + +```typescript +public readonly applicationName: string; +``` + +- *Type:* string + +--- + +##### `monthlyLimitInDollars`Required + +```typescript +public readonly monthlyLimitInDollars: number; +``` + +- *Type:* number + +--- + +##### `defaultTopic`Optional + +```typescript +public readonly defaultTopic: string; +``` + +- *Type:* string + +--- + +##### `otherStacksIncludedInBudget`Optional + +```typescript +public readonly otherStacksIncludedInBudget: Stack[]; +``` + +- *Type:* aws-cdk-lib.Stack[] + +--- + +##### `subscribers`Optional + +```typescript +public readonly subscribers: string[]; +``` + +- *Type:* string[] + +--- + + ### IBudgetStrategy #### Initializers @@ -572,7 +689,7 @@ Return default SNS topic only if the defultTopic prop has been passed when insta - *Extends:* IBudgetStrategyProps -- *Implemented By:* IApplicationCostMonitoringProps +- *Implemented By:* ApplicationCostMonitoringProps, IApplicationCostMonitoringProps #### Properties @@ -762,7 +879,7 @@ public readonly tags: ITag[]; ### IBudgetStrategyProps -- *Implemented By:* IApplicationCostMonitoringProps, IBudgetStrategyProps +- *Implemented By:* ApplicationCostMonitoringProps, IApplicationCostMonitoringProps, IBudgetStrategyProps #### Properties diff --git a/src/application-cost-monitoring.ts b/src/application-cost-monitoring.ts index 0f04f07..3b3067e 100644 --- a/src/application-cost-monitoring.ts +++ b/src/application-cost-monitoring.ts @@ -8,6 +8,16 @@ export interface IApplicationCostMonitoringProps extends IBudgetStrategyProps { otherStacksIncludedInBudget?: Stack[]; } +export class ApplicationCostMonitoringProps implements IApplicationCostMonitoringProps { + constructor( + public applicationName: string, + public monthlyLimitInDollars: number, + public otherStacksIncludedInBudget?: Stack[], + public defaultTopic?: string, + public subscribers?: string[] + ) {} +} + export class ApplicationCostMonitoring extends IBudgetStrategy { readonly applicationName: string; private otherStacks: Stack[]; @@ -41,7 +51,7 @@ export class ApplicationCostMonitoring extends IBudgetStrategy { * budgetStratgy.monitor(); * */ - constructor(stack: Stack, props: IApplicationCostMonitoringProps) { + constructor(stack: Stack, props: ApplicationCostMonitoringProps) { super(stack, props); if (props.monthlyLimitInDollars < 30) { diff --git a/src/index.ts b/src/index.ts index c1889ef..bbda665 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ export { AccountCostMonitoring } from "./account-cost-monitoring"; export { ApplicationCostMonitoring, + ApplicationCostMonitoringProps, IApplicationCostMonitoringProps, } from "./application-cost-monitoring"; export * from "./budget-strategy"; From 50a5978a3bbc442299189b51374910964626ae3c Mon Sep 17 00:00:00 2001 From: Federico Zambelli Date: Fri, 26 Apr 2024 15:49:24 +0200 Subject: [PATCH 2/2] feat: user can input custom cost allocation tag --- API.md | 31 +++++++++++++++++++++++++++++- src/application-cost-monitoring.ts | 9 +++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 835caac..1de6c79 100644 --- a/API.md +++ b/API.md @@ -454,7 +454,7 @@ public readonly applicationName: string; ```typescript import { ApplicationCostMonitoringProps } from 'cost-monitoring-construct' -new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollars: number, otherStacksIncludedInBudget?: Stack[], defaultTopic?: string, subscribers?: string[]) +new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollars: number, otherStacksIncludedInBudget?: Stack[], defaultTopic?: string, subscribers?: string[], costAllocationTag?: string) ``` | **Name** | **Type** | **Description** | @@ -464,6 +464,7 @@ new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollar | otherStacksIncludedInBudget | aws-cdk-lib.Stack[] | *No description.* | | defaultTopic | string | *No description.* | | subscribers | string[] | *No description.* | +| costAllocationTag | string | *No description.* | --- @@ -497,6 +498,12 @@ new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollar --- +##### `costAllocationTag`Optional + +- *Type:* string + +--- + #### Properties @@ -505,6 +512,7 @@ new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollar | --- | --- | --- | | applicationName | string | *No description.* | | monthlyLimitInDollars | number | *No description.* | +| costAllocationTag | string | *No description.* | | defaultTopic | string | *No description.* | | otherStacksIncludedInBudget | aws-cdk-lib.Stack[] | *No description.* | | subscribers | string[] | *No description.* | @@ -531,6 +539,16 @@ public readonly monthlyLimitInDollars: number; --- +##### `costAllocationTag`Optional + +```typescript +public readonly costAllocationTag: string; +``` + +- *Type:* string + +--- + ##### `defaultTopic`Optional ```typescript @@ -700,6 +718,7 @@ Return default SNS topic only if the defultTopic prop has been passed when insta | defaultTopic | string | *No description.* | | subscribers | string[] | *No description.* | | applicationName | string | *No description.* | +| costAllocationTag | string | *No description.* | | otherStacksIncludedInBudget | aws-cdk-lib.Stack[] | *No description.* | --- @@ -744,6 +763,16 @@ public readonly applicationName: string; --- +##### `costAllocationTag`Optional + +```typescript +public readonly costAllocationTag: string; +``` + +- *Type:* string + +--- + ##### `otherStacksIncludedInBudget`Optional ```typescript diff --git a/src/application-cost-monitoring.ts b/src/application-cost-monitoring.ts index 3b3067e..307ad5e 100644 --- a/src/application-cost-monitoring.ts +++ b/src/application-cost-monitoring.ts @@ -6,6 +6,7 @@ import { TimeUnit } from "./utils"; export interface IApplicationCostMonitoringProps extends IBudgetStrategyProps { applicationName: string; otherStacksIncludedInBudget?: Stack[]; + costAllocationTag?: string; } export class ApplicationCostMonitoringProps implements IApplicationCostMonitoringProps { @@ -14,13 +15,15 @@ export class ApplicationCostMonitoringProps implements IApplicationCostMonitorin public monthlyLimitInDollars: number, public otherStacksIncludedInBudget?: Stack[], public defaultTopic?: string, - public subscribers?: string[] + public subscribers?: string[], + public costAllocationTag?: string ) {} } export class ApplicationCostMonitoring extends IBudgetStrategy { readonly applicationName: string; private otherStacks: Stack[]; + private costAllocationTag?: string /** * Default Application CostMonitoring class that implements daily and monthly budgets. @@ -31,6 +34,7 @@ export class ApplicationCostMonitoring extends IBudgetStrategy { * @param props.monthlyLimitInDollars - montly limit in US Dollors. * @param props.defaultTopic - default SNS topic name. Only if provided, the BudgetStratgy creates an SNS topic and send notifications to it. * @param props.subscribers - list of email address that the CostMonitoring will use to send alerts to. + * @param props.costAllocationTag - Tag key used to track resources' expenditure. Only if provided, it will be used to tag the application resources. * * @example tracking budget for an application called `my-application`: * const app = new cdk.App(); @@ -62,6 +66,7 @@ export class ApplicationCostMonitoring extends IBudgetStrategy { this.applicationName = props.applicationName; this.otherStacks = props.otherStacksIncludedInBudget ?? []; + this.costAllocationTag = props.costAllocationTag; } protected createDailyBudgets( @@ -143,6 +148,6 @@ export class ApplicationCostMonitoring extends IBudgetStrategy { * Default key name for application tag. */ protected get applicationTagKey(): string { - return "cm:application"; + return this.costAllocationTag || "cm:application"; } }