Skip to content

Comments

proto doc: support file level 'not-implemented-hide' annotation#18923

Merged
phlax merged 7 commits intoenvoyproxy:mainfrom
wbpcode:hide-noimplemented-doc
Dec 30, 2021
Merged

proto doc: support file level 'not-implemented-hide' annotation#18923
phlax merged 7 commits intoenvoyproxy:mainfrom
wbpcode:hide-noimplemented-doc

Conversation

@wbpcode
Copy link
Member

@wbpcode wbpcode commented Nov 6, 2021

Commit Message: proto doc: support file level 'not-implemented-hide' annotation
Additional Description:

Ref #18841 for more background info.

Risk Level: Low.
Testing: N/A.
Docs Changes: N/A.
[Optional Fixes #Issue] #18841

wbpcode added 3 commits November 5, 2021 16:33
@wbpcode
Copy link
Member Author

wbpcode commented Nov 6, 2021

I am not familiar with protodoc. But I still hava a try in my local env. My initial idea was to completely hide the document with the file level 'not-implemented-hide' annotation. But I failed. 😞

In the end, I had to choose a compromise. If there is a 'not-implemented-hide' annotation, I simply ignore all messages and return a result containing only the warning info.

So, if there is a better solution, feel free to close this PR.

@wbpcode
Copy link
Member Author

wbpcode commented Nov 6, 2021

cc @phlax @htuch

@htuch
Copy link
Member

htuch commented Nov 7, 2021

It's probably reasonable to do it this way. Can you share a link to some generated docs with the output? Doesn't look like this is used yet.

@htuch htuch self-assigned this Nov 7, 2021
@wbpcode
Copy link
Member Author

wbpcode commented Nov 8, 2021

@htuch, in fact, some APIs already use file-level annotations (although they are used incorrectly #18924 ). So we can see the final effect based on these APIs.

image

@phlax
Copy link
Member

phlax commented Nov 8, 2021

'breaking changes. Do not use this feature without understanding each of the previous '
'points.\n\n')

FILE_LEVEL_NOT_IMPLEMENTED = (
Copy link
Member

Choose a reason for hiding this comment

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

im wondering whether we want a message, or rather no page at all

Copy link
Member Author

@wbpcode wbpcode Nov 8, 2021

Choose a reason for hiding this comment

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

My initial idea was to completely hide the document (no page at all). But the protoc plugin always need a output. 😞

Copy link
Member

Choose a reason for hiding this comment

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

ah, i see the comments above now

wondering if there is a way around this as it seems messy to include empty/hidden pages

Copy link
Member

Choose a reason for hiding this comment

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

what about hacking api_proto_plugin/plugin.py to bail if its an empty proto file ?

Copy link
Member Author

@wbpcode wbpcode Nov 9, 2021

Choose a reason for hiding this comment

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

I have tried this approach. I skip the output file generating or return output file with empty content. But I still failed. Perhaps because I am not familiar with this tool yet, there are other better methods. But I cannot be sure at the moment. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

there is already a situation in which the proto plugin skips certain files - see here:

if not file_proto.package.startswith('envoy.'):
continue

i may be wrong, but i think we can do something similar for hidden proto files

Copy link
Member Author

Choose a reason for hiding this comment

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

@phlax it not works.

If it's independent API (not link in any doc tree):

/tmp/tmpqc31del1/generated/rst/api-v3/service/endpoint/v3/leds.proto.rst: WARNING: document isn't included in any toctree

If it's normal API:

/tmp/tmpqc31del1/generated/rst/api-v3/config/filter/network/network.rst:4: WARNING: toctree contains reference to document 'api-v3/extensions/filters/network/echo/v3/echo.proto' that doesn't have a title: no link will be generated

@wbpcode
Copy link
Member Author

wbpcode commented Nov 9, 2021

/retest

@repokitteh-read-only
Copy link

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

🐱

Caused by: a #18923 (comment) was created by @wbpcode.

see: more, trace.

htuch pushed a commit that referenced this pull request Nov 9, 2021
Remove the unnecessary file level 'not-implemented-hide' annotation. I found these annotations during the development of PR #18923 . But it seems that they should not have this annotation.

If this is a misunderstanding on my part, please close this PR.

Risk Level: Doc Only.
Testing: N/A.
Docs Changes: N/A.
Release Notes: N/A.

Signed-off-by: wbpcode <[email protected]>
@htuch
Copy link
Member

htuch commented Nov 9, 2021

OK, this generally makes sense. I'm also curious if we could generate an empty file and just not copy that into the docs tree and skip linking?

@phlax
Copy link
Member

phlax commented Nov 9, 2021

...also curious if we could generate an empty file and just not copy that into the docs tree and skip linking?

only with what is done here - adding an orphan tag - otherwise sphinx will complain about superfluous pages

@htuch
Copy link
Member

htuch commented Nov 9, 2021

Yeah, maybe just an orphan tag then.

@wbpcode
Copy link
Member Author

wbpcode commented Nov 10, 2021

OK, this generally makes sense. I'm also curious if we could generate an empty file and just not copy that into the docs tree and skip linking?

This is a good idea. But I am not sure how to skip linking. 🤔 It seems that we need to update .rst index file in the /docs. It would make this approach more complex. For example:

Network filters
===============

.. toctree::
  :glob:
  :maxdepth: 2

  */empty/*
  */hide something/*
  ../../../extensions/filters/network/*/v3*/*

@wbpcode
Copy link
Member Author

wbpcode commented Nov 12, 2021

@htuch @phlax I made a few additional attempts, but they all failed.

If I skip whole .rst file generation of API proto, then there are some errors as follow:

ERROR: /build/tmp/_bazel_envoybuild/b570b5ccd0454dc9af9f65ab1833764d/external/envoy_api/envoy/service/discovery/v3/BUILD:7:18: protodoc external/envoy_api/envoy/service/discovery/v3/pkg/envoy/service/discovery/v3/ads.proto.rst failed: not all outputs were created or valid

If I return empty file or file only contains orphan tag, then there are some errors as follow:

/tmp/tmpn552h80o/generated/rst/api-v3/config/filter/network/network.rst:4: WARNING: toctree contains reference to document 'api-v3/extensions/filters/network/direct_response/v3/config.proto' that doesn't have a title: no link will be generated

@phlax
Copy link
Member

phlax commented Nov 12, 2021

i think the former way of not producing the file at all is preferable, but not sure exactly what is required to make it work

can i suggest just building the rst files and linking to it (the tarball) here - that way we can see what protodoc produces, and what sphinx tries to build from

@wbpcode
Copy link
Member Author

wbpcode commented Nov 12, 2021

i think the former way of not producing the file at all is preferable, but not sure exactly what is required to make it work

can i suggest just building the rst files and linking to it (the tarball) here - that way we can see what protodoc produces, and what sphinx tries to build from

protoc will create a .rst file for every proto file and this file will be linked to some .rst index in the /docs. The generated .rst file contains optional tags (orphan), as well as title, warnings, comments, and json formated proto msgs.

@phlax
Copy link
Member

phlax commented Nov 12, 2021

...file and this file will be linked to some .rst index in the /docs...

yep, and before sending these generated/collated rst files to sphinx, an rst.tar is created - you can build this directly like so...

$ bazel build //docs:rst

it would be helpful to look at what is inside this to figure out a way forward

... contains optional tags (orphan), as well as...

given that the way of adding an orphan tag etc isnt working out of the box, i would suggest focusing on not including the page at all

my reading of api_proto_plugin/plugin.py is that it seems possible to skip some proto files, but i forget exactly how protoc works in this respect

if we really cant get protoc/protodoc/api_proto_plugin to skip some files as desired then one option is to make the file empty and have the //docs:api_rst target strip out empty files

@wbpcode
Copy link
Member Author

wbpcode commented Nov 12, 2021

you can build this directly like so...

I get it and has done it. Thanks. But I still cannot find a way to solve our current problem. 🤣

my reading of api_proto_plugin/plugin.py is that it seems possible to skip some proto files

I am not sure, but may be we can filter the proto targets at the beginning.

if we really cant get protoc/protodoc/api_proto_plugin to skip some files as desired then one option is to make the file empty and have the //docs:api_rst target strip out empty files

This is also a possible idea. 🤔

@phlax
Copy link
Member

phlax commented Nov 12, 2021

I am not sure, but may be we can filter the proto targets at the beginning.

i think we have to parse with protoc to get the annotations, but im wondering whether we can return empty and skip - if not i guess its plan b with stripping empty files

@wbpcode
Copy link
Member Author

wbpcode commented Nov 12, 2021

I am not sure, but may be we can filter the proto targets at the beginning.

i think we have to parse with protoc to get the annotations, but im wondering whether we can return empty and skip - if not i guess its plan b with stripping empty files

But what if instead of using annotations, we aggregate the proto that needs to be skipped individually and then filter it out when we need to generate the document. Wouldn't that work?

I thought about it a bit more. Not too good. 😞

@phlax
Copy link
Member

phlax commented Nov 12, 2021

But what if instead of using annotations, we aggregate the proto that needs to be skipped individually and then filter it out when we need to generate the document. Wouldn't that work?

hmm, well, mho is that anything other than using protoc to parse and then act accordingly is a bit too automagic and best avoided

@htuch
Copy link
Member

htuch commented Nov 12, 2021

I think we can just do a custom docs copy phase that take 0 byte length files and drops them. Then we just need to have these hidden pages get turned into 0 bytes. It's a bit magical, but not that unintuitive; there aren't any valid use cases for rendering a completely blank page in the API docs.

@rojkov
Copy link
Member

rojkov commented Nov 16, 2021

/wait-any

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale stalebot believes this issue/PR has not been touched recently label Dec 16, 2021
Signed-off-by: wbpcode <[email protected]>
@wbpcode
Copy link
Member Author

wbpcode commented Dec 21, 2021

@phlax @htuch Sorry for the delayed update. It just dawned on me today that skipping empty files is very simple. 🤣

@phlax phlax self-assigned this Dec 21, 2021
@phlax phlax removed the stale stalebot believes this issue/PR has not been touched recently label Dec 21, 2021
@wbpcode wbpcode requested a review from phlax December 27, 2021 09:44
htuch
htuch previously approved these changes Dec 30, 2021
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. Yeah, this is what I thought it might look like. @phlax PTAL and merge if you don't see an issue.

continue

# Skip copying empty files.
if (os.path.getsize(rst_file_path) == 0):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (os.path.getsize(rst_file_path) == 0):
if os.path.getsize(rst_file_path) == 0:

Copy link
Member Author

Choose a reason for hiding this comment

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

get it. i will create new commit for it.

Signed-off-by: wbpcode <[email protected]>
Copy link
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 @wbpcode

@phlax phlax merged commit e79ceba into envoyproxy:main Dec 30, 2021
joshperry pushed a commit to joshperry/envoy that referenced this pull request Feb 13, 2022
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.

4 participants