Skip to content

Commit

Permalink
feat: user can input custom cost allocation tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Zambelli committed Apr 26, 2024
1 parent 590cd3b commit 50a5978
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
31 changes: 30 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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** |
Expand All @@ -464,6 +464,7 @@ new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollar
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.Initializer.parameter.otherStacksIncludedInBudget">otherStacksIncludedInBudget</a></code> | <code>aws-cdk-lib.Stack[]</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.Initializer.parameter.defaultTopic">defaultTopic</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.Initializer.parameter.subscribers">subscribers</a></code> | <code>string[]</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.Initializer.parameter.costAllocationTag">costAllocationTag</a></code> | <code>string</code> | *No description.* |

---

Expand Down Expand Up @@ -497,6 +498,12 @@ new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollar

---

##### `costAllocationTag`<sup>Optional</sup> <a name="costAllocationTag" id="cost-monitoring-construct.ApplicationCostMonitoringProps.Initializer.parameter.costAllocationTag"></a>

- *Type:* string

---



#### Properties <a name="Properties" id="Properties"></a>
Expand All @@ -505,6 +512,7 @@ new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollar
| --- | --- | --- |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.property.applicationName">applicationName</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.property.monthlyLimitInDollars">monthlyLimitInDollars</a></code> | <code>number</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.property.costAllocationTag">costAllocationTag</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.property.defaultTopic">defaultTopic</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.property.otherStacksIncludedInBudget">otherStacksIncludedInBudget</a></code> | <code>aws-cdk-lib.Stack[]</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.ApplicationCostMonitoringProps.property.subscribers">subscribers</a></code> | <code>string[]</code> | *No description.* |
Expand All @@ -531,6 +539,16 @@ public readonly monthlyLimitInDollars: number;

---

##### `costAllocationTag`<sup>Optional</sup> <a name="costAllocationTag" id="cost-monitoring-construct.ApplicationCostMonitoringProps.property.costAllocationTag"></a>

```typescript
public readonly costAllocationTag: string;
```

- *Type:* string

---

##### `defaultTopic`<sup>Optional</sup> <a name="defaultTopic" id="cost-monitoring-construct.ApplicationCostMonitoringProps.property.defaultTopic"></a>

```typescript
Expand Down Expand Up @@ -700,6 +718,7 @@ Return default SNS topic only if the defultTopic prop has been passed when insta
| <code><a href="#cost-monitoring-construct.IApplicationCostMonitoringProps.property.defaultTopic">defaultTopic</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.IApplicationCostMonitoringProps.property.subscribers">subscribers</a></code> | <code>string[]</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.IApplicationCostMonitoringProps.property.applicationName">applicationName</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.IApplicationCostMonitoringProps.property.costAllocationTag">costAllocationTag</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cost-monitoring-construct.IApplicationCostMonitoringProps.property.otherStacksIncludedInBudget">otherStacksIncludedInBudget</a></code> | <code>aws-cdk-lib.Stack[]</code> | *No description.* |

---
Expand Down Expand Up @@ -744,6 +763,16 @@ public readonly applicationName: string;

---

##### `costAllocationTag`<sup>Optional</sup> <a name="costAllocationTag" id="cost-monitoring-construct.IApplicationCostMonitoringProps.property.costAllocationTag"></a>

```typescript
public readonly costAllocationTag: string;
```

- *Type:* string

---

##### `otherStacksIncludedInBudget`<sup>Optional</sup> <a name="otherStacksIncludedInBudget" id="cost-monitoring-construct.IApplicationCostMonitoringProps.property.otherStacksIncludedInBudget"></a>

```typescript
Expand Down
9 changes: 7 additions & 2 deletions src/application-cost-monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TimeUnit } from "./utils";
export interface IApplicationCostMonitoringProps extends IBudgetStrategyProps {
applicationName: string;
otherStacksIncludedInBudget?: Stack[];
costAllocationTag?: string;
}

export class ApplicationCostMonitoringProps implements IApplicationCostMonitoringProps {
Expand All @@ -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.
Expand All @@ -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();
Expand Down Expand Up @@ -62,6 +66,7 @@ export class ApplicationCostMonitoring extends IBudgetStrategy {

this.applicationName = props.applicationName;
this.otherStacks = props.otherStacksIncludedInBudget ?? [];
this.costAllocationTag = props.costAllocationTag;
}

protected createDailyBudgets(
Expand Down Expand Up @@ -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";
}
}

0 comments on commit 50a5978

Please sign in to comment.