-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(cloudwatch): add contributor insights widget #13008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
packages/@aws-cdk/aws-cloudwatch/lib/contributor-insights-widget.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { LegendPosition } from './graph'; | ||
import { ConcreteWidget } from './widget'; | ||
/** | ||
* The number of top contributors to show. | ||
*/ | ||
export enum TopContributors { | ||
/** | ||
* The top 10 contributors | ||
*/ | ||
TOP10 = 10, | ||
/** | ||
* The top 25 contributors | ||
*/ | ||
TOP25 = 25, | ||
/** | ||
* The top 50 contributors | ||
*/ | ||
TOP50 = 50, | ||
/** | ||
* The top 100 contributors | ||
*/ | ||
TOP100 = 100, | ||
} | ||
|
||
/** | ||
* Statistic to use over the aggregation period | ||
*/ | ||
export enum OrderStatistic { | ||
/** | ||
* All values submitted for the matching metric added together. | ||
* This statistic can be useful for determining the total volume of a metric. | ||
*/ | ||
SUM = 'Sum', | ||
/** | ||
* The highest value observed during the specified period. | ||
* You can use this value to determine high volumes of activity for your application. | ||
*/ | ||
MAXIMUM = 'Maximum' | ||
} | ||
|
||
/** | ||
* Properties for a Contributor Insights widget | ||
*/ | ||
export interface ContributorInsightsWidgetProps { | ||
/** | ||
* Title for the widget | ||
* | ||
* @default No title | ||
*/ | ||
readonly title?: string; | ||
|
||
/** | ||
* Insights rule to display | ||
*/ | ||
readonly ruleName: string; | ||
|
||
/** | ||
* The selection of contributors to display | ||
* | ||
* @default Top 10 | ||
*/ | ||
readonly contributorSelection?: TopContributors; | ||
|
||
/** | ||
* Position of the legend | ||
* | ||
* @default - bottom | ||
*/ | ||
readonly legendPosition?: LegendPosition; | ||
|
||
/** | ||
* The region the metrics of this widget should be taken from | ||
* | ||
* @default Current region | ||
*/ | ||
readonly region?: string; | ||
|
||
/** | ||
* Whether the graph should be shown as stacked lines | ||
* | ||
* @default false | ||
*/ | ||
readonly stacked?: boolean; | ||
|
||
/** | ||
* What function to use for aggregating. | ||
* | ||
* @default Statistic.SUM | ||
*/ | ||
readonly statistic?: OrderStatistic; | ||
|
||
/** | ||
* The period over which the statistics are applied. | ||
* | ||
* @default Duration.minutes(5) | ||
*/ | ||
readonly period?: cdk.Duration; | ||
|
||
/** | ||
* Width of the widget, in a grid of 24 units wide | ||
* | ||
* @default 6 | ||
*/ | ||
readonly width?: number; | ||
|
||
/** | ||
* Height of the widget | ||
* | ||
* @default 6 | ||
*/ | ||
readonly height?: number; | ||
|
||
/** | ||
* Account the contributor insights data comes from | ||
* | ||
* @default Deployment account | ||
*/ | ||
readonly account?: string; | ||
} | ||
|
||
/** | ||
* Display contributor insights | ||
*/ | ||
export class ContributorInsightsWidget extends ConcreteWidget { | ||
private readonly props: ContributorInsightsWidgetProps; | ||
private period: number; | ||
|
||
constructor(props: ContributorInsightsWidgetProps) { | ||
super(props.width || 6, props.height || 6); | ||
|
||
this.period = (props.period || cdk.Duration.minutes(5)).toSeconds(); | ||
if (![60, 300, 900, 3600, 21600, 86400].includes(this.period)) { | ||
throw new Error( | ||
`'period' must be 60s, 300s, 900s, 3600s, 21600s, or 86400s, received ${this.period}`, | ||
); | ||
} | ||
this.props = props; | ||
} | ||
|
||
public toJson(): any[] { | ||
return [ | ||
{ | ||
type: 'metric', | ||
width: this.width, | ||
height: this.height, | ||
x: this.x, | ||
y: this.y, | ||
stacked: this.props.stacked || false, | ||
properties: { | ||
accountId: this.props.account, | ||
period: this.period, | ||
view: 'timeSeries', | ||
title: this.props.title, | ||
region: this.props.region || cdk.Aws.REGION, | ||
insightRule: { | ||
maxContributorCount: | ||
this.props.contributorSelection || TopContributors.TOP10, | ||
orderBy: this.props.statistic || OrderStatistic.SUM, | ||
ruleName: this.props.ruleName, | ||
}, | ||
legend: | ||
this.props.legendPosition !== undefined | ||
? { position: this.props.legendPosition } | ||
: undefined, | ||
}, | ||
}, | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is an "insights rule" a resource that is created independently?
In that case, referencing it should follow the same rules as referencing other AWS resources: we don't accept buckets as
bucketName: string
, we accept bucket asbucket: IBucket
.By that same token, we're probably going to need an
IInsightRule
and anInsightRule.fromInsightRuleName()
to produce one.You could go as far as completely fill out the L2 for
AWS::CloudWatch::InsightRule
but I will accept anabstract
class that only allows importing existing insight rules as a minimal delta from what we have, to move this PR forward.