From e190c7145e8f03955b305a4a0792ae8cc7a17ab0 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 20 Aug 2024 15:41:14 -0400 Subject: [PATCH 1/3] split: errors into trace and legacy parts --- weave/clear_cache.py | 16 ------------ weave/errors.py | 8 ++---- weave/legacy/clear_cache.py | 1 - weave/legacy/errors.py | 32 ++++++++++++++++++++++++ weave/legacy/ops_primitives/weave_api.py | 2 +- weave/{ => legacy}/trace_legacy.py | 5 ++-- weave/tests/legacy/test_trace.py | 3 ++- 7 files changed, 40 insertions(+), 27 deletions(-) delete mode 100644 weave/clear_cache.py create mode 100644 weave/legacy/errors.py rename weave/{ => legacy}/trace_legacy.py (97%) diff --git a/weave/clear_cache.py b/weave/clear_cache.py deleted file mode 100644 index 2d7b9da1dcd6..000000000000 --- a/weave/clear_cache.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import time - -from weave.legacy import cache - -# TODO: This should be split out into a scripts dir -# Script to run to delete expired caches -if __name__ == "__main__": - print("Starting clear cache job", flush=True) - hour_interval = int(os.getenv("WEAVE_CACHE_CLEAR_INTERVAL", 24)) - print("Clearing expired caches every " + str(hour_interval) + " hours", flush=True) - while True: - curTime = time.strftime("%x, %X", time.localtime()) - print("Clearing cache " + curTime, flush=True) - cache.clear_cache() - time.sleep(60 * 60 * hour_interval) diff --git a/weave/errors.py b/weave/errors.py index 5153972b272b..be70b599141d 100644 --- a/weave/errors.py +++ b/weave/errors.py @@ -1,10 +1,6 @@ from typing import Iterable, Optional -class WeaveUnmergableArtifactsError(Exception): - pass - - class WeaveFingerprintErrorMixin: fingerprint: Optional[Iterable] = None @@ -30,11 +26,11 @@ class WeaveInternalError(WeaveBaseError): pass -class WeaveConfigurationError(WeaveBaseError): +class WeaveSerializeError(WeaveBaseError): pass -class WeaveSerializeError(WeaveBaseError): +class WeaveConfigurationError(WeaveBaseError): pass diff --git a/weave/legacy/clear_cache.py b/weave/legacy/clear_cache.py index 2d7b9da1dcd6..39a6186efef1 100644 --- a/weave/legacy/clear_cache.py +++ b/weave/legacy/clear_cache.py @@ -3,7 +3,6 @@ from weave.legacy import cache -# TODO: This should be split out into a scripts dir # Script to run to delete expired caches if __name__ == "__main__": print("Starting clear cache job", flush=True) diff --git a/weave/legacy/errors.py b/weave/legacy/errors.py new file mode 100644 index 000000000000..f6b5fd477d37 --- /dev/null +++ b/weave/legacy/errors.py @@ -0,0 +1,32 @@ +from typing import Iterable, Optional + + +class WeaveUnmergableArtifactsError(Exception): + pass + + +class WeaveFingerprintErrorMixin: + fingerprint: Optional[Iterable] = None + + +class WeaveBaseError(Exception, WeaveFingerprintErrorMixin): + pass + + +class WeaveBaseWarning(Warning): + pass + +# Only use this if you actually want to return an Http 400 +# to the client. This should only happen in cases where the +# client is wrong. +class WeaveBadRequest(WeaveBaseError): + pass + + +class WeaveInternalError(WeaveBaseError): + """Internal Weave Error (a programming error)""" + + pass + +class WeaveSerializeError(WeaveBaseError): + pass diff --git a/weave/legacy/ops_primitives/weave_api.py b/weave/legacy/ops_primitives/weave_api.py index 4d95af0392c6..5417cb96de7b 100644 --- a/weave/legacy/ops_primitives/weave_api.py +++ b/weave/legacy/ops_primitives/weave_api.py @@ -7,7 +7,6 @@ ref_base, registry_mem, storage, - trace_legacy, weave_internal, ) from weave import weave_types as types @@ -20,6 +19,7 @@ graph, object_context, runs, + trace_legacy, uris, ) from weave.legacy.graph import Node diff --git a/weave/trace_legacy.py b/weave/legacy/trace_legacy.py similarity index 97% rename from weave/trace_legacy.py rename to weave/legacy/trace_legacy.py index 6a1b41fe69ad..3264585672d7 100644 --- a/weave/trace_legacy.py +++ b/weave/legacy/trace_legacy.py @@ -3,8 +3,9 @@ from weave.legacy import artifact_local, graph, runs -from . import errors, ref_base -from . import weave_types as types +from .. import ref_base +from . import errors +from .. import weave_types as types def get_obj_creator(ref: ref_base.Ref) -> typing.Optional[runs.Run]: diff --git a/weave/tests/legacy/test_trace.py b/weave/tests/legacy/test_trace.py index bd32cec3e01a..e779f576e7eb 100644 --- a/weave/tests/legacy/test_trace.py +++ b/weave/tests/legacy/test_trace.py @@ -3,7 +3,8 @@ from weave.legacy import graph from ... import api as weave -from ... import storage, trace_legacy +from ... import storage +from ...legacy import trace_legacy from ...weave_internal import make_const_node From 49150dd2fa514d64d35ecc0f03dcb4a9923e68f0 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Mon, 26 Aug 2024 19:20:48 -0400 Subject: [PATCH 2/3] move to scripts, legacy/scripts: scripts --- .github/workflows/test.yaml | 2 +- DEVELOPMENT.md | 3 +-- integration_test/README.md | 2 +- bisect_script.sh => scripts/bisect_script.sh | 0 build_frontend.sh => scripts/build_frontend.sh | 0 build_test_container.sh => scripts/build_test_container.sh | 0 dd_weave_server.sh => scripts/dd_weave_server.sh | 0 dd_weave_server_replay.sh => scripts/dd_weave_server_replay.sh | 0 weave_server.sh => scripts/weave_server.sh | 0 weave_server_replay.sh => scripts/weave_server_replay.sh | 0 weave_server_test.sh => scripts/weave_server_test.sh | 0 supervisord.conf | 2 +- weave-js/src/core/README.md | 2 +- weave/legacy/{ => scripts}/clear_cache.py | 0 jupyter_dev.sh => weave/legacy/scripts/jupyter_dev.sh | 0 weave/{ => scripts}/pytest_parallel.sh | 0 16 files changed, 5 insertions(+), 6 deletions(-) rename bisect_script.sh => scripts/bisect_script.sh (100%) rename build_frontend.sh => scripts/build_frontend.sh (100%) rename build_test_container.sh => scripts/build_test_container.sh (100%) rename dd_weave_server.sh => scripts/dd_weave_server.sh (100%) rename dd_weave_server_replay.sh => scripts/dd_weave_server_replay.sh (100%) rename weave_server.sh => scripts/weave_server.sh (100%) rename weave_server_replay.sh => scripts/weave_server_replay.sh (100%) rename weave_server_test.sh => scripts/weave_server_test.sh (100%) rename weave/legacy/{ => scripts}/clear_cache.py (100%) rename jupyter_dev.sh => weave/legacy/scripts/jupyter_dev.sh (100%) rename weave/{ => scripts}/pytest_parallel.sh (100%) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 38e0a8aef2ed..f1b883498b13 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -186,7 +186,7 @@ jobs: # github actions does something funky with the std file descriptors, they end up # being closed. tqdm (for example) raises an exception when the descriptor it # wants to write to is closed. - run: nohup ./weave_server_test.sh < /dev/null &> /tmp/weave/log/stdout.log & + run: nohup ./scripts/weave_server_test.sh < /dev/null &> /tmp/weave/log/stdout.log & shell: bash - name: Cypress run # Use the following to run just a single test diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 86d52a80135d..27f7ded18778 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -72,7 +72,7 @@ yarn dev Weave backend server. This does not currently auto-reload, so you need to restart it if you change stuff. ``` -sh weave_server.sh +sh scripts/weave_server.sh ``` Now you should be able to go to localhost:3000 to see the weave home page. @@ -92,7 +92,6 @@ You can tell everything is working if the weave UI renders and you see your serv Some ops require environment variables to be set, like OPENAI_API_KEY. You need to set these for the server environment and your Jupyter notebook. - ## Unit tests Some of the unit tests try to run a wandb server container, and will produce 403s if that container is out of date. The container is only accessible to wandb developers currently. diff --git a/integration_test/README.md b/integration_test/README.md index e97a5c5d65a5..77c6eab53db0 100644 --- a/integration_test/README.md +++ b/integration_test/README.md @@ -18,4 +18,4 @@ yarn && yarn run cypress open Start the weave server with -bash weave_server_test.sh +bash scripts/weave_server_test.sh diff --git a/bisect_script.sh b/scripts/bisect_script.sh similarity index 100% rename from bisect_script.sh rename to scripts/bisect_script.sh diff --git a/build_frontend.sh b/scripts/build_frontend.sh similarity index 100% rename from build_frontend.sh rename to scripts/build_frontend.sh diff --git a/build_test_container.sh b/scripts/build_test_container.sh similarity index 100% rename from build_test_container.sh rename to scripts/build_test_container.sh diff --git a/dd_weave_server.sh b/scripts/dd_weave_server.sh similarity index 100% rename from dd_weave_server.sh rename to scripts/dd_weave_server.sh diff --git a/dd_weave_server_replay.sh b/scripts/dd_weave_server_replay.sh similarity index 100% rename from dd_weave_server_replay.sh rename to scripts/dd_weave_server_replay.sh diff --git a/weave_server.sh b/scripts/weave_server.sh similarity index 100% rename from weave_server.sh rename to scripts/weave_server.sh diff --git a/weave_server_replay.sh b/scripts/weave_server_replay.sh similarity index 100% rename from weave_server_replay.sh rename to scripts/weave_server_replay.sh diff --git a/weave_server_test.sh b/scripts/weave_server_test.sh similarity index 100% rename from weave_server_test.sh rename to scripts/weave_server_test.sh diff --git a/supervisord.conf b/supervisord.conf index 39f470d75293..e5c0649f61ab 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -27,7 +27,7 @@ stopasgroup = true killasgroup = true [program:weave-python-server] -command = bash ./weave_server_test.sh +command = bash ./scripts/weave_server_test.sh directory = . autostart = true autorestart = false diff --git a/weave-js/src/core/README.md b/weave-js/src/core/README.md index 0936c1535fa7..b6ab48c56ba0 100644 --- a/weave-js/src/core/README.md +++ b/weave-js/src/core/README.md @@ -424,5 +424,5 @@ See [generateDocs.ts](./generateDocs.ts) for implementation. # Testing Against Weave Python -1. Start a Weave Server using `./weave_server.sh` from the `weave/weave` directory +1. Start a Weave Server using `./scripts/weave_server.sh` from the `weave/weave` directory 2. Run `yarn test:python-backend` from this directory diff --git a/weave/legacy/clear_cache.py b/weave/legacy/scripts/clear_cache.py similarity index 100% rename from weave/legacy/clear_cache.py rename to weave/legacy/scripts/clear_cache.py diff --git a/jupyter_dev.sh b/weave/legacy/scripts/jupyter_dev.sh similarity index 100% rename from jupyter_dev.sh rename to weave/legacy/scripts/jupyter_dev.sh diff --git a/weave/pytest_parallel.sh b/weave/scripts/pytest_parallel.sh similarity index 100% rename from weave/pytest_parallel.sh rename to weave/scripts/pytest_parallel.sh From d3d8d4194c6b34e53632079bdefb178e285b5d7e Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Sat, 24 Aug 2024 16:06:46 -0400 Subject: [PATCH 3/3] format: scripts --- scripts/build_test_container.sh | 6 +++++- scripts/dd_weave_server.sh | 19 +++++++++++-------- scripts/dd_weave_server_replay.sh | 11 ++++++++--- scripts/weave_server.sh | 12 ++++++++---- scripts/weave_server_replay.sh | 6 +++++- scripts/weave_server_test.sh | 9 ++++++++- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/scripts/build_test_container.sh b/scripts/build_test_container.sh index d7a705eac39a..7c02c00baecb 100755 --- a/scripts/build_test_container.sh +++ b/scripts/build_test_container.sh @@ -1 +1,5 @@ -docker buildx build --platform linux/amd64 -t us-east4-docker.pkg.dev/weave-support-367421/weave-images/weave-test:latest . -f Dockerfile.test +docker buildx build \ + --platform linux/amd64 \ + -t us-east4-docker.pkg.dev/weave-support-367421/weave-images/weave-test:latest \ + -f Dockerfile.test \ + . diff --git a/scripts/dd_weave_server.sh b/scripts/dd_weave_server.sh index c1c12ea833a4..7556d1bdb5e8 100755 --- a/scripts/dd_weave_server.sh +++ b/scripts/dd_weave_server.sh @@ -1,13 +1,16 @@ #!/bin/sh -DD_SERVICE="weave-python" DD_ENV="dev-$(whoami)" DD_LOGS_INJECTION=true \ - DD_TRACE_PROPAGATION_STYLE_EXTRACT=b3,datadog \ - DD_TRACE_PROPAGATION_STYLE_INJECT=b3,datadog \ - WEAVE_DISABLE_ANALYTICS=true \ - WEAVE_SERVER_ENABLE_LOGGING=true \ - FLASK_ENV=development \ - FLASK_APP=weave.weave_server \ - ddtrace-run flask run --port 9994 +DD_SERVICE="weave-python" +DD_ENV="dev-$(whoami)" +DD_LOGS_INJECTION=true +DD_TRACE_PROPAGATION_STYLE_EXTRACT=b3,datadog +DD_TRACE_PROPAGATION_STYLE_INJECT=b3,datadog +WEAVE_DISABLE_ANALYTICS=true +WEAVE_SERVER_ENABLE_LOGGING=true +FLASK_ENV=development +FLASK_APP=weave.weave_server + +ddtrace-run flask run --port 9994 # This runs with the datadog profiler on, but it is expensive! # I noticed a 2x increase in query time for some queries diff --git a/scripts/dd_weave_server_replay.sh b/scripts/dd_weave_server_replay.sh index 34039457b217..590a0b38bd8f 100755 --- a/scripts/dd_weave_server_replay.sh +++ b/scripts/dd_weave_server_replay.sh @@ -1,5 +1,10 @@ #!/bin/sh -WEAVE_SERVER_DEBUG=true \ -DD_SERVICE="weave-python" DD_ENV="dev-$(whoami)" DD_LOGS_INJECTION=true \ - WEAVE_SERVER_ENABLE_LOGGING=true FLASK_APP=weave.weave_server ddtrace-run flask run --port 9994 +WEAVE_SERVER_DEBUG=true +DD_SERVICE="weave-python" +DD_ENV="dev-$(whoami)" +DD_LOGS_INJECTION=true +WEAVE_SERVER_ENABLE_LOGGING=true +FLASK_APP=weave.weave_server + +ddtrace-run flask run --port 9994 diff --git a/scripts/weave_server.sh b/scripts/weave_server.sh index a2cebdd4134b..91bc19fccd61 100755 --- a/scripts/weave_server.sh +++ b/scripts/weave_server.sh @@ -2,7 +2,11 @@ # We could set WEAVE_BACKEND_HOST=http://localhost:9994/__weave but the frontend dev server # automatically forwards so it shouldn't be necessary. -( - source ./config/auth_modes.sh - WEAVE_DISABLE_ANALYTICS=true WEAVE_SERVER_ENABLE_LOGGING=true FLASK_DEBUG=1 FLASK_APP=weave.weave_server flask run --port 9994 -) +source ./config/auth_modes.sh + +WEAVE_DISABLE_ANALYTICS=true +WEAVE_SERVER_ENABLE_LOGGING=true +FLASK_DEBUG=1 +FLASK_APP=weave.weave_server + +flask run --port 9994 diff --git a/scripts/weave_server_replay.sh b/scripts/weave_server_replay.sh index d8242a8841e1..41814fb476d6 100755 --- a/scripts/weave_server_replay.sh +++ b/scripts/weave_server_replay.sh @@ -1,3 +1,7 @@ #!/bin/sh -WEAVE_SERVER_DEBUG=true WEAVE_SERVER_ENABLE_LOGGING=true FLASK_APP=weave.weave_server flask run --port 9994 +export WEAVE_SERVER_DEBUG=true +export WEAVE_SERVER_ENABLE_LOGGING=true +export FLASK_APP=weave.weave_server + +flask run --port 9994 diff --git a/scripts/weave_server_test.sh b/scripts/weave_server_test.sh index 3f084bfcb632..366ad390ac9e 100755 --- a/scripts/weave_server_test.sh +++ b/scripts/weave_server_test.sh @@ -1,3 +1,10 @@ #!/bin/sh -WEAVE_CI=true WEAVE_DISABLE_ANALYTICS=true WEAVE_SERVER_DEBUG=true WEAVE_SERVER_ENABLE_LOGGING=true WEAVE_WANDB_GQL_NUM_TIMEOUT_RETRIES=1 FLASK_APP=weave.weave_server flask run --port 9994 $@ +export WEAVE_CI=true +export WEAVE_DISABLE_ANALYTICS=true +export WEAVE_SERVER_DEBUG=true +export WEAVE_SERVER_ENABLE_LOGGING=true +export WEAVE_WANDB_GQL_NUM_TIMEOUT_RETRIES=1 +export FLASK_APP=weave.weave_server + +flask run --port 9994 "$@"