Skip to content

api: deprecated version annotation introduction#15564

Merged
htuch merged 22 commits intoenvoyproxy:mainfrom
adisuissa:deprecated_version_annotation_v2
Mar 31, 2021
Merged

api: deprecated version annotation introduction#15564
htuch merged 22 commits intoenvoyproxy:mainfrom
adisuissa:deprecated_version_annotation_v2

Conversation

@adisuissa
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa commented Mar 19, 2021

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

Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
API shepherd assignee is @htuch
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #15564 was opened by adisuissa.

see: more, trace.

@adisuissa
Copy link
Copy Markdown
Contributor Author

The first commit 3ffd898 has the relevant scripts changes (including tests).
The second commit 8f9b997 contains the updates to all protos in api and generated_api_shadow.

Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
@adisuissa
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

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

🐱

Caused by: a #15564 (comment) was created by @adisuissa.

see: more, trace.

Copy link
Copy Markdown
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.

This is really great @adisuissa, matches exactly what we need. @phlax could you take a pass over this from a Python & tools/ perspective?
/wait

Copy link
Copy Markdown
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

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

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>
@adisuissa
Copy link
Copy Markdown
Contributor Author

@htuch, @phlax thanks for the comments!
It should be all set now.

@adisuissa
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

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

🐱

Caused by: a #15564 (comment) was created by @adisuissa.

see: more, trace.

Copy link
Copy Markdown
Member

@phlax phlax 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 update - comments inline

"""
import generate_api_version_header
from generate_api_version_header import ApiVersion
import utils
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you move this below the std library imports

"""Returns the API version from a given API version input file.

Args:
input_path: the file containing the API version (API_VERSION).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and move this up one - in general its (sylistically) preferred that from ... import comes after import ... from the same module

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@phlax can we have tooling to automate this? We have custom Python to do this for C++ to enforce Envoy opinionated include order.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isort is the goto for this altho it might fight with yapf (i think i saw something about compatibility tho)

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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yep wfm

…annotation_v2

Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 25, 2021

@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>
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
Copy link
Copy Markdown
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.

Looks good generally! Couple of minor comments..

a namedtuple containing the major, minor, patch versions.
"""
lines = pathlib.Path(input_path).read_text().splitlines()
assert len(lines) == 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Arguably we shouldn't be asserting on external conditions like file contents, but depends on how "internal" the file is.

Copy link
Copy Markdown
Member

@phlax phlax Mar 26, 2021

Choose a reason for hiding this comment

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

also if this triggers it will raise an assertion error about lengh which might not be that helpful

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

@phlax phlax Mar 29, 2021

Choose a reason for hiding this comment

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

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>
AssertionError

ie 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yep - use a proper exception - its also catchable then

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?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

return False
except ValueError:
return False
return True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this belong in utils? Good candidate for unit tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved, and added tests.

@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 25, 2021

@phlax I think we should stop merging format fixes until this PR merges.

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>
@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 26, 2021

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>
@adisuissa
Copy link
Copy Markdown
Contributor Author

@phlax I think we should stop merging format fixes until this PR merges.

yep k - apologies @adisuissa - py formatting has been a bit of shifting target and been a merge/rebase nightmare

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).

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

My plan is to add an explanation to api/API_VERSIONING.md (see draft: #14943).
I can also update the docs, but not sure where. It seems that the API versioning points to the internal doc.
Another possibility is to add the explanation to this FAQ.

@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 29, 2021

My plan is to add an explanation to api/API_VERSIONING.md

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>
@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 29, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

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

🐱

Caused by: a #15564 (comment) was created by @phlax.

see: more, trace.

htuch
htuch previously approved these changes Mar 30, 2021
Copy link
Copy Markdown
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! @phlax if you're good we can merge this.

input_path: the file containing the API version (API_VERSION).

Returns:
a namedtuple containing the major, minor, patch versions.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Throws docsstring

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>
@adisuissa
Copy link
Copy Markdown
Contributor Author

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

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).
Moreover, we'll need to clarify which deprecated fields are no longer supported in a specific version.

@phlax thanks for the thorough review and great comments!

Copy link
Copy Markdown
Member

@phlax phlax 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

im looking forward to getting a better understanding of how we can use in docs

@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 30, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

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

🐱

Caused by: a #15564 (comment) was created by @phlax.

see: more, trace.

Copy link
Copy Markdown
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!

@htuch htuch merged commit 5a8bfa2 into envoyproxy:main Mar 31, 2021
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.

3 participants