forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-cloudwatch): query results widget
Add a `QueryWidget` to generate a dashboard widget showing the results of a query from Logs Insights. This was a missing feature which is available in the console. Also make `ILogGroup` extend `cloudwatch.IQueryLogGroup` so it can be passed as a property for a `QueryWidget`. closes aws#3681
- Loading branch information
1 parent
1423c53
commit 300a79f
Showing
7 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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,83 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { ConcreteWidget } from './widget'; | ||
|
||
/** | ||
* Allows any object providing a logGroupName to be supplied to a QueryWidget such as an ILogGroup. | ||
*/ | ||
export interface IQueryLogGroup { | ||
/** | ||
* The name of this log group | ||
*/ | ||
readonly logGroupName: string; | ||
} | ||
|
||
/** | ||
* Properties for a Query widget | ||
*/ | ||
export interface QueryWidgetProps { | ||
/** | ||
* Title for the widget | ||
* | ||
* @default No title | ||
*/ | ||
readonly title?: string; | ||
|
||
/** | ||
* Log group to query | ||
*/ | ||
readonly logGroup: IQueryLogGroup; // ILogGroup cannot be used without creating cyclic dependencies. | ||
|
||
/** | ||
* Query for log insights | ||
*/ | ||
readonly queryString: string; | ||
|
||
/** | ||
* The region the metrics of this widget should be taken from | ||
* | ||
* @default Current region | ||
*/ | ||
readonly region?: string; | ||
|
||
/** | ||
* 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; | ||
} | ||
|
||
/** | ||
* Display query results from Logs Insights | ||
*/ | ||
export class QueryWidget extends ConcreteWidget { | ||
private readonly props: QueryWidgetProps; | ||
|
||
constructor(props: QueryWidgetProps) { | ||
super(props.width || 6, props.height || 6); | ||
this.props = props; | ||
} | ||
|
||
public toJson(): any[] { | ||
return [{ | ||
type: 'log', | ||
width: this.width, | ||
height: this.height, | ||
x: this.x, | ||
y: this.y, | ||
properties: { | ||
view: 'table', | ||
title: this.props.title, | ||
region: this.props.region || cdk.Aws.REGION, | ||
query: `SOURCE '${this.props.logGroup.logGroupName}' | ${this.props.queryString}`, | ||
}, | ||
}]; | ||
} | ||
} |
This file contains 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 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 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 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