Difference between revisions of "Automation Analytics"
(→compose backend and local frontend) |
|||
Line 161: | Line 161: | ||
* commment out the frontend in local.yml | * commment out the frontend in local.yml | ||
− | * after spinning up the stack with <pre>make up</pre> use docker exec to edit the proxy container's /etc/hosts and set the frontend IP to the container's gateway | + | * after spinning up the stack with <pre>make up</pre> use <pre>docker exec -it toweranalyticsbackend_insights_proxy_1 /bin/bash</pre> to edit the proxy container's /etc/hosts and set the frontend IP to the container's gateway |
* spin up the frontend with <pre>npm run start:container</pre> so that the service binds to 0.0.0.0 instead of 127.0.0.1 | * spin up the frontend with <pre>npm run start:container</pre> so that the service binds to 0.0.0.0 instead of 127.0.0.1 | ||
Revision as of 07:09, 9 September 2020
Contents
- 1 frontend dev setup
- 2 fullstack dev setup
- 3 local insights.chrome
- 4 compose backend and local frontend
- 5 FAQ
- 5.1 How do I enable calls to the browser console in the frontend code?
- 5.2 How can I connect to the local backend postgres?
- 5.3 How can I see what active queries are running in postgres?
- 5.4 How do I kill a query in postgres?
- 5.5 How do I run a single frontend test file?
- 5.6 How do I fix inotify for vscode?
- 5.7 What should I do if the UI spins on a white page and never proceeds?
- 5.8 How is a new nav item added to the leftnav?
- 6 troubleshooting
frontend dev setup
- use nvm to install and use node 10.15
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.bashrc
nvm install 10.15
nvm use 10.15
- clone the various repos
mkdir -p ~/workspace/github/RedHatInsights
git clone https://github.com/RedHatInsights/tower-analytics-frontend ~/workspace/github/RedHatInsights/tower-analytics-frontend
git clone https://github.com/RedHatInsights/insights-proxy ~/workspace/github/RedHatInsights/insights-proxy
- fix the frontend spandx config
diff --git a/config/spandx.config.js b/config/spandx.config.js
index c40e554..611bc40 100644
--- a/config/spandx.config.js
+++ b/config/spandx.config.js
@@ -9,6 +9,5 @@ module.exports = {
'/apps/automation-analytics': { host: `https://${localhost}:8002` },
'/ansible/automation-analytics': { host: `https://${localhost}:8002` },
'/beta/ansible/automation-analytics': { host: `https://${localhost}:8002` },
- '/beta/config': { host: `http://${localhost}:8889` }
}
};
- set the hosts file
cd ~/workspace/github/RedHatInsights/insights-proxy
sudo ./scripts/patch-etc-hosts.sh
- start the proxy [requires docker or podman-docker]
cd ~/workspace/github/RedHatInsights/insights-proxy
SPANDX_CONFIG=~/workspace/github/RedHatInsights/tower-analytics-frontend/config/spandx.config.js ./scripts/run.sh
- install the npm packages
cd ~/workspace/github/RedHatInsights/tower-analytics-frontend
npm install
DEBUG='express:*' npm start
- open the "prod" url
https://prod.foo.redhat.com:1337/beta/ansible/automation-analytics/clusters
fullstack dev setup
The backend stack is in a private repo https://github.com/RedHatInsights/tower-analytics-backend
The stack is heavily reliant on docker-compose to spin up and podman-compose will fail if used.
- fix the spandx config
[jtanner@corsair tower-analytics-frontend]$ git diff config/local-api.spandx.config.js
diff --git a/config/local-api.spandx.config.js b/config/local-api.spandx.config.js
index 0645a59..4529b37 100644
--- a/config/local-api.spandx.config.js
+++ b/config/local-api.spandx.config.js
@@ -11,7 +11,6 @@ module.exports = {
'/apps/automation-analytics': { host: `https://${localhost}:8002` },
'/ansible/automation-analytics': { host: `https://${localhost}:8002` },
'/beta/ansible/automation-analytics': { host: `https://${localhost}:8002` },
- '/beta/config': { host: `http://${localhost}:8889` },
'/api/tower-analytics': { host: `http://${localhost}:8000` }
}
};
- run the insights proxy
cd ~/workspace/github/RedHatInsights/insights-proxy
SPANDX_CONFIG=~/workspace/github/RedHatInsights/tower-analytics-frontend/config/local-api.spandx.config.js ./scripts/run.sh
- run the backend
cd ~/workspace/github/RedHatInsights/tower-analytics-backend
docker-compose -f local_ui_dev.yml kill
docker-compose -f local_ui_dev.yml down
docker image prune -a
sudo rm -rf integration_test/__pycache__
docker-compose -f local_ui_dev.yml up
- migrate the database and make some fake data
cd ~/workspace/github/RedHatInsights/tower-analytics-backend
make init
- fix the proxy container's hosts file
cd ~/workspace/github/RedHatInsights/tower-analytics-backend
docker-compose -f local.yml ps
docker exec -it <proxy-container-name> /bin/bash
echo "127.0.0.1 prod.foo.redhat.com" >> /etc/hosts
- run the frontend
nvm use 10.15
cd ~/workspace/github/RedHatInsights/tower-analytics-frontend
npm install
DEBUG='express:*' npm start
- open the urls ...
- https://ci.foo.redhat.com:1337/ -> requires vpn
- https://qa.foo.redhat.com:1337/ -> requires vpn
- https://stage.foo.redhat.com:1337/ -> requires vpn
- https://prod.foo.redhat.com:1337/beta/ansible/automation-analytics/clusters
local insights.chrome
# checkout and build
git clone https://github.com/RedHatInsights/insights-chrome
cd insights-chrome
npm install
npm run build
# symlink apps/chrome to build
mkdir apps
ln -s ../build apps/chrome
# start httpd
npm install http-server
node_modules/http-server/bin/http-server -a 0.0.0.0 -p 8080
Add the following entry to the spandx config ...
'/apps/chrome': { host: `http://${localhost}:8080` }
- NOTE
The insights-proxy has a builtin flag to do something similar to this ... https://github.com/RedHatInsights/insights-proxy/blob/a3a0b4bbf3ab4348ba893416dd2d85113cea5516/spandx.config.js#L138
compose backend and local frontend
- commment out the frontend in local.yml
- after spinning up the stack with
make up
usedocker exec -it toweranalyticsbackend_insights_proxy_1 /bin/bash
to edit the proxy container's /etc/hosts and set the frontend IP to the container's gateway - spin up the frontend with
npm run start:container
so that the service binds to 0.0.0.0 instead of 127.0.0.1
FAQ
How do I enable calls to the browser console in the frontend code?
eslint disabes console.log entries in the code, and needs configuration to allow it ...
diff --git a/.eslintrc.yml b/.eslintrc.yml
index c5d7d33..61835e5 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -72,6 +72,7 @@ rules:
new-cap: 2
no-bitwise: 2
no-caller: 2
+ no-console: "off"
no-mixed-spaces-and-tabs: 2
no-multiple-empty-lines:
- error
/*eslint-disable */at the top of the individual files.
How can I connect to the local backend postgres?
docker-compose -f local.yml exec postgres /bin/sh
su - postgres
psql
How can I see what active queries are running in postgres?
SELECT * FROM pg_stat_activity WHERE state = 'active';
How do I kill a query in postgres?
SELECT pg_terminate_backend(<pid>);
How do I run a single frontend test file?
node_modules/jest/bin/jest.js --coverage=false src/Charts/PieChart.test.js
How do I fix inotify for vscode?
[jtanner@jtx1 tower-analytics-frontend]$ cat /etc/sysctl.d/01-watches.conf
fs.inotify.max_user_watches = 524200
[jtanner@jtx1 tower-analytics-frontend]$ sudo systemctl restart systemd-sysctl.service
[jtanner@jtx1 tower-analytics-frontend]$ cat /proc/sys/fs/inotify/max_user_watches
524200
What should I do if the UI spins on a white page and never proceeds?
Check the network tab in chrome dev utils and look for any red entries. Double click on those and accept the certs.
https://github.com/RedHatInsights/cloud-services-config serves a route for "config/main.yml". This file contains a yaml'ized structure of the leftnav ...
automation-analytics:
title: Automation Analytics
api:
versions:
- v1
deployment_repo: https://github.com/RedHatInsights/tower-analytics-frontend-build.git
frontend:
paths:
- /ansible
- /ansible/automation-analytics
sub_apps:
- id: clusters
title: Clusters
default: true
- id: organization-statistics
title: Organization Statistics
- id: automation-calculator
title: Automation calculator
- id: notifications
title: Notifications
- id: stuff
title: My STUFF
source_repo: https://github.com/RedHatInsights/tower-analytics-frontend
troubleshooting
- podman permission or OCI errors ...
sudo rm -rf ~/.local/share/containers/