Skip to content

Commit

Permalink
put it all together
Browse files Browse the repository at this point in the history
  • Loading branch information
vallard committed Jul 25, 2022
1 parent 1500b28 commit 18ebcc5
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 10 deletions.
23 changes: 23 additions & 0 deletions 02/terragrunt/live/stage-mon/eks/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include "root" {
path = find_in_parent_folders()
}

terraform {
source = "../../../modules//eks"
extra_arguments "common_vars" {
commands = get_terraform_commands_that_need_vars()
required_var_files = ["${get_parent_terragrunt_dir()}/common.tfvars"]
}
}

dependency "vpc" {
config_path = "../vpc"
}

inputs = {
public_subnets = dependency.vpc.outputs.vpc.public_subnets
k8s_version = 1.21
min_nodes = 1
desired_nodes = 3
max_nodes = 6
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ terraform {
}

dependency "vpc" {
config_path = "../../../live/stage//vpc"
config_path = "..//vpc"
}

dependency "eks" {
config_path = "../../../live/stage//eks"
config_path = "..//eks"
}

inputs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ remote_state {
}
config = {
bucket = "k8sclass-tf-state"
key = "stage/${path_relative_to_include()}/terraform.tfstate"
key = "stage-mon/${path_relative_to_include()}/terraform.tfstate"
region = "us-west-2"
encrypt = true
}
Expand Down
17 changes: 17 additions & 0 deletions 02/terragrunt/live/stage-mon/vpc/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include "root" {
path = find_in_parent_folders()
}

terraform {
source = "../../../modules//vpc"
extra_arguments "common_vars" {
commands = get_terraform_commands_that_need_vars()
required_var_files = ["${get_parent_terragrunt_dir()}/common.tfvars"]
}
}

inputs = {
cidr = "10.0.0.0/16"
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ In this segment we'll go over some Kubernetes primitives. We move fast, show wh

* [README](m05/README.md)

### M06 - CloudWatch Alarms

* [README](m06/README.md)

### M07 - FEK Stack

* [README](m07-fek/README.md)

### M08 - Application Logging

* [README](m08-app-logging/README.md)




Expand Down
Binary file modified app-api/app/__pycache__/main.cpython-39.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions app-api/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@

# END PROMETHEUS (part 5)


# Fluent (part 8)
from app.lib.app_logging import setup_logging

setup_logging("api")
import logging

logger = logging.getLogger("api")
logger.info("HELLO LOGGING!")
# End fluent (part 8)

origins = [
"http://localhost",
"http://localhost:3000",
Expand Down
Binary file modified app-api/app/routers/__pycache__/auth.cpython-39.pyc
Binary file not shown.
Binary file modified app-api/app/routers/__pycache__/user.cpython-39.pyc
Binary file not shown.
19 changes: 14 additions & 5 deletions app-api/app/routers/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import os
import json
from re import I
from webbrowser import get
from fastapi import APIRouter, Depends, HTTPException
from fastapi.security import OAuth2PasswordRequestForm
from app.database import get_db
Expand All @@ -20,7 +16,6 @@
import requests

router = APIRouter(tags=["auth"])

# PROMETHEUS (part 5)
from prometheus_client import Counter

Expand All @@ -31,6 +26,11 @@
# END PROMETHEUS (part 5)


# Fluent (part 8)
logger = logging.getLogger("api.auth")
# END Fluent (part 8)


@router.post("/auth/signup", response_model=schemas.users.User, status_code=201) # 1
def create_user_signup(
*,
Expand All @@ -51,6 +51,7 @@ def create_user_signup(
db.commit()
db.refresh(user)
sc = SlackClient()
logger.info(f"New User has signed up: {user.email}")
sc.post_message(f"New Customer signed up: {user.email}")
return user

Expand All @@ -72,11 +73,19 @@ def login(
# PROMETHEUS (part 5)
FAILED_LOGIN_DETAILS.inc()
# END PROMETHEUS (part 5)
# Fluent (part 8)
logger.warning(f"Failed login attempt: %s", {form_data.username})
# END Fluent (part 8)

raise HTTPException(status_code=400, detail="Incorrect username or password")

# PROMETHEUS (part 5)
SUCESSFUL_LOGIN_DETAILS.inc()
# END PROMETHEUS (part 5)

# Fluent (part 8)
logger.info(f"User {user.email} has logged in")
# END Fluent (part 8)
return {
"access_token": create_access_token(sub=user.id), # 4
"token_type": "bearer",
Expand Down
5 changes: 3 additions & 2 deletions app-api/app/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from app.database import get_db
from app.models.users import User
from app.schemas.users import UserCreate, UserOut
#from app.lib.slack import SlackClient

# from app.lib.slack import SlackClient
import app.crud
from sqlalchemy.orm import Session
import logging
Expand All @@ -15,8 +16,8 @@

router = APIRouter(prefix="/user", tags=["user"])


@router.get("", response_model=UserOut)
def get_user(current_user: User = Depends(deps.get_current_user)):
user = current_user
print("Current user: ", user)
return {"user_id": user.id, "email": user.email}
7 changes: 7 additions & 0 deletions app-api/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ services:
- MYSQL_USER=user
- MYSQL_PASSWORD=asdf1234
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

fluentd:
image: fluentd
container_name: fluentd
ports:
- 24224

1 change: 1 addition & 0 deletions app-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ alembic==1.7.6
bcrypt==3.2.0
fastapi==0.73.0
fastapi-utils==0.2.1
fluent-logger==0.10.0
databases[mysql]==0.5.5
passlib==1.7.4
pydantic[email] ~= 1.9.0
Expand Down
6 changes: 6 additions & 0 deletions m08-app-logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Application Logging

One way we can ensure we have a handle on what our application is doing is by having a centralized logging area where all our logs are created.

Since we already have fluent set up, let's log everything in our application and test it out. Then we can filter the logs to only show logs for our application.

0 comments on commit 18ebcc5

Please sign in to comment.