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

ci: Add API protobuf breaking-change-detector CI script #17793

Merged
merged 16 commits into from
Aug 27, 2021

Conversation

YaseenAlk
Copy link
Contributor

@YaseenAlk YaseenAlk commented Aug 20, 2021

Commit Message: Add API protobuf breaking-change-detector CI script

Additional Description:

This PR is a continuation to #17515 - it adds a script that uses buf to check for breaking changes on proto files in the api folder. It does so by comparing the current api folder against the api folder at the git commit computed by tools/git/last_github_commit.sh - that should hopefully represent the most recent commit on main (if there is a better method to obtain the base branch commit, let me know!).

Adding the script also required re-organizing some of the breaking change detector logic from the previous pr: some levels of abstraction were added, and the detector now expects a git repository and ref as the input for initial state (rather than a proto file).

The script is invoked in do_ci.sh if bazel.api_compat is specified as the CI_TARGET.

This PR also bumps the buf bazel dependency to 0.53.0. If this is preferred to be in a separate PR, let me know and I would be happy to do so

Risk Level: low (hopefully) - the CI script will be invoked in a separate CI pipeline job that can be set to be optional on github. The azure pipeline has been added but needs to be set to optional by a CI maintainer

Testing: New scripts and logic were tested manually; also ran tests from the previous PR and they still pass. hoping to observe more output of this tool through reading CI logs of other PRs once this is merged (this PR should not affect the existing PR workflow - refer to Risk Level)

Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: CI script uses a linux binary for buf so it cannot be run outside of docker on non-linux systems

Related Issue #3368

Signed-off-by: Yaseen Alkhafaji <[email protected]>
Signed-off-by: Yaseen Alkhafaji <[email protected]>
@repokitteh-read-only repokitteh-read-only bot added the deps Approval required for changes to Envoy's external dependencies label Aug 20, 2021
@repokitteh-read-only
Copy link

CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).

🐱

Caused by: #17793 was opened by YaseenAlk.

see: more, trace.

@YaseenAlk
Copy link
Contributor Author

cc @akonradi @adisuissa

Signed-off-by: Yaseen Alkhafaji <[email protected]>
Copy link
Contributor

@akonradi akonradi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to review plenty of the code but flushing comments for now

tools/api_proto_breaking_change_detector/BUILD Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/buf_utils.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/buf_utils.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/buf_utils.py Outdated Show resolved Hide resolved
buf_args = _generate_buf_args(target_path, config_file_loc, additional_args)

update_code, _, update_err = run_command(f'{buf_path} mod update')
# for some reason buf prints out the "downloading..." lines on stderr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can capture or redirect stderr if that's useful?

tools/api_proto_breaking_change_detector/buf_utils.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/buf_utils.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/detector.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/detector.py Outdated Show resolved Hide resolved
Signed-off-by: Yaseen Alkhafaji <[email protected]>
Signed-off-by: Yaseen Alkhafaji <[email protected]>
@YaseenAlk
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17793 (comment) was created by @YaseenAlk.

see: more, trace.

Signed-off-by: Yaseen Alkhafaji <[email protected]>
Signed-off-by: Yaseen Alkhafaji <[email protected]>
@YaseenAlk
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17793 (comment) was created by @YaseenAlk.

see: more, trace.

@adisuissa adisuissa self-assigned this Aug 24, 2021
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!
Left a few high-level comments

tools/api_proto_breaking_change_detector/detector.py Outdated Show resolved Hide resolved
@@ -1,28 +1,48 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")

licenses(["notice"]) # Apache 2

