Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(onboarding): early exit conditions in lib-injection #9323

Merged
merged 101 commits into from
Jun 11, 2024
Merged
Changes from 6 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
b8ab509
add logic for checking packages and runtimes against allowlists
ZStriker19 May 20, 2024
40a4449
enhance telemetry event to be sent and modify for package incompatibi…
ZStriker19 May 20, 2024
9c28276
add rest of telemetry events needed
ZStriker19 May 21, 2024
4f47c1b
update telemetry payload to be easily sendable
ZStriker19 May 21, 2024
c3f9073
refactor and change payload spec
ZStriker19 May 21, 2024
69c2c23
modifications for updated metrics, make python 2.7 compatible
ZStriker19 May 23, 2024
0201430
implement new payload standard, sending multiple events in payload, m…
ZStriker19 May 23, 2024
5d4371c
fix override tags
ZStriker19 May 23, 2024
2b50e83
update metrics with new tags
ZStriker19 May 24, 2024
aaa5e0e
remove send_telemetry
ZStriker19 May 24, 2024
31a8812
Merge branch 'main' into zachg/guardrails_poc
emmettbutler May 28, 2024
4e0b323
Update lib-injection/sitecustomize.py
ZStriker19 May 28, 2024
5ade18a
check in requirements_script
emmettbutler May 28, 2024
705b1ce
add mode that imports riot;
emmettbutler May 29, 2024
5083060
remove ast mode
emmettbutler May 29, 2024
9491cdd
minimum requiremets in dockerfile
emmettbutler May 29, 2024
0c651ab
rename
emmettbutler May 29, 2024
ae4450b
commit generated file
emmettbutler May 29, 2024
9cab85e
check in requirements_script
emmettbutler May 28, 2024
b5c3d8b
add mode that imports riot;
emmettbutler May 29, 2024
dcba12b
remove ast mode
emmettbutler May 29, 2024
a22a5a5
Merge branch 'emmett.butler/min_versions' into zachg/guardrails_poc
emmettbutler May 29, 2024
c45d32a
include min versions file in build
emmettbutler May 29, 2024
5a1546c
proper riotfile import
emmettbutler May 30, 2024
857e45e
Merge branch 'emmett.butler/min_versions' into zachg/guardrails_poc
emmettbutler May 30, 2024
5ac0ec5
add a copy of the csv to lib-injection
emmettbutler May 30, 2024
aaa1604
add copy during OCI build
emmettbutler May 30, 2024
ff77089
try different path
emmettbutler May 30, 2024
8cf5032
more copying
emmettbutler May 30, 2024
f51bec0
wrong name
emmettbutler May 30, 2024
f73eb10
path
emmettbutler May 30, 2024
154a71b
verbose and listdir for debugging
emmettbutler May 30, 2024
b97ea06
dir?
emmettbutler May 30, 2024
dfc9c82
handle unset executable path
emmettbutler May 30, 2024
72fb22d
py version detection logic fix
emmettbutler May 30, 2024
e36b24c
use pkg_resources instead
emmettbutler May 30, 2024
582ed77
strs
emmettbutler May 30, 2024
d335d38
ignore setuptools
emmettbutler May 30, 2024
d005634
no more pkg_resources beyond 3.7
emmettbutler May 30, 2024
20dce57
no letters allowed
emmettbutler May 30, 2024
b7c9c09
allow forcing
emmettbutler May 30, 2024
21fcf75
copypasta
emmettbutler May 31, 2024
f3186b9
debug print
emmettbutler May 31, 2024
57192e4
debug print
emmettbutler May 31, 2024
c3fb4c8
do not install ddtrace because it causes logic under test to be skipped
emmettbutler May 31, 2024
5f0bfa1
no ddtracerun if it is not installed
emmettbutler May 31, 2024
2242ed0
remove prints
emmettbutler May 31, 2024
6b8406f
add a test for unsupported package in env
emmettbutler May 31, 2024
a72a7a6
try installing a different unsupported package that will not break th…
emmettbutler May 31, 2024
7cf4e73
reno
emmettbutler May 31, 2024
ac556ca
Merge branch 'main' into zachg/guardrails_poc
emmettbutler May 31, 2024
037cc0f
include specifier info in file
emmettbutler May 31, 2024
2add1fa
smarter version constraint handling
emmettbutler May 31, 2024
db3e4fc
tup not gen
emmettbutler May 31, 2024
cd9b818
oops
emmettbutler May 31, 2024
cd7f30a
oops
emmettbutler May 31, 2024
8372d75
dead file
emmettbutler May 31, 2024
fce97f8
regenerate
emmettbutler May 31, 2024
a792a32
lint
emmettbutler Jun 3, 2024
86cfecf
cover some more pieces of the test matrix
emmettbutler Jun 4, 2024
53e8643
Update lib-injection/sitecustomize.py
emmettbutler Jun 4, 2024
4010b64
review feedback
emmettbutler Jun 4, 2024
87c3517
update compatible versions
emmettbutler Jun 4, 2024
2e7b12c
fix apparent logic error in version check
emmettbutler Jun 4, 2024
c974688
change force test to exercise a setup that will actually generate traces
emmettbutler Jun 4, 2024
c0d4db4
disable instrumentation of unsupported package
emmettbutler Jun 4, 2024
4fae4f5
try with a different unsupported library that hopefully does not inte…
emmettbutler Jun 4, 2024
e6be3e4
syntax
emmettbutler Jun 4, 2024
6b62355
quiet
emmettbutler Jun 4, 2024
f079e93
wait longer???
emmettbutler Jun 4, 2024
26b8ec0
pretty sure this is supposed to work
emmettbutler Jun 4, 2024
930df59
change ddtrace version being checked for
emmettbutler Jun 4, 2024
efa8538
undefined name
emmettbutler Jun 4, 2024
279f12e
telemetry enabled envvar
emmettbutler Jun 4, 2024
25191af
Update lib-injection/sitecustomize.py
emmettbutler Jun 4, 2024
3b4fe03
Update lib-injection/sitecustomize.py
emmettbutler Jun 4, 2024
d2466ff
catch everything
emmettbutler Jun 4, 2024
e5c84da
Update releasenotes/notes/injection-guardrails-bde1d57db91f33d1.yaml
emmettbutler Jun 4, 2024
faba009
suitespec
emmettbutler Jun 6, 2024
9ebf5d8
checkpoint
emmettbutler Jun 10, 2024
1dfdb91
try platform pyversion again
emmettbutler Jun 10, 2024
b69ce20
strip minor version for site-packages path
emmettbutler Jun 10, 2024
09c6ca4
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 10, 2024
5e1e4ba
simpler path
emmettbutler Jun 10, 2024
0e31d1e
try a different path
emmettbutler Jun 10, 2024
b3332f8
multiple paths
emmettbutler Jun 10, 2024
ce22468
only use the first file found
emmettbutler Jun 10, 2024
c3f6936
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 10, 2024
8affa8f
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 10, 2024
b839f2a
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 10, 2024
24ec2b9
case insensitive package name comparisons
emmettbutler Jun 10, 2024
79e0d2a
missed a spot
emmettbutler Jun 10, 2024
5ab1346
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 10, 2024
8b08f59
missed a spot
emmettbutler Jun 10, 2024
a40cf90
Update lib-injection/sitecustomize.py
emmettbutler Jun 10, 2024
6b03ec4
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 10, 2024
362c030
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 10, 2024
2e80831
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 10, 2024
08cd07c
Update lib-injection/sitecustomize.py
emmettbutler Jun 10, 2024
8895a65
Update lib-injection/sitecustomize.py
emmettbutler Jun 10, 2024
43bdbc3
Merge branch 'main' into zachg/guardrails_poc
emmettbutler Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions min_compatible_versions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
This file was generated by scripts/min_compatible_versions.py
pkg_name,min_version
Flask-Cache,0.13.1
Jinja2,2.11.0
SQLAlchemy,2.0.22
WebTest,0
Werkzeug,1.0
ai21,0
aiobotocore,1.4.2
aiofiles,0
aiohttp,3.7
aiohttp_jinja2,1.5.0
aiomysql,0.1.0
aiopg,0.16.0
aiosqlite,0
algoliasearch,2.5
anyio,3.4.0
aredis,0
asgiref,3.0.0
astunparse,0
async_generator,1.10
asyncpg,0.22.0
asynctest,0.13.0
attrs,20
austin-python,1.0
blinker,0
boto3,0
botocore,1.13
bottle,0.12
bytecode,0
cassandra-driver,3.24.0
cattrs,23.1.1
celery,4.4
cfn-lint,0.53.1
channels,3.0
cherrypy,17
click,7.1.2
cohere,0
confluent-kafka,1.9.2
coverage,0
cryptography,39
daphne,0
databases,0
datadog-lambda,4.66.0
ddsketch,3.0.0
django,2.2
django-pylibmc,0.6
django-q,0
django-redis,4.5
django_hosts,4.0
djangorestframework,3.11
docker,0
dogpile.cache,0.9
dramatiq,0
elasticsearch,7.13.0
elasticsearch1,1.10.0
elasticsearch2,2.5.0
elasticsearch5,5.5.0
elasticsearch6,6.8.0
elasticsearch7,7.13.0
elasticsearch7[async],0
elasticsearch8,8.0.1
elasticsearch[async],0
envier,0.5.1
exceptiongroup,0
falcon,3.0.0
fastapi,0.64.0
flask,0.12.0
flask-caching,1.10.0
flask-login,0.6.2
gevent,20.12.0
git+https://github.com/gnufede/pytest-memray.git@24a3c0735db99eedf57fb36c573680f9bab7cd73,0
googleapis-common-protos,0
graphene,3.0.0
graphql-core,3.2.0
graphql-relay,0
greenlet,1.0
grpcio,1.34.0
gunicorn,20.0.4
gunicorn[gevent],0
httpretty,1.1
httpx,0.17.0
huggingface-hub,0
hypothesis,6.45.1
importlib-metadata,0
importlib_metadata,5.0
itsdangerous,2.0
jinja2,2.11.0
kombu,4.2.0
langchain,0.0.192
langchain-community,0.0.14
langchain-core,0.1.27
langchain-openai,0.0.8
langchain-pinecone,0.0.3
langchain_experimental,0.0.47
langsmith,0.1.9
logbook,1.0.0
loguru,0.4.0
mako,1.1.0
mariadb,1.0
markupsafe,2.0
mock,0
molten,1.0
mongoengine,0.23
more_itertools,8.11.0
moto,1.0
moto[all],5.0
msgpack,1.0.0
mysql-connector-python,8.0.5
mysqlclient,2.0
numexpr,0
openai,0.26.5
openai[datalib],1.30.1
"openai[embeddings,datalib]",0.27.2
opensearch-py,0
opensearch-py[async],0
opensearch-py[requests],1.1.0
opentelemetry-api,1.0.0
opentelemetry-instrumentation-flask,0.37b0
opentracing,2.0.0
peewee,0
pillow,0
pinecone-client,2.2.4
pony,0
protobuf,3
psutil,0
psycopg,3.0.18
psycopg2-binary,2.8.0
py-cpuinfo,8.0.0
pycryptodome,0
pyfakefs,0
pylibmc,1.6.2
pymemcache,3.4.2
pymongo,3.11
pymysql,0.10
pynamodb,5.0
pyodbc,4.0.31
pyramid,1.10
pysqlite3-binary,0
pytest,4.0
pytest-aiohttp,0
pytest-asyncio,0.21.1
pytest-bdd,4.0
pytest-benchmark,3.1.0
pytest-cov,2.9.0
pytest-django,3.10.0
pytest-mock,2.0.0
pytest-randomly,0
pytest-sanic,1.6.2
python-consul,1.1
python-json-logger,2.0.7
python-memcached,0
redis,2.0
redis-py-cluster,2.0
reno,0
requests,2.20.0
requests-mock,1.4
responses,0.16.0
rich,0
rq,1.8.0
ruamel.yaml,0
sanic,20.12
sanic-testing,0.8.3
scikit-learn,1.0.2
setuptools,67.6.0
simplejson,0
six,1.12.0
snowflake-connector-python,2.3.0
sqlalchemy,1.2.18
starlette,0.14.0
structlog,20.2.0
tests/contrib/pyramid/pserve_app,0
tiktoken,0
tornado,4.5.0
tortoise-orm,0
typing-extensions,0
typing_extensions,0
urllib3,1.0
uwsgi,0
vcrpy,4.2.1
vertica-python,0.6.0
websockets,11.0
webtest,0
werkzeug,1.0
wheel,0
xmltodict,0.12
yaaredis,2.0.0
yarl,1.0
108 changes: 108 additions & 0 deletions scripts/min_compatible_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import ast
import csv
from typing import Dict
from typing import List
from typing import Set

