Skip to content
Open

Main #31

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
"name": "Cruddur Configuration",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/aws-cli:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-docker",
"ms-python.python",

]
}
}



// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
26 changes: 26 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.8'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
backend-flask:
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
# build:
# context: .
# dockerfile: .devcontainer/Dockerfile

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- ..:/workspaces:cached

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
29 changes: 27 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@

tasks:
- name: aws-cli
env:
AWS_CLI_AUTO_PROMPT: on-partial
init: |
cd /workspace
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
cd $THEIA_WORKSPACE_ROOT
- name: react-js
command: |
cd frontend-react-js
npm i
vscode:
extensions:
- 42Crunch.vscode-openapi
- 42Crunch.vscode-openapi

ports:
- name: frontend
port: 3000
onOpen: open-browser
visibility: public
- name: backend
port: 4567
visibility: public
- name: xray-daemon
port: 2000
visibility: public
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"main"
]
}
35 changes: 35 additions & 0 deletions aws/json/alarm-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"AlarmName": "DailyEstimatedCharges",
"AlarmDescription": "This alarm would be triggered if the daily estimated charges exceeds 1$",
"ActionsEnabled": true,
"AlarmActions": [
"arn:aws:sns:us-east-1:***REMOVED***:billing-alarm"
],
"EvaluationPeriods": 1,
"DatapointsToAlarm": 1,
"Threshold": 1,
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
"TreatMissingData": "breaching",
"Metrics": [{
"Id": "m1",
"MetricStat": {
"Metric": {
"Namespace": "AWS/Billing",
"MetricName": "EstimatedCharges",
"Dimensions": [{
"Name": "Currency",
"Value": "USD"
}]
},
"Period": 86400,
"Stat": "Maximum"
},
"ReturnData": false
},
{
"Id": "e1",
"Expression": "IF(RATE(m1)>0,RATE(m1)*86400,0)",
"Label": "DailyEstimatedCharges",
"ReturnData": true
}]
}
16 changes: 16 additions & 0 deletions aws/json/budget-notifications-with-subscribers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"Notification": {
"ComparisonOperator": "GREATER_THAN",
"NotificationType": "ACTUAL",
"Threshold": 80,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [
{
"Address": "emmanuelkazadi88@gmail.com",
"SubscriptionType": "EMAIL"
}
]
}
]
31 changes: 31 additions & 0 deletions aws/json/budget.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"BudgetLimit": {
"Amount": "1",
"Unit": "USD"
},
"BudgetName": "Example Tag Budget",
"BudgetType": "COST",
"CostFilters": {
"TagKeyValue": [
"user:Key$value1",
"user:Key$value2"
]
},
"CostTypes": {
"IncludeCredit": true,
"IncludeDiscount": true,
"IncludeOtherSubscription": true,
"IncludeRecurring": true,
"IncludeRefund": true,
"IncludeSubscription": true,
"IncludeSupport": true,
"IncludeTax": true,
"IncludeUpfront": true,
"UseBlended": false
},
"TimePeriod": {
"Start": 1477958399,
"End": 3706473600
},
"TimeUnit": "MONTHLY"
}
15 changes: 15 additions & 0 deletions aws/json/xray.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"SamplingRule": {
"RuleName": "Cruddur",
"ResourceARN": "*",
"Priority": 9000,
"FixedRate": 0.1,
"ReservoirSize": 5,
"ServiceName": "backend-flask",
"ServiceType": "*",
"Host": "*",
"HTTPMethod": "*",
"URLPath": "*",
"Version": 1
}
}
29 changes: 29 additions & 0 deletions backend-flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM python:3.10-slim-buster

# Inside Container
# make a new folder inside container
WORKDIR /backend-flask

# Outside Container -> Inside Container
# this contains the libraries want to install to run the app
COPY requirements.txt requirements.txt

# Inside Container
# Install the python libraries used for the app
RUN pip3 install -r requirements.txt

# Outside Container -> Inside Container
# . means everything in the current directory
# first period . - /backend-flask (outside container)
# second period . /backend-flask (inside container)
COPY . .

# Set Enviroment Variables (Env Vars)
# Inside Container and wil remain set when the container is running
ENV FLASK_ENV=development

EXPOSE ${PORT}

# CMD (Command)
# python3 -m flask run --host=0.0.0.0 --port=4567
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port=4567"]
41 changes: 41 additions & 0 deletions backend-flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,48 @@
from services.create_message import *
from services.show_activity import *

# HoneyComb ---------
from opentelemetry import trace
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

# X-RAY ----------
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware


# HoneyComb ---------
# Initialize tracing and an exporter that can send data to Honeycomb
provider = TracerProvider()
processor = BatchSpanProcessor(OTLPSpanExporter())
provider.add_span_processor(processor)

# X-RAY ----------
xray_url = os.getenv("AWS_XRAY_URL")
xray_recorder.configure(service='backend-flask', dynamic_naming=xray_url)

# Show this in the logs within the backend-flask app (STDOUT)
simple_processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(simple_processor)

trace.set_tracer_provider(provider)
tracer = trace.get_tracer(__name__)

app = Flask(__name__)

# X-RAY ----------
XRayMiddleware(app, xray_recorder)

# HoneyComb ---------
# Initialize automatic instrumentation with Flask
FlaskInstrumentor().instrument_app(app)
RequestsInstrumentor().instrument()


frontend = os.getenv('FRONTEND_URL')
backend = os.getenv('BACKEND_URL')
origins = [frontend, backend]
Expand Down
19 changes: 9 additions & 10 deletions backend-flask/openapi-3.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ paths:
- activities
responses:
'200':
description: Returns an array of activities"
description: Returns an array of activities
content:
application/json:
schema:
Expand All @@ -35,7 +35,7 @@ paths:
example: "#100DaysOfCloud"
responses:
'200':
description: Returns an array of activities"
description: Returns an array of activities
content:
application/json:
schema:
Expand All @@ -44,7 +44,7 @@ paths:
$ref: '#/components/schemas/Activity'
/api/activities:
post:
description: Create a new activitiy eg. Creating a Crud
description: Create a new activity e.g., Creating a Crud
tags:
- activities
requestBody:
Expand All @@ -62,13 +62,12 @@ paths:
type: string
responses:
'200':
description: Returns a recently created activity"
description: Returns a recently created activity
content:
application/json:
schema:
type: object
items:
$ref: '#/components/schemas/Activity'
$ref: '#/components/schemas/Activity'
/api/activities/@{handle}:
get:
description: 'Return a feed of activity for a specific user'
Expand All @@ -83,7 +82,7 @@ paths:
type: string
responses:
'200':
description: Returns an array of activities"
description: Returns an array of activities
content:
application/json:
schema:
Expand All @@ -92,7 +91,7 @@ paths:
$ref: '#/components/schemas/Activity'
/api/message_groups:
get:
description: 'Return a list of two way private conversations for the user'
description: 'Return a list of two-way private conversations for the user'
tags:
- messages
responses:
Expand Down Expand Up @@ -122,7 +121,7 @@ paths:
content:
application/json:
schema:
type: object
type: array
items:
$ref: '#/components/schemas/Message'
/api/messages:
Expand Down Expand Up @@ -238,4 +237,4 @@ components:
example: "Worf"
handle:
type: string
example: "worf"
example: "worf"
10 changes: 9 additions & 1 deletion backend-flask/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
flask
flask-cors
flask-cors

opentelemetry-api
opentelemetry-sdk
opentelemetry-exporter-otlp-proto-http
opentelemetry-instrumentation-flask
opentelemetry-instrumentation-requests

aws-xray-sdk
Loading