py_binary(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should also have detector_ci.py here.

tools/api_proto_breaking_change_detector/detector.py Outdated Show resolved Hide resolved
Copy link
Contributor

@akonradi akonradi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to re-review once the changes to remove lock file support are made

tools/api_proto_breaking_change_detector/BUILD Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/buf_utils.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/detector_ci.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/detector_test.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/detector_test.py Outdated Show resolved Hide resolved
tools/api_proto_breaking_change_detector/detector_test.py Outdated Show resolved Hide resolved
tools/base/utils.py Show resolved Hide resolved
@@ -374,6 +374,16 @@ elif [[ "$CI_TARGET" == "bazel.api" ]]; then
echo "Testing API boosting (golden C++ tests)..."
# We use custom BAZEL_BUILD_OPTIONS here; the API booster isn't capable of working with libc++ yet.
BAZEL_BUILD_OPTIONS="${BAZEL_BUILD_OPTIONS[*]}" python3.8 "${ENVOY_SRCDIR}"/tools/api_boost/api_boost_test.py
echo "Building buf..."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend moving this to a bazel.api_compat target and CI job. We can then turn this on as an optional GitHub check, which will make it an active part of the ongoing review process. If we see false positives or need to override, it won't block developer velocity, and ideally we can tune them. At some point it can become a mandatory check and senior maintainers can override as needed.

WDYT @lizan @phlax @mattklein123?

I'm very excited to see this land and think this will be immeasurably valuable in avoiding costly breaking changes that hurt the ecosystem. It will also free up bandwidth of @envoyproxy/api-shepherds to focus on things other than breaking changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure SGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what adding a new CI job entails on the azure/github side but I modified .azure-pipelines/pipelines.yml to add api_compat under api for the bazel job of the check stage. if I need to do anything else, let me know

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the new CI check, and it seems to be failing as expected.

Signed-off-by: Yaseen Alkhafaji <[email protected]>
@YaseenAlk
Copy link
Contributor Author

this should be ready for a second review! @adisuissa @akonradi

akonradi
akonradi previously approved these changes Aug 27, 2021
Copy link
Contributor

@akonradi akonradi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one nit.

@@ -374,6 +374,16 @@ elif [[ "$CI_TARGET" == "bazel.api" ]]; then
echo "Testing API boosting (golden C++ tests)..."
# We use custom BAZEL_BUILD_OPTIONS here; the API booster isn't capable of working with libc++ yet.
BAZEL_BUILD_OPTIONS="${BAZEL_BUILD_OPTIONS[*]}" python3.8 "${ENVOY_SRCDIR}"/tools/api_boost/api_boost_test.py
echo "Building buf..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the new CI check, and it seems to be failing as expected.

tools/api_proto_breaking_change_detector/detector.py Outdated Show resolved Hide resolved
adisuissa
adisuissa previously approved these changes Aug 27, 2021
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@adisuissa
Copy link
Contributor

Please add a comment on why api_compat is failing for this PR.

api/buf.yaml Outdated
@@ -1,13 +1,19 @@
version: v1beta1
deps:
- buf.build/beta/googleapis

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this protobuf module has been deprecated in favor of buf.build/googleapis/googleapis. I think it'd be good to update it now before merging this as changing the dependency later can be annoying for downstream dependents.

@YaseenAlk
Copy link
Contributor Author

@htuch this should be ready for one last review from you! the api_compat check will fail until we merge in necessary buf config files into the main branch (e.g. buf.lock file), because buf is trying to compile the API proto files on the main branch without proper configuration. I will also monitor other PRs today to make sure it starts passing and I can try to make a quick fix if something else is wrong

initial_state_input += f',subdir={subdir}'

final_code, final_out, final_err = run_command(
' '.join([buf_path, f"breaking --against {initial_state_input}", *buf_args]))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, if you actually want to parse this output (I see it's not really being parsed here) you can use --error-format=json to get structured results.

@YaseenAlk
Copy link
Contributor Author

actually hold on, going to push one more change to update buf version and adjust BSR dependencies that @johanbrandhorst recommended

@YaseenAlk
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17793 (comment) was created by @YaseenAlk.

see: more, trace.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Look forward to working with this and iterating. Great accomplishment for the internship!

@htuch
Copy link
Member

htuch commented Aug 27, 2021

/lgtm deps

@repokitteh-read-only repokitteh-read-only bot removed the deps Approval required for changes to Envoy's external dependencies label Aug 27, 2021
@htuch htuch merged commit f30c289 into envoyproxy:main Aug 27, 2021
@htuch
Copy link
Member

htuch commented Aug 27, 2021

@envoyproxy/maintainers @phlax this may cause issues in CI or PRs; presumably not given its an optional check, but just flagging it in case. Please rollback if there is a genuine CI breakage (i.e. modulo the optional api_compat check).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants