Skip to content

Commit 9899afc

Browse files
feat: update third-party-integrations resource (#1554)
Co-authored-by: Rakhul S Prakash <rakhul.s.prakash@peerislands.io>
1 parent edd77b7 commit 9899afc

13 files changed

Lines changed: 204 additions & 17 deletions

File tree

.github/workflows/contract-testing.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
stream-instance: ${{ steps.filter.outputs.stream-instance }}
3737
stream-processor: ${{ steps.filter.outputs.stream-processor }}
3838
stream-workspace: ${{ steps.filter.outputs.stream-workspace }}
39+
third-party-integration: ${{ steps.filter.outputs.third-party-integration }}
3940
steps:
4041
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
4142
if: ${{ github.event_name == 'push' }}
@@ -93,6 +94,8 @@ jobs:
9394
- 'cfn-resources/stream-processor/**'
9495
stream-workspace:
9596
- 'cfn-resources/stream-workspace/**'
97+
third-party-integration:
98+
- 'cfn-resources/third-party-integration/**'
9699
access-list-api-key:
97100
needs: change-detection
98101
if: ${{ needs.change-detection.outputs.access-list-api-key == 'true' }}
@@ -1116,5 +1119,57 @@ jobs:
11161119
cat inputs/inputs_1_create.json
11171120
cat inputs/inputs_1_update.json
11181121
1122+
make run-contract-testing
1123+
make delete-test-resources
1124+
third-party-integration:
1125+
needs: change-detection
1126+
if: ${{ needs.change-detection.outputs.third-party-integration == 'true' }}
1127+
runs-on: ubuntu-latest
1128+
steps:
1129+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
1130+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
1131+
with:
1132+
go-version-file: 'cfn-resources/go.mod'
1133+
- name: setup Atlas CLI
1134+
uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b
1135+
- uses: aws-actions/setup-sam@c2a20b1822cc4a6bc594ff7f1dbb658758e383c3
1136+
with:
1137+
use-installer: true
1138+
- uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
1139+
with:
1140+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }}
1141+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }}
1142+
aws-region: eu-west-1
1143+
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
1144+
with:
1145+
python-version: '3.9'
1146+
cache: 'pip' # caching pip dependencies
1147+
- run: pip install cloudformation-cli cloudformation-cli-go-plugin
1148+
- name: Run the Contract test
1149+
shell: bash
1150+
env:
1151+
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
1152+
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
1153+
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
1154+
MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
1155+
MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action
1156+
WEBHOOK_CREATE_URL: ${{ vars.WEBHOOK_CREATE_URL }}
1157+
WEBHOOK_UPDATE_URL: ${{ vars.WEBHOOK_UPDATE_URL }}
1158+
WEBHOOK_UPDATE_SECRET: ${{ vars.WEBHOOK_UPDATE_SECRET }}
1159+
PROMETHEUS_USER_NAME: ${{ vars.PROMETHEUS_USER_NAME }}
1160+
PROMETHEUS_PASSWORD_NAME: ${{ vars.PROMETHEUS_PASSWORD_NAME }}
1161+
PAGER_DUTY_CREATE_SERVICE_KEY: ${{ vars.PAGER_DUTY_CREATE_SERVICE_KEY }}
1162+
PAGER_DUTY_UPDATE_SERVICE_KEY: ${{ vars.PAGER_DUTY_UPDATE_SERVICE_KEY }}
1163+
DATA_DOG_CREATE_API_KEY: ${{ vars.DATA_DOG_CREATE_API_KEY }}
1164+
DATA_DOG_UPDATE_API_KEY: ${{ vars.DATA_DOG_UPDATE_API_KEY }}
1165+
OPS_GENIE_API_KEY: ${{ vars.OPS_GENIE_API_KEY }}
1166+
MICROSOFT_TEAMS_WEBHOOK_CREATE_URL: ${{ vars.MICROSOFT_TEAMS_WEBHOOK_CREATE_URL }}
1167+
MICROSOFT_TEAMS_WEBHOOK_UPDATE_URL: ${{ vars.MICROSOFT_TEAMS_WEBHOOK_UPDATE_URL }}
1168+
run: |
1169+
cd cfn-resources/third-party-integration
1170+
make create-test-resources
1171+
1172+
cat inputs/*
1173+
11191174
make run-contract-testing
11201175
make delete-test-resources

cfn-resources/third-party-integration/Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ build:
1313

1414
debug:
1515
cfn generate
16-
env GOOS=$(goos) CGO_ENABLED=$(cgo) GOARCH=$(goarch) go build -ldflags="$(ldXflagsD)" -tags="$(tags)" -o bin/bootstrap cmd/main.go
16+
env GOOS=$(goos) CGO_ENABLED=$(cgo) GOARCH=$(goarch) go build -ldflags="$(ldXflagsD)" -tags="$(tags)" -o bin/debug cmd/main.go
1717

1818
clean:
1919
rm -rf bin
20+
21+
create-test-resources:
22+
@echo "==> Creating test files and resources for contract testing"
23+
./test/contract-testing/cfn-test-create.sh
24+
25+
delete-test-resources:
26+
@echo "==> Delete test resources used for contract testing"
27+
./test/contract-testing/cfn-test-delete.sh
28+
29+
run-contract-testing:
30+
@echo "==> Run contract testing"
31+
make build
32+
sam local start-lambda &
33+
cfn test --function-name TestEntrypoint --verbose

cfn-resources/third-party-integration/cmd/resource/model.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/third-party-integration/cmd/resource/resource.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ func updateIntegrationFromSchema(currentModel *Model, integration *admin.ThirdPa
214214
if currentModel.SendUserProvidedResourceTags != nil {
215215
integration.SendUserProvidedResourceTags = currentModel.SendUserProvidedResourceTags
216216
}
217+
if currentModel.SendCollectionLatencyMetrics != nil {
218+
integration.SendCollectionLatencyMetrics = currentModel.SendCollectionLatencyMetrics
219+
}
220+
if currentModel.SendDatabaseMetrics != nil {
221+
integration.SendDatabaseMetrics = currentModel.SendDatabaseMetrics
222+
}
217223
}
218224

219225
func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) {
@@ -331,6 +337,12 @@ func modelToIntegration(currentModel *Model) (out *admin.ThirdPartyIntegration)
331337
if currentModel.SendUserProvidedResourceTags != nil {
332338
out.SendUserProvidedResourceTags = currentModel.SendUserProvidedResourceTags
333339
}
340+
if currentModel.SendCollectionLatencyMetrics != nil {
341+
out.SendCollectionLatencyMetrics = currentModel.SendCollectionLatencyMetrics
342+
}
343+
if currentModel.SendDatabaseMetrics != nil {
344+
out.SendDatabaseMetrics = currentModel.SendDatabaseMetrics
345+
}
334346
return out
335347
}
336348

@@ -346,6 +358,8 @@ func integrationToModel(currentModel Model, integration *admin.ThirdPartyIntegra
346358
ProjectId: currentModel.ProjectId,
347359
Profile: currentModel.Profile,
348360
SendUserProvidedResourceTags: currentModel.SendUserProvidedResourceTags,
361+
SendCollectionLatencyMetrics: currentModel.SendCollectionLatencyMetrics,
362+
SendDatabaseMetrics: currentModel.SendDatabaseMetrics,
349363
}
350364

351365
if !enabled {

cfn-resources/third-party-integration/docs/README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ To declare this entity in your AWS CloudFormation template, use the following sy
3131
"<a href="#enabled" title="Enabled">Enabled</a>" : <i>Boolean</i>,
3232
"<a href="#listenaddress" title="ListenAddress">ListenAddress</a>" : <i>String</i>,
3333
"<a href="#tlspempath" title="TlsPemPath">TlsPemPath</a>" : <i>String</i>,
34-
"<a href="#senduserprovidedresourcetags" title="SendUserProvidedResourceTags">SendUserProvidedResourceTags</a>" : <i>Boolean</i>
34+
"<a href="#senduserprovidedresourcetags" title="SendUserProvidedResourceTags">SendUserProvidedResourceTags</a>" : <i>Boolean</i>,
35+
"<a href="#sendcollectionlatencymetrics" title="SendCollectionLatencyMetrics">SendCollectionLatencyMetrics</a>" : <i>Boolean</i>,
36+
"<a href="#senddatabasemetrics" title="SendDatabaseMetrics">SendDatabaseMetrics</a>" : <i>Boolean</i>
3537
}
3638
}
3739
</pre>
@@ -61,6 +63,8 @@ Properties:
6163
<a href="#listenaddress" title="ListenAddress">ListenAddress</a>: <i>String</i>
6264
<a href="#tlspempath" title="TlsPemPath">TlsPemPath</a>: <i>String</i>
6365
<a href="#senduserprovidedresourcetags" title="SendUserProvidedResourceTags">SendUserProvidedResourceTags</a>: <i>Boolean</i>
66+
<a href="#sendcollectionlatencymetrics" title="SendCollectionLatencyMetrics">SendCollectionLatencyMetrics</a>: <i>Boolean</i>
67+
<a href="#senddatabasemetrics" title="SendDatabaseMetrics">SendDatabaseMetrics</a>: <i>Boolean</i>
6468
</pre>
6569

6670
## Properties
@@ -269,3 +273,23 @@ _Type_: Boolean
269273

270274
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
271275

276+
#### SendCollectionLatencyMetrics
277+
278+
Flag that indicates whether to send collection latency metrics to Datadog, including database names, collection names, and latency metrics on reads, writes, commands, and transactions.
279+
280+
_Required_: No
281+
282+
_Type_: Boolean
283+
284+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
285+
286+
#### SendDatabaseMetrics
287+
288+
Flag that indicates whether to send database metrics to Datadog, including database names and metrics on the number of collections, storage size, and index size.
289+
290+
_Required_: No
291+
292+
_Type_: Boolean
293+
294+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
295+

cfn-resources/third-party-integration/mongodb-atlas-thirdpartyintegration.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@
155155
"SendUserProvidedResourceTags": {
156156
"type": "boolean",
157157
"description": "Flag that indicates whether to include user-defined resource tags when sending metrics and alerts to third-party services."
158+
},
159+
"SendCollectionLatencyMetrics": {
160+
"type": "boolean",
161+
"description": "Flag that indicates whether to send collection latency metrics to Datadog, including database names, collection names, and latency metrics on reads, writes, commands, and transactions."
162+
},
163+
"SendDatabaseMetrics": {
164+
"type": "boolean",
165+
"description": "Flag that indicates whether to send database metrics to Datadog, including database names and metrics on the number of collections, storage size, and index size."
158166
}
159167
},
160168
"typeName": "MongoDB::Atlas::ThirdPartyIntegration",

cfn-resources/third-party-integration/test/cfn-test-create-inputs.sh

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ function usage {
1515
if [ "$#" -ne 1 ]; then usage; fi
1616
if [[ "$*" == help ]]; then usage; fi
1717

18+
profile="default"
19+
if [ ${MONGODB_ATLAS_PROFILE+x} ]; then
20+
echo "profile set to ${MONGODB_ATLAS_PROFILE}"
21+
profile=${MONGODB_ATLAS_PROFILE}
22+
fi
23+
1824
rm -rf inputs
1925
mkdir inputs
2026

@@ -35,30 +41,34 @@ webHookUpdateUrl="$WEBHOOK_UPDATE_URL"
3541
webHookUpdateSecret="$WEBHOOK_UPDATE_SECRET"
3642

3743
jq --arg project_id "$projectId" \
44+
--arg profile "$profile" \
3845
--arg web_hook_create_url "$webHookCreateUrl" \
39-
'.ProjectId?|=$project_id | .Url?|=$web_hook_create_url' \
46+
'.ProjectId?|=$project_id | .Profile?|=$profile | .Url?|=$web_hook_create_url' \
4047
"$(dirname "$0")/inputs_1_create.template.json" >"inputs/inputs_1_create.json"
4148

4249
jq --arg project_id "$projectId" \
50+
--arg profile "$profile" \
4351
--arg web_hook_create_url "$webHookUpdateUrl" \
4452
--arg web_hook_create_secret "$webHookUpdateSecret" \
45-
'.ProjectId?|=$project_id | .Url?|=$web_hook_create_url | .Secret?|=$web_hook_create_secret' \
53+
'.ProjectId?|=$project_id | .Profile?|=$profile | .Url?|=$web_hook_create_url | .Secret?|=$web_hook_create_secret' \
4654
"$(dirname "$0")/inputs_1_update.template.json" >"inputs/inputs_1_update.json"
4755

4856
#PROMETHEUS
4957
prometheusUsrName="$PROMETHEUS_USER_NAME"
5058
prometheusPassword="$PROMETHEUS_PASSWORD_NAME"
5159

5260
jq --arg project_id "$projectId" \
61+
--arg profile "$profile" \
5362
--arg prometheus_usr_name "$prometheusUsrName" \
5463
--arg prometheus_password "$prometheusPassword" \
55-
'.ProjectId?|=$project_id | .UserName?|=$prometheus_usr_name | .Password?|=$prometheus_password' \
64+
'.ProjectId?|=$project_id | .Profile?|=$profile | .UserName?|=$prometheus_usr_name | .Password?|=$prometheus_password' \
5665
"$(dirname "$0")/inputs_2_create.template.json" >"inputs/inputs_2_create.json"
5766

5867
jq --arg project_id "$projectId" \
68+
--arg profile "$profile" \
5969
--arg prometheus_usr_name "$prometheusUsrName" \
6070
--arg prometheus_password "$prometheusPassword" \
61-
'.ProjectId?|=$project_id | .UserName?|=$prometheus_usr_name | .Password?|=$prometheus_password' \
71+
'.ProjectId?|=$project_id | .Profile?|=$profile | .UserName?|=$prometheus_usr_name | .Password?|=$prometheus_password' \
6272
"$(dirname "$0")/inputs_2_update.template.json" >"inputs/inputs_2_update.json"
6373

6474
#PAGER_DUTY
@@ -67,13 +77,15 @@ pagerDutyCreateServiceKey="$PAGER_DUTY_CREATE_SERVICE_KEY"
6777
pagerDutyUpdateServiceKey="$PAGER_DUTY_UPDATE_SERVICE_KEY"
6878

6979
jq --arg project_id "$projectId" \
80+
--arg profile "$profile" \
7081
--arg service_key "$pagerDutyCreateServiceKey" \
71-
'.ProjectId?|=$project_id | .ServiceKey?|=$service_key' \
82+
'.ProjectId?|=$project_id | .Profile?|=$profile | .ServiceKey?|=$service_key' \
7283
"$(dirname "$0")/inputs_3_create.template.json" >"inputs/inputs_3_create.json"
7384

7485
jq --arg project_id "$projectId" \
86+
--arg profile "$profile" \
7587
--arg service_key "$pagerDutyUpdateServiceKey" \
76-
'.ProjectId?|=$project_id | .ServiceKey?|=$service_key' \
88+
'.ProjectId?|=$project_id | .Profile?|=$profile | .ServiceKey?|=$service_key' \
7789
"$(dirname "$0")/inputs_3_update.template.json" >"inputs/inputs_3_update.json"
7890

7991
#DATA_DOG
@@ -82,27 +94,31 @@ dataDogCreateApiKey="$DATA_DOG_CREATE_API_KEY"
8294
dataDogUpdateApiKey="$DATA_DOG_UPDATE_API_KEY"
8395

8496
jq --arg project_id "$projectId" \
97+
--arg profile "$profile" \
8598
--arg data_dog_create_api_key "$dataDogCreateApiKey" \
86-
'.ProjectId?|=$project_id | .ApiKey?|=$data_dog_create_api_key' \
99+
'.ProjectId?|=$project_id | .Profile?|=$profile | .ApiKey?|=$data_dog_create_api_key' \
87100
"$(dirname "$0")/inputs_4_create.template.json" >"inputs/inputs_4_create.json"
88101

89102
jq --arg project_id "$projectId" \
103+
--arg profile "$profile" \
90104
--arg data_dog_update_api_key "$dataDogUpdateApiKey" \
91-
'.ProjectId?|=$project_id | .ApiKey?|=$data_dog_update_api_key' \
105+
'.ProjectId?|=$project_id | .Profile?|=$profile | .ApiKey?|=$data_dog_update_api_key' \
92106
"$(dirname "$0")/inputs_4_update.template.json" >"inputs/inputs_4_update.json"
93107

94108
#OPS_GENIE
95109

96110
opsGenieApiKey="$OPS_GENIE_API_KEY"
97111

98112
jq --arg project_id "$projectId" \
113+
--arg profile "$profile" \
99114
--arg ops_genie_api_key "$opsGenieApiKey" \
100-
'.ProjectId?|=$project_id | .ApiKey?|=$ops_genie_api_key' \
115+
'.ProjectId?|=$project_id | .Profile?|=$profile | .ApiKey?|=$ops_genie_api_key' \
101116
"$(dirname "$0")/inputs_5_create.template.json" >"inputs/inputs_5_create.json"
102117

103118
jq --arg project_id "$projectId" \
119+
--arg profile "$profile" \
104120
--arg ops_genie_api_key "$opsGenieApiKey" \
105-
'.ProjectId?|=$project_id | .ApiKey?|=$ops_genie_api_key' \
121+
'.ProjectId?|=$project_id | .Profile?|=$profile | .ApiKey?|=$ops_genie_api_key' \
106122
"$(dirname "$0")/inputs_5_update.template.json" >"inputs/inputs_5_update.json"
107123

108124
#MICROSOFT_TEAMS
@@ -111,13 +127,15 @@ microsoftTeamsCreateWebHook="$MICROSOFT_TEAMS_WEBHOOK_CREATE_URL"
111127
microsoftTeamsUpdateWebHook="$MICROSOFT_TEAMS_WEBHOOK_UPDATE_URL"
112128

113129
jq --arg project_id "$projectId" \
130+
--arg profile "$profile" \
114131
--arg microsoft_teams_create_web_hook "$microsoftTeamsCreateWebHook" \
115-
'.ProjectId?|=$project_id | .MicrosoftTeamsWebhookUrl?|=$microsoft_teams_create_web_hook' \
132+
'.ProjectId?|=$project_id | .Profile?|=$profile | .MicrosoftTeamsWebhookUrl?|=$microsoft_teams_create_web_hook' \
116133
"$(dirname "$0")/inputs_6_create.template.json" >"inputs/inputs_6_create.json"
117134

118135
jq --arg project_id "$projectId" \
136+
--arg profile "$profile" \
119137
--arg microsoft_teams_update_web_hook "$microsoftTeamsUpdateWebHook" \
120-
'.ProjectId?|=$project_id | .MicrosoftTeamsWebhookUrl?|=$microsoft_teams_update_web_hook' \
138+
'.ProjectId?|=$project_id | .Profile?|=$profile | .MicrosoftTeamsWebhookUrl?|=$microsoft_teams_update_web_hook' \
121139
"$(dirname "$0")/inputs_6_update.template.json" >"inputs/inputs_6_update.json"
122140

123141
cd ..
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
# cfn-test-delete-inputs.sh
3+
#
4+
# This tool deletes the mongodb resources used for `cfn test` as inputs.
5+
#
6+
7+
set -o errexit
8+
set -o nounset
9+
set -o pipefail
10+
11+
function usage {
12+
echo "usage:$0 "
13+
}
14+
15+
projectId=$(jq -r '.ProjectId' ./inputs/inputs_1_create.json)
16+
17+
#delete project
18+
if atlas projects delete "$projectId" --force; then
19+
echo "$projectId project deletion OK"
20+
else
21+
(echo "Failed cleaning project:$projectId" && exit 1)
22+
fi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
# This tool generates the resources and json files in the inputs/ for `cfn test`.
4+
set -o errexit
5+
set -o nounset
6+
set -o pipefail
7+
8+
projectName="cfn-test-bot-$(date +%s)-$RANDOM"
9+
10+
# create project
11+
projectId=$(atlas projects create "${projectName}" --output=json | jq -r '.id')
12+
13+
echo "projectId: $projectId"
14+
echo "projectName: $projectName"
15+
16+
./test/cfn-test-create-inputs.sh "$projectName"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
# This tool deletes the mongodb resources used for `cfn test` as inputs.
4+
set -o errexit
5+
set -o nounset
6+
set -o pipefail
7+
8+
./test/cfn-test-delete-inputs.sh

0 commit comments

Comments
 (0)