Skip to content

Commit

Permalink
Merge branch 'master' into feature/restore-critical-exp
Browse files Browse the repository at this point in the history
  • Loading branch information
gid-sentry authored Jan 24, 2025
2 parents fb8bd05 + 76731e7 commit 5890136
Show file tree
Hide file tree
Showing 187 changed files with 32,530 additions and 1,483 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/auto-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Run React tests
run: |
npm install
npm test -- --coverage
npm test -- --coverage --reporters=jest-junit
working-directory: ./empower/react
- uses: codecov/codecov-action@v3
with:
Expand All @@ -83,12 +83,18 @@ jobs:
run: |
pip install -U pytest
pip install pytest-codecov
pytest --cov=. --cov-report=xml
pytest --cov=. --cov-report=xml --junitxml=junit.xml -o junit_family=legacy
working-directory: ./empower/flask/src
- uses: codecov/codecov-action@v3
- name: Upload coverage results to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: api
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Get GCP_ env variables from empower-config/.gcloudrc
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mock-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: mock-data.yml
on:
push:
branches: [master, test-me-*]
pull_request:
#pull_request:

jobs:
mock-data:
Expand Down
27 changes: 20 additions & 7 deletions .github/workflows/run_codecov_on_pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: codecov.yml
# Run Codecov on PR open or change
on: pull_request
on:
push:
branches:
- master
pull_request:

jobs:
codecov:
runs-on: ubuntu-20.04
Expand All @@ -16,11 +21,13 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: "18"

- name: Run React tests
# Need to run "npm run build" command for bundle analysis: https://docs.codecov.com/docs/webpack-quick-start
- name: Build React and run tests
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
npm install
npm test -- --coverage
CI=false ./build.sh
npm test -- --coverage --reporters=jest-junit
working-directory: ./empower/react
- uses: codecov/codecov-action@v3
with:
Expand All @@ -32,11 +39,17 @@ jobs:
pip install -U pytest
pip install pytz
pip install pytest-codecov
pytest --cov=. --cov-report=xml
pytest --cov=. --cov-report=xml --junitxml=junit.xml -o junit_family=legacy
working-directory: ./empower/flask/src
- uses: codecov/codecov-action@v3
- name: Upload coverage results to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: api
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

- run: echo "Job status is ${{ job.status }}."
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
# dependencies
/node_modules
react/node_modules
next/.next
next/node_modules
express/node_modules
/.pnp
.pnp.js
.vercel

# testing
/coverage

# production
/build
react/build
next/dist


# misc
.idea
Expand All @@ -29,6 +34,7 @@ venv
npm-debug.log*
yarn-debug.log*
yarn-error.log*
next/config-overrides.js

notes.txt
flask/.virtualenv
Expand Down Expand Up @@ -85,6 +91,8 @@ env-config/*
**/local.env
tda/env

next/.env.sentry-build-plugin

