Skip to content

Commit

Permalink
Change GHGC monitoring visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
amarouane-ABDELHAK committed May 31, 2024
0 parents commit 2c8878d
Show file tree
Hide file tree
Showing 27 changed files with 1,583 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
STAGE=example
VPC_ID=vpc-abcde12345abcde12
PERMISSIONS_BOUNDARY_ARN=
GITHUB_ALLOWED_ORGS
64 changes: 64 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Deploy

permissions:
id-token: write
contents: read

on:
workflow_dispatch:
inputs:
environment:
description: Environment to deploy to
type: environment
required: true
aws-region:
description: AWS region to deploy to
type: string
required: false
default: us-west-2


workflow_call:
inputs:
environment:
type: string
required: true
aws-region:
type: string
required: false
default: us-west-2

jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}

env:
AWS_REGION: ${{ inputs.aws-region || vars.AWS_REGION }}
VPC_ID: ${{ vars.VPC_ID }}
STAGE: ${{ vars.STAGE }}
PERMISSIONS_BOUNDARY_ARN: ${{ vars.PERMISSIONS_BOUNDARY_ARN }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"

- run: pip install -r requirements.txt

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ vars.DEPLOYMENT_ROLE_ARN }}
role-session-name: ${{ github.actor }}
aws-region: ${{ env.AWS_REGION }}

- name: Deploy
run: |
npx cdk deploy GHGC-grafana-${{ vars.STAGE }} \
--require-approval never
33 changes: 33 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Commit Checks
on: push
jobs:
define-environment:
name: Set ✨ environment ✨ based on the branch 🌳
runs-on: ubuntu-latest
steps:
- name: Set the environment
id: define_environment
run: |
if [ "${{ github.ref_name }}" == "main" ]; then
echo "env_name=staging" >> $GITHUB_OUTPUT
elif [ "${{ github.ref_name }}" == "dev" ]; then
echo "env_name=development" >> $GITHUB_OUTPUT
elif [ "${{ github.ref_name }}" == "production" ]; then
echo "env_name=production" >> $GITHUB_OUTPUT
else
echo "No environment associated with ${GITHUB_REF##*/} branch"
fi
- name: Print the environment
if: ${{ steps.define_environment.outputs.env_name }}
run: echo "The environment is ${{ steps.define_environment.outputs.env_name }}"
outputs:
env_name: ${{ steps.define_environment.outputs.env_name }}

deploy:
needs: define-environment
uses: "./.github/workflows/deploy.yaml"
if : ${{ needs.define-environment.outputs.env_name }}
with:
environment: ${{ needs.define-environment.outputs.env_name }}
aws-region: "us-west-2"
secrets: inherit
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*.swp
package-lock.json
.pytest_cache
*.egg-info

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Environments
.env*
!.env.example
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# CDK Context & Staging files
.cdk.staging/
cdk.out/
cdk.context.json
.idea
.vscode
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# GHGC Monitoring System

## Summary

The purpose of this system is to manage the state of all applications within GHGC, by consolidating and tracking performance metrics and logs into actionable data and alerts.

## Design

All significant design decisions are captured in Architectural Decision Records (ADR). Currently, the following ADRs exist:

* [#1 Observability Platform Selection](./docs/adr/001-observability-platform-selection.md)
* [#2 Testing Strategy](./docs/adr/002-testing-strategy.md)

## Deployment

Deployment of monitoring services is managed via [AWS CDK](https://aws.amazon.com/cdk/).

### dotenv

Configuration is provided via environment variables. These environment variables can be provided to the application in a number of ways:

- set on the environment manually prior to running CDK commands (e.g. `export STAGE=my-stage`)
- provided inline when running CDK (e.g. `STAGE=my-stage cdk diffnpx `)
- specified within a dotenv file. When our settings class initializes, it will attempt to load a dotenv file (located at `.env` by default, configurable via the `DOTENV` environment variable). Note that some environment variables such as `AWS_PROFILE` are best provided via methods other than a dotenv file as CDK will make available required related environment variables (e.g. `CDK_DEFAULT_ACCOUNT`, `CDK_DEFAULT_REGION`) before initializing our settings class

An example of the environment variables used by our settings class can be found in `.env.example`.

### Useful commands

- `cdk ls` list all stacks in the app
- `cdk synth` emits the synthesized CloudFormation template
- `cdk deploy` deploy this stack to your default AWS account/region
- `cdk diff` compare deployed stack with current state
- `cdk docs` open CDK documentation
51 changes: 51 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"app": "python3 -m stacks",
"watch": {
"include": ["**"],
"exclude": [
"README.md",
"cdk*.json",
"requirements*.txt",
"source.bat",
"**/*.pyc",
"**/__pycache__",
"**/*.tmp",
"tests"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true
}
}
145 changes: 145 additions & 0 deletions docs/adr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
**.DS_Store

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.env.*
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Github Actions
act/.secrets

#DS Store
.DS_Store

#CDK
cdk.out
cdk.context.json


# Local files
volumes
Loading

0 comments on commit 2c8878d

Please sign in to comment.