[Python o11y] Fix Python O11Y artifacts name (#35965)

Update observability to PYPI failed because the artifact name is not correct.

This PR:
* Fix the artifacts name.
* Add step to test observability artifacts in `test_packages.sh`.
* Added `-fno-ipa-cp` compile flag.
  * We're seeing `inlining failed in call to always_inline 'vsnprintf': function body can be overwritten at link time` errors when building from source using musl libc.
  * Based on [investigation](https://gitlab.alpinelinux.org/alpine/aports/-/issues/8626), it's because we're using `-flto` flag.
  * One solution is to [disable fortify by adding this flag](https://gitlab.alpinelinux.org/alpine/aports/-/issues/8626).

After this PR, the observability artifacts have the correct name:
* [Distribution Tests Python Linux](https://pantheon.corp.google.com/storage/browser/grpc-testing-kokoro-prod/test_result_public/prod/grpc/core/pull_request/linux/grpc_distribtests_python/28687/20240223-105306/github/grpc/artifacts;tab=objects?pageState=(%22StorageObjectListTable%22:(%22f%22:%22%255B%255D%22))&e=13802955&mods=-logs_tg_prod&prefix=&forceOnObjectsSortingFiltering=false)

Also tested that the artifacts build in this PR can be successfully uploaded to testpypi:
* https://test.pypi.org/project/grpcio-observability/1.63.0.dev0

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #35965

PiperOrigin-RevId: 611268154
pull/35982/head
Xuan Wang 9 months ago committed by Copybara-Service
parent 493cad8ef2
commit 9b424b5dd4
  1. 16
      src/python/grpcio_observability/setup.py
  2. 4
      test/distrib/python/test_packages.sh
  3. 37
      tools/run_tests/artifacts/build_artifact_python.sh

@ -61,6 +61,18 @@ def _env_bool_value(env_name, default):
return os.environ.get(env_name, default).upper() not in ["FALSE", "0", ""]
def _is_alpine():
"""Checks if it's building Alpine"""
os_release_content = ""
try:
with open("/etc/os-release", "r") as f:
os_release_content = f.read()
if "alpine" in os_release_content:
return True
except Exception:
return False
# Environment variable to determine whether or not the Cython extension should
# *use* Cython or use the generated C files. Note that this requires the C files
# to have been generated by building first *with* Cython support.
@ -154,6 +166,10 @@ if EXTRA_ENV_LINK_ARGS is None:
# Note that it does not work for MSCV on windows.
if "win32" not in sys.platform:
EXTRA_ENV_COMPILE_ARGS += " -flto"
# Compile with fail with error: `lto-wrapper failed` when lto flag was enabled in Alpine using musl libc.
# As a work around we need to disable ipa-cp.
if _is_alpine():
EXTRA_ENV_COMPILE_ARGS += " -fno-ipa-cp"
EXTRA_COMPILE_ARGS = shlex.split(EXTRA_ENV_COMPILE_ARGS)
EXTRA_LINK_ARGS = shlex.split(EXTRA_ENV_LINK_ARGS)

@ -24,10 +24,12 @@ then
echo "Testing Python binary distribution"
ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-[0-9]*.whl)
TOOLS_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio_tools-[0-9]*.whl)
OBSERVABILITY_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio_observability-[0-9]*.whl)
else
echo "Testing Python source distribution"
ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-[0-9]*.tar.gz)
TOOLS_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-tools-[0-9]*.tar.gz)
OBSERVABILITY_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-observability-[0-9]*.tar.gz)
fi
HEALTH_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-health-checking-[0-9]*.tar.gz)
@ -63,6 +65,7 @@ function at_least_one_installs() {
if [[ "$1" == "binary" ]]; then
validate_wheel_hashes "${ARCHIVES[@]}"
validate_wheel_hashes "${TOOLS_ARCHIVES[@]}"
validate_wheel_hashes "${OBSERVABILITY_ARCHIVES[@]}"
fi
@ -75,6 +78,7 @@ at_least_one_installs "${TOOLS_ARCHIVES[@]}"
at_least_one_installs "${HEALTH_ARCHIVES[@]}"
at_least_one_installs "${REFLECTION_ARCHIVES[@]}"
at_least_one_installs "${TESTING_ARCHIVES[@]}"
at_least_one_installs "${OBSERVABILITY_ARCHIVES[@]}"
#

@ -147,6 +147,14 @@ ${SETARCH_CMD} "${PYTHON}" tools/distrib/python/grpcio_tools/setup.py sdist
# shellcheck disable=SC2086
${SETARCH_CMD} "${PYTHON}" tools/distrib/python/grpcio_tools/setup.py bdist_wheel $WHEEL_PLAT_NAME_FLAG
if [ "$GRPC_BUILD_MAC" == "" ]; then
"${PYTHON}" src/python/grpcio_observability/make_grpcio_observability.py
${SETARCH_CMD} "${PYTHON}" src/python/grpcio_observability/setup.py sdist
# shellcheck disable=SC2086
${SETARCH_CMD} "${PYTHON}" src/python/grpcio_observability/setup.py bdist_wheel $WHEEL_PLAT_NAME_FLAG
fi
# run twine check before auditwheel, because auditwheel puts the repaired wheels into
# the artifacts output dir.
if [ "$GRPC_SKIP_TWINE_CHECK" == "" ]
@ -158,6 +166,9 @@ then
# Ensure the generated artifacts are valid using "twine check"
venv/bin/python -m pip install "twine<=2.0" "readme_renderer<40.0"
venv/bin/python -m twine check dist/* tools/distrib/python/grpcio_tools/dist/*
if [ "$GRPC_BUILD_MAC" == "" ]; then
venv/bin/python -m twine check src/python/grpcio_observability/dist/*
fi
rm -rf venv/
fi
@ -209,11 +220,26 @@ else
cp -r tools/distrib/python/grpcio_tools/dist/*.whl "$ARTIFACT_DIR"
fi
# grpcio and grpcio-tools wheels have already been copied to artifact_dir
# grpcio and grpcio-tools have already been copied to artifact_dir
# by "auditwheel repair", now copy the .tar.gz source archives as well.
cp -r dist/*.tar.gz "$ARTIFACT_DIR"
cp -r tools/distrib/python/grpcio_tools/dist/*.tar.gz "$ARTIFACT_DIR"
if [ "$GRPC_BUILD_MAC" == "" ]; then
if [ "$GRPC_RUN_AUDITWHEEL_REPAIR" != "" ]
then
for wheel in src/python/grpcio_observability/dist/*.whl; do
"${AUDITWHEEL}" show "$wheel" | tee /dev/stderr | grep -E -w "$AUDITWHEEL_PLAT"
"${AUDITWHEEL}" repair "$wheel" --strip --wheel-dir "$ARTIFACT_DIR"
rm "$wheel"
done
else
cp -r src/python/grpcio_observability/dist/*.whl "$ARTIFACT_DIR"
fi
cp -r src/python/grpcio_observability/dist/*.tar.gz "$ARTIFACT_DIR"
fi
# We need to use the built grpcio-tools/grpcio to compile the health proto
# Wheels are not supported by setup_requires/dependency_links, so we
# manually install the dependency. Note we should only do this if we
@ -282,13 +308,4 @@ then
sdist bdist_wheel
cp -r src/python/grpcio_admin/dist/* "$ARTIFACT_DIR"
# Build grpcio_observability source distribution
# Skips MacOS since grpcio_observability does not support MacOS.
if [ "$GRPC_BUILD_MAC" == "" ]; then
"${PYTHON}" src/python/grpcio_observability/make_grpcio_observability.py
${SETARCH_CMD} "${PYTHON}" src/python/grpcio_observability/setup.py \
sdist bdist_wheel
cp -r src/python/grpcio_observability/dist/* "$ARTIFACT_DIR"
fi
fi

Loading…
Cancel
Save