from packaging.version import parse as parse_version


OUT_FILENAME = "min_compatible_versions.csv"


def tree_pkgs(node: ast.AST) -> Dict[str, Set[str]]:
result = {pkg: set(versions) for pkg, versions in node.pkgs.items()}
for child_venv in node.venvs:
child_pkgs = tree_pkgs(child_venv)
for pkg_name, versions in child_pkgs.items():
if pkg_name in result:
result[pkg_name] = result[pkg_name].union(versions)
else:
result[pkg_name] = versions
return result


def get_venv_root_ast_node(syntax_tree: ast.AST) -> ast.AST:
for node in reversed(syntax_tree.body):
if hasattr(node, "targets"):
if node.targets[0].id == "venv":
return node.value


def get_children(venv_ast_node: ast.AST) -> List[ast.AST]:
for keyword in getattr(venv_ast_node, "keywords", []):
if keyword.arg == "venvs":
return keyword.value.elts
return []


def _parse_requirements_from_node(venv_ast_node: ast.AST) -> Dict[str, Set[str]]:
pkgs_node = None
for keyword in getattr(venv_ast_node, "keywords", []):
if keyword.arg == "pkgs":
pkgs_node = keyword

if not pkgs_node:
return dict()

requirements = dict()
for key, value in zip(pkgs_node.value.keys, pkgs_node.value.values):
versions = set()
if isinstance(value, ast.Constant):
versions = set([value.value])
elif isinstance(value, ast.List):
versions = set([getattr(item, "value", "") for item in value.elts])
requirements[key.value] = _format_version_specifiers(versions)
return requirements


