api: deprecated version annotation introduction#15564
api: deprecated version annotation introduction#15564htuch merged 22 commits intoenvoyproxy:mainfrom
Conversation
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
|
/retest |
|
Retrying Azure Pipelines: |
htuch
left a comment
There was a problem hiding this comment.
This is really great @adisuissa, matches exactly what we need. @phlax could you take a pass over this from a Python & tools/ perspective?
/wait
phlax
left a comment
There was a problem hiding this comment.
hi @adisuissa
this PR will need a rebase as i have been making quite invasive changes to the py code - apologies for that
overall looks like a very welcome addition - im wondering if we can/should use the rst .. deprecated:: directive - but i guess that is beyond the scope of this PR
…annotation_v2 Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
…annotation_v2 Signed-off-by: Adi Suissa-Peleg <adip@google.com>
|
/retest |
|
Retrying Azure Pipelines: |
phlax
left a comment
There was a problem hiding this comment.
thanks for update - comments inline
| """ | ||
| import generate_api_version_header | ||
| from generate_api_version_header import ApiVersion | ||
| import utils |
There was a problem hiding this comment.
could you move this below the std library imports
tools/api_versioning/utils.py
Outdated
| """Returns the API version from a given API version input file. | ||
|
|
||
| Args: | ||
| input_path: the file containing the API version (API_VERSION). |
There was a problem hiding this comment.
these docstring still need further indenting
|
|
||
| from tools.api_proto_plugin import annotations, traverse, visitor | ||
| import tools.api_versioning.utils as api_version_utils | ||
| from tools.protoxform import options as protoxform_options, utils |
There was a problem hiding this comment.
and move this up one - in general its (sylistically) preferred that from ... import comes after import ... from the same module
There was a problem hiding this comment.
@phlax can we have tooling to automate this? We have custom Python to do this for C++ to enforce Envoy opinionated include order.
There was a problem hiding this comment.
isort is the goto for this altho it might fight with yapf (i think i saw something about compatibility tho)
tools/protoxform/protoprint.py
Outdated
| not protoxform_options.has_hide_option(field_or_evalue.options): | ||
| # If the field or enum value has annotation from deprecation.proto, need to import it. | ||
| if field_or_evalue.options.HasExtension(deprecation_tag) or \ | ||
| field_or_evalue.options.HasExtension(disallowed_tag): |
There was a problem hiding this comment.
think this would be more readable as:
self._needs_deprecation_annotation_import = (
field_or_evalue.options.HasExtension(deprecation_tag)
or field_or_evalue.options.HasExtension(disallowed_tag))similar above although in that case you would need to set a local var - eg
should_do_something = (
field_or_evalue.options.deprecated
and not self._frozen_proto
and not protoxform_options.has_hide_option(field_or_evalue.options)(not sure on the best name for should_do_something - but in a way that is what i want to know)
There was a problem hiding this comment.
This would then set/reset the flag on each invocation (not a flag that is only raised once).
I can do the following:
self._needs_deprecation_annotation_import = (
self._needs_deprecation_annotation_import
or field_or_evalue.options.HasExtension(deprecation_tag)
or field_or_evalue.options.HasExtension(disallowed_tag))
Do you think it's more understandable this way?
…annotation_v2 Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
|
@adisuissa can you merge main? @phlax I think we should stop merging format fixes until this PR merges. |
…annotation_v2 Signed-off-by: Adi Suissa-Peleg <adip@google.com>
htuch
left a comment
There was a problem hiding this comment.
Looks good generally! Couple of minor comments..
tools/api_versioning/utils.py
Outdated
| a namedtuple containing the major, minor, patch versions. | ||
| """ | ||
| lines = pathlib.Path(input_path).read_text().splitlines() | ||
| assert len(lines) == 1 |
There was a problem hiding this comment.
Arguably we shouldn't be asserting on external conditions like file contents, but depends on how "internal" the file is.
There was a problem hiding this comment.
also if this triggers it will raise an assertion error about lengh which might not be that helpful
There was a problem hiding this comment.
I think an assertion/exception is needed in case the API_VERSION file contents are accidentally modified.
I've added a comment to the assertion failure, but let me know if you think it should be removed.
There was a problem hiding this comment.
if you keep it, then add an exception that will be useful when the code runs
with just an assert you would get something like this
>>> assert len([]) == 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionErrorie no useful info
i think you need to use an error that will provide info, eg:
if len(lines) != 1:
raise APIHeaderError("Explanation of what has gone wrong")not sure exactly what kind of error or message is best
There was a problem hiding this comment.
Hmmm, interesting...
I was under the impression that assertion failure also prints the line number. This is what I get at the moment:
Traceback (most recent call last):
File "/home/adip/git/envoy/bazel-bin/tools/protoxform/protoprint.runfiles/envoy/tools/protoxform/protoprint.py", line 733, in <module>
traverse.traverse_file(file_proto, ProtoFormatVisitor(api_version_file_path, frozen_proto)))
File "/home/adip/git/envoy/bazel-bin/tools/protoxform/protoprint.runfiles/envoy/tools/protoxform/protoprint.py", line 586, in __init__
current_api_version = api_version_utils.get_api_version(api_version_file_path)
File "/home/adip/git/envoy/bazel-bin/tools/protoxform/protoprint.runfiles/envoy/tools/api_versioning/utils.py", line 28, in get_api_version
assert len(lines) == 1, 'Api version file must have a single line of format X.Y.Z, where X, Y, and Z are non-negative integers.'
AssertionError: Api version file must have a single line of format X.Y.Z, where X, Y, and Z are non-negative integers.
I don't object using an exception, although there are other errors that may emit an assertion failure (e.g., empty lines), so I'll just add explicit handling of these.
There was a problem hiding this comment.
yep - use a proper exception - its also catchable then
tools/protoxform/protoprint.py
Outdated
| file_proto: FileDescriptorProto for file. | ||
| empty_file: are there no message/enum/service defs in file? | ||
| import_deprecation_proto: should the "envoy/annotation/deprecation.proto" be imported? | ||
| frozen_proto: is the proto file frozen? |
There was a problem hiding this comment.
The logic here is a bit hard to follow; could we have something more descriptive, e.g. has_minor_version_deprecation and then infer these other properties?
tools/protoxform/protoprint.py
Outdated
| return False | ||
| except ValueError: | ||
| return False | ||
| return True |
There was a problem hiding this comment.
Should this belong in utils? Good candidate for unit tests.
There was a problem hiding this comment.
Moved, and added tests.
yep k - apologies @adisuissa - py formatting has been a bit of shifting target and been a merge/rebase nightmare |
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
…annotation_v2 Signed-off-by: Adi Suissa-Peleg <adip@google.com>
…annotation_v2 Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
|
docs are rendered here: https://storage.googleapis.com/envoy-pr/15564/docs/index.html maybe i misunderstand what is included here - or the purpose - but i expected to find some change to the docs re deprecation |
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
…annotation_v2 Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
No worries, I can fix the format if needed (it would just be easier to see the relevant changes if there were no formatting changes needed).
My plan is to add an explanation to |
if we have a way of saying "this feature is deprecated in version X" it would be really helpful to include this in the docs that end users read - im still not sure if i understand the purpose exactly - or whether this provides that |
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
|
/retest |
|
Retrying Azure Pipelines: |
| input_path: the file containing the API version (API_VERSION). | ||
|
|
||
| Returns: | ||
| a namedtuple containing the major, minor, patch versions. |
There was a problem hiding this comment.
Added the Raises clause to the docstring.
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
…annotation_v2 Signed-off-by: Adi Suissa-Peleg <adip@google.com>
I agree that the docs should be updated, once the patch version capabilities will be added (until now the work has mainly added minor version capabilities). @phlax thanks for the thorough review and great comments! |
phlax
left a comment
There was a problem hiding this comment.
lgtm, thanks @adisuissa
im looking forward to getting a better understanding of how we can use in docs
|
/retest |
|
Retrying Azure Pipelines: |
Commit Message: api: deprecated version annotation introduction
Additional Description:
Adding a deprecated API version annotation to deprecated fields and enum values in proto files.
This is part of the work on adding minor/patch versioning work.
Risk Level: Low (adding annotation to existing protos).
Testing: Added and modified tests for the tooling (in
tools/testdata).Docs Changes:
Release Notes:
Platform Specific Features: None