-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloudwatch): LogGroup Query Widget
Add a `LogQueryWidget` 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. closes #3681
- Loading branch information
1 parent
e72c353
commit 1275952
Showing
6 changed files
with
157 additions
and
2 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,100 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { ConcreteWidget } from './widget'; | ||
|
||
/** | ||
* Properties for a Query widget | ||
*/ | ||
export interface LogQueryWidgetProps { | ||
/** | ||
* Title for the widget | ||
* | ||
* @default No title | ||
*/ | ||
readonly title?: string; | ||
|
||
/** | ||
* Names of log groups to query | ||
*/ | ||
readonly logGroupNames: string[]; | ||
|
||
/** | ||
* Full query string for log insights | ||
* | ||
* Be sure to prepend every new line with a newline and pipe character | ||
* (`\n|`). | ||
* | ||
* @default - Exactly one of `queryString`, `queryLines` is required. | ||
*/ | ||
readonly queryString?: string; | ||
|
||
/** | ||
* A sequence of lines to use to build the query | ||
* | ||
* The query will be built by joining the lines together using `\n|`. | ||
* | ||
* @default - Exactly one of `queryString`, `queryLines` is required. | ||
*/ | ||
readonly queryLines?: 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 LogQueryWidget extends ConcreteWidget { | ||
private readonly props: LogQueryWidgetProps; | ||
|
||
constructor(props: LogQueryWidgetProps) { | ||
super(props.width || 6, props.height || 6); | ||
this.props = props; | ||
|
||
if (props.logGroupNames.length === 0) { | ||
throw new Error('Specify at least one log group name.'); | ||
} | ||
|
||
if (!!props.queryString === !!props.queryLines) { | ||
throw new Error('Specify exactly one of \'queryString\' and \'queryLines\''); | ||
} | ||
} | ||
|
||
public toJson(): any[] { | ||
const sources = this.props.logGroupNames.map(l => `SOURCE '${l}'`).join(' | '); | ||
const query = this.props.queryLines | ||
? this.props.queryLines.join('\n| ') | ||
: this.props.queryString; | ||
|
||
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: `${sources} | ${query}`, | ||
}, | ||
}]; | ||
} | ||
} |
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