def _format_version_specifiers(spec: Set[str]) -> Set[str]:
return set([part.strip("~<>==") for v in [v.split(",") for v in spec if v] for part in v if "!=" not in part])


def _requirements_at_node(venv_ast_node: ast.AST) -> Dict[str, Set[str]]:
result = _parse_requirements_from_node(venv_ast_node)
for child in get_children(venv_ast_node):
child_pkgs = _requirements_at_node(child)
for pkg_name, versions in child_pkgs.items():
if pkg_name in result:
result[pkg_name] = result[pkg_name].union(versions)
else:
result[pkg_name] = versions
return result


def parse_riotfile_ast(riotfile_ast: ast.AST) -> Dict[str, Set[str]]:
root_venv_node = get_venv_root_ast_node(riotfile_ast)
requirements = _requirements_at_node(root_venv_node)
return requirements


def tree_pkgs_from_ast() -> Dict[str, Set[str]]:
with open("riotfile.py", "r") as f:
riotfile_content = f.read()
return parse_riotfile_ast(ast.parse(riotfile_content))


def write_out(all_pkgs: Dict[str, Set[str]]) -> None:
with open(OUT_FILENAME, "w") as csvfile:
csv_writer = csv.writer(csvfile, delimiter=",")
csv_writer.writerow(["This file was generated by scripts/min_compatible_versions.py"])
csv_writer.writerow(["pkg_name", "min_version"])
for pkg, versions in sorted(all_pkgs.items()):
min_version = "0"
if versions:
min_version = min((parse_version(v) for v in versions))
print("%s\n\tTested versions: %s\n\tMinimum: %s" % (pkg, sorted(list(versions)), min_version))
csv_writer.writerow([pkg, min_version])


def main():
"""Discover the minimum version of every package referenced in the riotfile

Writes to stdout and min_versions.csv
"""
write_out(tree_pkgs_from_ast())


main()