Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from akhainak/fix/alerts-naming
Browse files Browse the repository at this point in the history
fix: alerts naming
  • Loading branch information
vorobievalex authored Aug 4, 2021
2 parents fa54cf1 + ec82cbe commit 0a3c415
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/conditions/infrastructure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { defaultAlertTypes } from '../../constants/alerts'
import { ConditionType } from '../../constants/condition-type'
import defaultAlerts from './default-alerts'

const getInfrastructureCondition = (alert, serviceName, policyId) => {
const getInfrastructureCondition = (alert, policyId) => {
if (defaultAlertTypes.includes(alert.type)) {
const defaultConfig = defaultAlerts[alert.type]
return {
policy_id: { Ref: policyId },
data: {
type: ConditionType.INFRA_METRIC,
name: `${serviceName} - ${alert.title}`,
name: alert.title,
enabled: alert.enabled,
filter: {
and: [
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class NewRelicPlugin implements Plugin {
Type: 'Custom::NewRelicInfrastructureCondition',
Properties: {
ServiceToken: this.infrastructureConditionServiceToken,
...getInfrastructureCondition(alert, this.serviceName, this.normalizedPolicyName)
...getInfrastructureCondition(alert, this.normalizedPolicyName)
}
}
}
Expand Down Expand Up @@ -274,6 +274,7 @@ class NewRelicPlugin implements Plugin {
this.serviceName = `${getNormalizedName(this.serverless.service.getServiceName())} ${upperCase(
this.awsProvider.getStage()
)}`

this.policyName = this.customPolicyName
? `${this.customPolicyName} ${upperCase(this.awsProvider.getStage())}`
: this.serviceName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dummy Throttles",
"name": "Dummy Throttles",
"enabled": true,
"filter": {
"and": [
Expand Down Expand Up @@ -58,7 +58,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Duration 1 sec",
"name": "Duration 1 sec",
"enabled": true,
"filter": {
"and": [
Expand Down Expand Up @@ -98,7 +98,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Function Errors",
"name": "Function Errors",
"enabled": true,
"filter": {
"and": [
Expand Down Expand Up @@ -137,7 +137,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Api Gateway 4 XX Errors",
"name": "Api Gateway 4 XX Errors",
"enabled": true,
"filter": {
"and": [
Expand Down Expand Up @@ -174,7 +174,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Api Gateway 5 XX Errors",
"name": "Api Gateway 5 XX Errors",
"enabled": true,
"filter": {
"and": [
Expand Down Expand Up @@ -211,7 +211,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Sqs Dlq Visible Messages",
"name": "Sqs Dlq Visible Messages",
"enabled": true,
"filter": {
"and": [
Expand Down Expand Up @@ -249,7 +249,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dynamo Db Batch Get System Errors",
"name": "Dynamo Db Batch Get System Errors",
"enabled": false,
"filter": {
"and": [
Expand Down Expand Up @@ -287,7 +287,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dynamo Db Batch Write System Errors",
"name": "Dynamo Db Batch Write System Errors",
"enabled": false,
"filter": {
"and": [
Expand Down Expand Up @@ -325,7 +325,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dynamo Db Delete System Errors",
"name": "Dynamo Db Delete System Errors",
"enabled": false,
"filter": {
"and": [
Expand Down Expand Up @@ -363,7 +363,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dynamo Db Get System Errors",
"name": "Dynamo Db Get System Errors",
"enabled": false,
"filter": {
"and": [
Expand Down Expand Up @@ -401,7 +401,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dynamo Db Put System Errors",
"name": "Dynamo Db Put System Errors",
"enabled": false,
"filter": {
"and": [
Expand Down Expand Up @@ -439,7 +439,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dynamo Db Query System Errors",
"name": "Dynamo Db Query System Errors",
"enabled": false,
"filter": {
"and": [
Expand Down Expand Up @@ -477,7 +477,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dynamo Db Scan System Errors",
"name": "Dynamo Db Scan System Errors",
"enabled": false,
"filter": {
"and": [
Expand Down Expand Up @@ -515,7 +515,7 @@
},
"data": {
"type": "infra_metric",
"name": "PluginTest TEST - Dynamo Db Update System Errors",
"name": "Dynamo Db Update System Errors",
"enabled": false,
"filter": {
"and": [
Expand Down
32 changes: 16 additions & 16 deletions test/__snapshots__/plugin.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Object {
],
},
"integration_provider": undefined,
"name": "TestService TEST - Api Gateway 4 XX Errors",
"name": "Api Gateway 4 XX Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -67,7 +67,7 @@ Object {
],
},
"integration_provider": undefined,
"name": "TestService TEST - Api Gateway 5 XX Errors",
"name": "Api Gateway 5 XX Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -112,7 +112,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db Batch Get System Errors",
"name": "Dynamo Db Batch Get System Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -152,7 +152,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db Batch Write System Errors",
"name": "Dynamo Db Batch Write System Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -192,7 +192,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db Delete System Errors",
"name": "Dynamo Db Delete System Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -232,7 +232,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db Get System Errors",
"name": "Dynamo Db Get System Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -272,7 +272,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db Put System Errors",
"name": "Dynamo Db Put System Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -312,7 +312,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db Query System Errors",
"name": "Dynamo Db Query System Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -352,7 +352,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db Scan System Errors",
"name": "Dynamo Db Scan System Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -392,7 +392,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db Update System Errors",
"name": "Dynamo Db Update System Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -432,7 +432,7 @@ Object {
],
},
"integration_provider": "DynamoDbTable",
"name": "TestService TEST - Dynamo Db User Errors",
"name": "Dynamo Db User Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -477,7 +477,7 @@ Object {
],
},
"integration_provider": "LambdaFunction",
"name": "TestService TEST - Function Duration 1 Sec",
"name": "Function Duration 1 Sec",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -517,7 +517,7 @@ Object {
],
},
"integration_provider": "LambdaFunction",
"name": "TestService TEST - Function Errors",
"name": "Function Errors",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -557,7 +557,7 @@ Object {
],
},
"integration_provider": "LambdaFunction",
"name": "TestService TEST - Function Throttles",
"name": "Function Throttles",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -601,7 +601,7 @@ Object {
],
},
"integration_provider": "LambdaFunction",
"name": "TestService TEST - Test Function 2 Function Duration 1 Sec",
"name": "Test Function 2 Function Duration 1 Sec",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down Expand Up @@ -675,7 +675,7 @@ Object {
],
},
"integration_provider": "SqsQueue",
"name": "TestService TEST - Sqs Dlq Visible Messages",
"name": "Sqs Dlq Visible Messages",
"policy_id": Object {
"Ref": "TestServiceTestNewRelicPolicy",
},
Expand Down
1 change: 1 addition & 0 deletions test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ describe('Newrelic Alert Plugin', () => {

it('should filter out with warning all unknown alerts', () => {
const plugin = new NewRelicPlugin(getServerless(minimalConfig))
plugin.configure()
const alerts = plugin.getGlobalAlerts([FunctionAlert.THROTTLES, 'unknownAlert'])
expect(alerts).toEqual([
{
Expand Down

0 comments on commit 0a3c415

Please sign in to comment.