# .NET
aspnetcore/bin
aspnetcore/obj
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,21 @@ The [user feedback widget](https://docs.sentry.io/platforms/javascript/user-feed

# Local Setup / Development

> [!WARNING]
> Don't simply use `npm run` etc directly, please use the build system (`deploy.sh`) that's documented in detail below. It's not meant to be run directly.
## Setup

1. Permit your IP address in CloudSQL:
1. Go to https://console.cloud.google.com/sql/instances
2. You will see 1 instance, under Actions column click "..." -> Edit
3. Expand "Connections", under Authorized Networks click "ADD NETWORK"
4. Google "my IP address", add it.
2. Copy `local.env` from [empower-config](https://github.com/sentry-demos/empower-config) into `env-config` directory of your local repo, or, if you don't have access to it, follow `env-config/example.env`.
3. The `REACT_APP_FLASK_BACKEND` in `env-config/local.env` points to the backend instance deployed to AppEngine, the same one used by the cloud-hosted React web app. Flask is the default backend. If you expect to run other backend types, add values for those in `env-config` in your `local.env` file as well (i.e. `REACT_APP_EXPRESS_BACKEND`).
4. Confirm [Homebrew](https://brew.sh/) is installed with `brew -v`. If not, install using `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`.
5. Confirm PostgreSQL is installed with `Postgres -V`. If not, install using `brew install postgresql`.
6. As the application is compatible with specific versions of `node` and `npm`, install the following to be able to set the specific versions required (below describes how to achieve it using `n` package, but alternatively you can use `nvm`):
1. Copy `local.env` from [empower-config](https://github.com/sentry-demos/empower-config) into `env-config` directory of your local repo, or, if you don't have access to it, follow `env-config/example.env`.
2. The `REACT_APP_FLASK_BACKEND` in `env-config/local.env` points to the backend instance deployed to AppEngine, the same one used by the cloud-hosted React web app. Flask is the default backend. If you expect to run other backend types, add values for those in `env-config` in your `local.env` file as well (i.e. `REACT_APP_EXPRESS_BACKEND`).
3. Confirm [Homebrew](https://brew.sh/) is installed with `brew -v`. If not, install using `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`.
4. Confirm PostgreSQL is installed with `Postgres -V`. If not, install using `brew install postgresql`.
5. As the application is compatible with specific versions of `node` and `npm`, install the following to be able to set the specific versions required (below describes how to achieve it using `n` package, but you can use `nvm`):
1. Install compatible `npm` version with `npm install -g [email protected]`. NOTE: may need to use `sudo` with command.
2. Install `n` to update `node` version with `npm install -g n`.
3. Set the specific `node` version with `n XX.XX.XX`. NOTE: may need to use `sudo` with command.
7. Configure the `CLI` using [this](https://docs.sentry.io/product/cli/configuration/) document.
8. Install [gcloud](https://cloud.google.com/sdk/docs/install) in the root of your project to be able to deploy to staging. Initialize the gcloud CLI by running `gcloud init`. When prompted, choose the project `sales-engineering-sf`.
6. Configure the `CLI` using [this](https://docs.sentry.io/product/cli/configuration/) document.
7. Install [gcloud](https://cloud.google.com/sdk/docs/install) in the root of your project to be able to deploy to staging. Initialize the gcloud CLI by running `gcloud init`. When prompted, choose the project `sales-engineering-sf`.

Following sub-projects might not work with `deploy.sh` at this moment. Consult their README's for how to run and deploy them (and feel free to submit a PR that fixes it):

Expand Down Expand Up @@ -180,3 +178,11 @@ gcloud config list, to display current account
```

`gcloud app deploy` does not support `--update-env-vars RELEASE=$RELEASE` like `gcloud run deploy` does with Cloud Run

## Local Run with AI Suggestions

1. Add your OPENAI_API_KEY= to local.env
2. Run next and flask (./deploy.sh --env=local next flask)
3. Get suggestion button should show automatically

On main page load, next will check with flask if it has the OPEN_API_KEY and conditionally show the get suggestion input.
4 changes: 2 additions & 2 deletions auto-deploy.exclude
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ laravel
tda
postgres
crons-python
ruby-on-rails
# ^ see https://github.com/sentry-demos/empower/issues/439
next
# ^ uses Vercel automation
16 changes: 15 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ fixes:
- "empower/::"

coverage:
precision: 2
round: down
status:
project:
default:
Expand Down Expand Up @@ -61,4 +63,16 @@ component_management:
name: product_component
paths:
- react/src/components/**


# Vlad said--
# i just checked the file. the test_utils.py is purely a test file,
# just assertions and tests, so in theory it shouldn't be counted
# towards the overall coverage of the repo or "production code".
# i'm not sure why some tools include the tests as part of the coverage report,
# but it can be mitigated by excluding them via codecov.yaml or --source setting
# in the pytest, but the issue is that the test directory is also under the
# /src/ so it looks like it is instrumenting the code for all the python files
# in that location. this is not a big deal, but in case anyone asks this is why
# it is showing up.
ignore:
- "flask/src/test/"
4 changes: 2 additions & 2 deletions crons-python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sentry-sdk==1.23.0
python-dotenv==1.0.0
sentry-sdk==2.4.0
python-dotenv==1.0.0
9 changes: 7 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ for proj in $projects; do # bash only
# Point to local backend http://host:port instead of cloud endpoints for all _built_ BE projects
# If no backend projects specified in CLI args, keep using cloud (production or staging) BE endpoints.
for be_proj in $be_projects; do
backend_var=$(var_name.sh %s_APP_%s_BACKEND $proj $be_proj)
if [ "$proj" == "next" ]; then
# Next env variables need to start with NEXT_PUBLIC_*
backend_var=$(var_name.sh NEXT_PUBLIC_%s_BACKEND $be_proj)
else
backend_var=$(var_name.sh %s_APP_%s_BACKEND $proj $be_proj)
fi
. get_proj_var.sh "%s_LOCAL_PORT" $be_proj # sets $local_port
echo "" >> .env # in case no newline
backend_local="http://localhost:$local_port"
Expand All @@ -166,7 +171,7 @@ for proj in $projects; do # bash only
./build.sh

if [[ "$fe_projects" = *"$proj "* ]]; then # project is frontend
if [[ "$proj" == "react" ]]; then
if [[ "$proj" == "react" || "$proj" == "next" ]]; then
upload_sourcemaps="false" # using webpack plugin
else
upload_sourcemaps="true"
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ services:
ports: [9989:9989]
volumes: [./mini-relay/data:/data:rw]
postgres:
image: 'postgres:alpine'
image: "postgres:alpine"
environment:
- POSTGRES_PASSWORD=postgres
init: true
ports: [5432:5432]
volumes:
- ./postgres/data/empowerplant.sql:/docker-entrypoint-initdb.d/empowerplant.sql:ro
8 changes: 7 additions & 1 deletion env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ if ! [[ $proj =~ ^(crons|tda)- ]]; then
export RELEASE="$release"
fi
fi
if [ "$proj" == "react" ]; then
if [[ "$proj" == "react" ]]; then
echo "REACT_APP_RELEASE=$RELEASE" >> .env
fi


if [[ "$proj" == "next" ]]; then
echo "NEXT_PUBLIC_RELEASE=$RELEASE" >> .env
fi


validate_dotenv.sh

if [ "$2" == "" ]; then
Expand Down
12 changes: 10 additions & 2 deletions flask/app.yaml.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
service: <SERVICE>
service: <SERVICE>
runtime: python312
entrypoint: gunicorn -b :$PORT -w 2 src.main:app
entrypoint: gunicorn -b :$PORT -w 2 --timeout 60 src.main:app

env_variables:
REDISHOST: 10.251.35.179
REDISPORT: 6379

vpc_access_connector:
name: projects/sales-engineering-sf/locations/us-central1/connectors/empower-plant-connector

7 changes: 6 additions & 1 deletion flask/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ pg8000==1.16.6
psycopg2-binary==2.9.9
python-dotenv==0.12.0
pytz==2020.4
sentry-sdk==1.40.0
sentry-sdk==2.17.0
sqlalchemy==1.4.49
redis==5.0.1
Werkzeug==3.0.3
flask_caching==2.3.0
openai==1.52.2
tiktoken==0.8.0
8 changes: 8 additions & 0 deletions flask/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ pip3 install -r requirements.txt

function cleanup {
stop.sh python3 $LOCAL_PORT
stop.sh gcloud 6379
}
trap cleanup EXIT

# needed for caches since GCP redis doesn't have public IP
ACTIVE_ACCOUNT=$(gcloud auth list --format="value(account)" --filter="status:ACTIVE")
if [ -z "$ACTIVE_ACCOUNT" ]; then
gcloud auth login
fi
gcloud compute ssh redis-relay --zone=us-central1-a -- -N -L 6379:10.251.35.179:6379 &

flask run --port $LOCAL_PORT
2 changes: 1 addition & 1 deletion flask/src/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_products_join():
try:
with sentry_sdk.start_span(op="get_products_join", description="db.connect"):
connection = db.connect()

with sentry_sdk.start_span(op="get_products_join", description="db.query") as span:
products = connection.execute(
"SELECT * FROM products"
Expand Down
Loading

0 comments on commit 5890136

Please sign in to comment.