Skip to content

Commit

Permalink
fix: Change MonitorType interface
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Change MonitorType from union type to enum.
  • Loading branch information
NomadBlacky committed May 5, 2021
1 parent eee27cb commit f789836
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
28 changes: 26 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ Name|Description
[MonitorThresholds](#nomadblacky-cdk-datadog-resources-monitorthresholds)|*No description*


**Enums**

Name|Description
----|-----------
[MonitorType](#nomadblacky-cdk-datadog-resources-monitortype)|The type of the monitor.



## class DatadogMonitor <a id="nomadblacky-cdk-datadog-resources-datadogmonitor"></a>

Expand All @@ -38,7 +45,7 @@ new DatadogMonitor(scope: Construct, id: string, props: DatadogMonitorProps)
* **props** (<code>[DatadogMonitorProps](#nomadblacky-cdk-datadog-resources-datadogmonitorprops)</code>) *No description*
* **datadogCredentials** (<code>[DatadogCredentials](#nomadblacky-cdk-datadog-resources-datadogcredentials)</code>) Credentials for the Datadog API.
* **query** (<code>string</code>) The monitor query.
* **type** (<code>string</code>) The type of the monitor.
* **type** (<code>[MonitorType](#nomadblacky-cdk-datadog-resources-monitortype)</code>) The type of the monitor.
* **message** (<code>string</code>) A message to include with notifications for the monitor. __*Optional*__
* **multi** (<code>boolean</code>) Whether or not the monitor is multi alert. __*Optional*__
* **name** (<code>string</code>) Name of the monitor. __*Optional*__
Expand Down Expand Up @@ -74,7 +81,7 @@ Name | Type | Description
-----|------|-------------
**datadogCredentials** | <code>[DatadogCredentials](#nomadblacky-cdk-datadog-resources-datadogcredentials)</code> | Credentials for the Datadog API.
**query** | <code>string</code> | The monitor query.
**type** | <code>string</code> | The type of the monitor.
**type** | <code>[MonitorType](#nomadblacky-cdk-datadog-resources-monitortype)</code> | The type of the monitor.
**message**? | <code>string</code> | A message to include with notifications for the monitor.<br/>__*Optional*__
**multi**? | <code>boolean</code> | Whether or not the monitor is multi alert.<br/>__*Optional*__
**name**? | <code>string</code> | Name of the monitor.<br/>__*Optional*__
Expand Down Expand Up @@ -142,3 +149,20 @@ Name | Type | Description



## enum MonitorType <a id="nomadblacky-cdk-datadog-resources-monitortype"></a>

The type of the monitor.

Name | Description
-----|-----
**COMPOSITE** |
**EVENT_ALERT** |
**LOG_ALERT** |
**METRIC_ALERT** |
**PROCESS_ALERT** |
**QUERY_ALERT** |
**SERVICE_CHECK** |
**SYNTHETICS_ALERT** |
**TRACE_ANALYTICS_ALERT** |


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ new DatadogMonitor(stack, 'TestMonitor', {
applicationKey: process.env.DATADOG_APP_KEY || 'DATADOG_APP_KEY',
},
query: 'avg(last_1h):sum:system.cpu.system{host:host0} > 100',
type: 'query alert',
type: MonitorType.QueryAlert,
name: 'Test Monitor',
options: {
thresholds: {
Expand Down
3 changes: 2 additions & 1 deletion src/cdk-app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { App, Stack } from '@aws-cdk/core';
import { DatadogMonitor } from './monitors/datadog-monitor';
import { MonitorType } from './monitors/properties';

const app = new App();
const stack = new Stack(app, 'CdkDatadogResourcesTestStack');
Expand All @@ -10,7 +11,7 @@ new DatadogMonitor(stack, 'TestMonitor', {
applicationKey: process.env.DATADOG_APP_KEY || 'DATADOG_APP_KEY',
},
query: 'avg(last_1h):sum:system.cpu.system{host:host0} > 100',
type: 'query alert',
type: MonitorType.QUERY_ALERT,
name: 'Test Monitor',
options: {
thresholds: {
Expand Down
24 changes: 14 additions & 10 deletions src/monitors/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ export interface DatadogCredentials {
readonly apiURL?: string;
}

export type MonitorType =
| 'composite'
| 'event alert'
| 'log alert'
| 'metric alert'
| 'process alert'
| 'query alert'
| 'service check'
| 'synthetics alert'
| 'trace-analytics alert';
/**
* The type of the monitor
*/
export enum MonitorType {
COMPOSITE = 'composite',
EVENT_ALERT = 'event alert',
LOG_ALERT = 'log alert',
METRIC_ALERT = 'metric alert',
PROCESS_ALERT = 'process alert',
QUERY_ALERT = 'query alert',
SERVICE_CHECK = 'service check',
SYNTHETICS_ALERT = 'synthetics alert',
TRACE_ANALYTICS_ALERT = 'trace-analytics alert',
}

export interface MonitorOptions {
/** Whether or not to include a sample of the logs */
Expand Down
4 changes: 2 additions & 2 deletions test/monitors/datadog-monitor.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SynthUtils } from '@aws-cdk/assert';
import { Stack } from '@aws-cdk/core';
import { DatadogMonitor } from '../../src';
import { DatadogMonitor, MonitorType } from '../../src';

test('Snapshot test', () => {
const stack = new Stack();
Expand All @@ -11,7 +11,7 @@ test('Snapshot test', () => {
applicationKey: 'DATADOG_APP_KEY',
},
query: 'avg(last_1h):sum:system.cpu.system{host:host0} > 100',
type: 'query alert',
type: MonitorType.QUERY_ALERT,
name: 'Test Monitor',
options: {
thresholds: {
Expand Down

0 comments on commit f789836

Please sign in to comment.