forked from manifoldmarkets/manifold
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Twitch metrics (manifoldmarkets#1366)
* Manifold user data now cached within bot rather than using update hooks. This reduces CPU overhead when many remote documents are updated simultaneously. * Changed yarn command for local web server to "dev". Added local debugger support for NodeJS. * Moved timing utilities to utils.ts. * Corrected new contract ante. * Bot Firestore user data is now cached in the bot. This reduces connection latency for the dock and overlay, and reduces the delay when placing a bet. * Only users declared as "admin: true" in the bot Firebase can use the group controls UI in the dock. * Updated engine.io to fix security issue. * Hackathon project: dashboard metrics prototype. * Fixed Twitch bot building and deployment using common manifold files. Converted Twitch sub-repository to CJS. Imports now have consistent and unambiguous resolutions due to using import aliases. * Server-side metrics working and connected to Firestore. * Metrics UI working with backend to serve latest real data. Improved icons for percentage difference to previous day when handing edge cases. * Improved metrics behaviour with sparse data. Fixed styling issue with dock "Create new question" popup. * Added colors to logging to make errors and warnings clearer. * Removed legacy windows scripts. Made unix scripts the default. * Fixed auto-refresh not working for dock and overlay after migrating server build to esbuild. * Normalized manifold envs. Removed broken "use latest git" option from deploy script. Fixed manifold logo overflowing overlay page. * Added Twitch bot debug configuration to VSCode config. * Attempt at fixing deployment script when running through Git Bash on Windows. Also updated README with latest instructions for debugging, building and deploying as well as viewing the logs and metrics of the deployed bot. * Fixed bug with colors being sent to gcloud logger.
- Loading branch information
1 parent
8d345ab
commit f3b44ab
Showing
23 changed files
with
720 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type MetricDay = { | ||
uniqueUserFeatures: number; // Users that have featured a market today | ||
featuredQuestions: number; // Total number of features questions today | ||
newBots: number; // Number of users that have added the bot to their channel for the first time | ||
twitchLinks: number; // Number of users that have linked their Manifold account to Twitch | ||
commandsUsed: number; // Times a Twitch bot command has been used | ||
activeUsers: number; // Users that have used a command today | ||
}; | ||
|
||
export function getCurrentEpochDay() { | ||
return (Date.now() / 8.64e7) >> 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cd ../.. | ||
start=`date +%s` | ||
docker build -f twitch-bot/Dockerfile -t mb . | ||
end=`date +%s` | ||
echo "=================================" | ||
echo "= Build completed in $((end-start)) seconds =" | ||
echo "=================================" | ||
sleep 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/bin/sh | ||
|
||
# This script is a quick way to deploy a docker image to the remote GCloud server. | ||
# It works by building the default repository Docker image first, extracting the build | ||
# artifacts, zipping them up along with a mini Dockerfile, copying them to the server, | ||
# and finally building the runtime image there. | ||
|
||
# ============ | ||
# CONFIG | ||
# ============ | ||
ROUTE_TO_SCRIPTS_DIR=. | ||
PROJECT=mantic-markets | ||
|
||
DEV_INSTANCE=dev-twitch-bot | ||
DEV_BUILD_DIR=build/dev | ||
DEV_ZONE=europe-west2-c | ||
|
||
PROD_INSTANCE=twitch-bot | ||
PROD_BUILD_DIR=build/prod | ||
PROD_ZONE=us-central1-a | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
# ============ | ||
# SCRIPT | ||
# ============ | ||
error () { | ||
echo An error occuring during the deployment process. | ||
exit 1 | ||
} | ||
|
||
pushd () { | ||
command pushd "$@" > /dev/null | ||
} | ||
|
||
popd () { | ||
command popd "$@" > /dev/null | ||
} | ||
|
||
gcloud() { | ||
command node "$SCRIPT_DIR/gcloud.mjs" "$@" | ||
} | ||
|
||
build() { | ||
pushd ../.. | ||
echo Building code... | ||
docker rmi mb | ||
docker build -f twitch-bot/Dockerfile -t mb . || error | ||
popd | ||
|
||
pushd $BUILD_DIR | ||
echo Preparing files... | ||
CONTAINER_ID=$(docker create mb) | ||
docker cp $CONTAINER_ID:deploy/. out/ | ||
docker rm $CONTAINER_ID | ||
popd | ||
|
||
cp $BUILD_DIR/.env $BUILD_DIR/out/ | ||
cp Dockerfile $BUILD_DIR/out/ | ||
|
||
pushd $BUILD_DIR | ||
echo Copying files to server... | ||
tar -czf out.tar.gz out | ||
rm -r out | ||
gcloud compute scp --recurse --zone $ZONE out.tar.gz Phil@$INSTANCE_NAME:. || error | ||
rm out.tar.gz | ||
|
||
COMMAND="tar -zxf out.tar.gz out && \ | ||
rm out.tar.gz && \ | ||
echo Rebuilding docker image... && \ | ||
docker build -t bot out && \ | ||
echo Launching docker image... && \ | ||
docker run -d --env-file=out/.env --restart on-failure --network=host bot && \ | ||
echo Cleaning up... && \ | ||
rm -r out && \ | ||
docker system prune -a -f" | ||
|
||
gcloud compute ssh --zone $ZONE $INSTANCE_NAME --command "$COMMAND" || error | ||
|
||
exit 0 | ||
} | ||
|
||
init_dev () { | ||
echo Deploying to DEV | ||
INSTANCE_NAME=$DEV_INSTANCE | ||
BUILD_DIR=$DEV_BUILD_DIR | ||
ZONE=$DEV_ZONE | ||
build | ||
} | ||
|
||
init_prod () { | ||
echo Deploying to PROD | ||
INSTANCE_NAME=$PROD_INSTANCE | ||
BUILD_DIR=$PROD_BUILD_DIR | ||
ZONE=$PROD_ZONE | ||
build | ||
} | ||
|
||
cd "$SCRIPT_DIR" | ||
read -p "Which server do you want to deploy to [DEV/prod]? " de | ||
case $de in | ||
prod|p ) init_prod; break;; | ||
dev|d|"" ) init_dev; break;; | ||
* ) echo "Invalid option entered. Exiting..."; error; break;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { spawnSync } from 'child_process'; | ||
|
||
const gcloudArgs = process.argv.splice(2); | ||
const newArgs = []; | ||
for (let arg of gcloudArgs) { | ||
arg = arg.replaceAll(/[\n\r\t]/g, ''); | ||
if (arg.includes(' ')) { | ||
newArgs.push(`"${arg}"`); | ||
} else { | ||
newArgs.push(arg); | ||
} | ||
} | ||
spawnSync('gcloud', newArgs, { shell: true, stdio: 'inherit' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd .. | ||
docker run -it --env-file=.env -p 9172:9172 mb |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.