-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Generate reference links for painless API #22775
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
Conversation
Adds "Appending B. Painless API Reference", a reference of all classes and methods available from Painless. Removes links to java packages because they contain methods that we don't expose and don't contain methods that we do expose (the ones in Augmentation). Instead this generates a list of every class and every exposed method using the same type information available to the interpreter/compiler/whatever-we-call-it. From there you can jump to the relevant docs. Right now you build all the asciidoc files by running ``` gradle generatePainlessApi ``` These files are expected to be committed because we build the docs without running `gradle`. Also changes the output of `Debug.explain` so that it is easy to search for the class in the generated reference documentation. You can also run it in an IDE safely if you pass the path to the directory in which to generate the docs as the first parameter. It'll blow away the entire directory an recreate it from scratch so be careful. And then you can build the docs by running something like: ``` ../docs/build_docs.pl --out ../built_docs/ --doc docs/reference/index.asciidoc --open ``` That is, if you have checked out https://github.com/elastic/docs in `../docs`. Wait a minute or two and your browser will pop open in with all of Elasticsearch's reference documentation. If you go to `http://localhost:8000/painless-api-reference.html` you can see this list. Or you can get there by following the links to `Modules` and `Scripting` and `Painless` and then clicking the link in the paragraphs below titled `Appendix B. Painless API Reference`. I like having these in asciidoc because we can deep link to them from the rest of the guide with constructs like `<<painless-api-reference-Object-hashCode-0>>` and `<<painless-api-reference->>` and we get link checking. Then the only brittle link maintenance bit is the link generation for javadoc. Which sucks. But I think it is important that we link to the methods directly so they are easy to find.
I haven't added the I also am not including all of the generated docs in this PR for now. I'll regenerate after a review. For now I've included some of the generated asciidoc so we can look at it and talk about it. |
@@ -38,23 +38,24 @@ POST /hockey/player/1/_explain | |||
// we have to override it to get a normal shaped response | |||
|
|||
Which shows that the class of `doc.first` is | |||
`org.elasticsearch.index.fielddata.ScriptDocValues$Longs` by responding with: | |||
`org.elasticsearch.index.fielddata.ScriptDocValues.Longs` by responding with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this to match the painless_class
which is what we document in the reference.
@@ -90,19 +92,5 @@ The response looks like: | |||
// TESTRESPONSE[s/\.\.\./"script_stack": $body.error.caused_by.script_stack, "script": $body.error.caused_by.script, "lang": $body.error.caused_by.lang, "caused_by": $body.error.caused_by.caused_by, "reason": $body.error.caused_by.reason/] | |||
// TESTRESPONSE[s/"to_string": ".+"/"to_string": $body.error.caused_by.to_string/] | |||
|
|||
// TODO we should build some javadoc like mashup so people don't have to jump through these hoops. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is this TODO.
worth going to the version that matches the version of Java you are using to | ||
run Elasticsearch just in case. | ||
|
||
include::painless-api-reference/index.asciidoc[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is maintained by hand. Everything in the painless-api-reference
directory, including index.asciidoc
is generated.
Rebuild by running `gradle generatePainlessApi`. | ||
//// | ||
|
||
* [[painless-api-reference-Math]]Math[afterthought]##(link:{java8-javadoc}/java/lang/Math.html#Math[reference])## |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to generate a file per class rather than dump them all in the same file because I thought these files were dense enough as is.
/** | ||
* Utility methods for debugging painless scripts that are accessible to painless scripts. | ||
*/ | ||
public class Debug { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved so it is included in the public javadocs.
this.methods = Collections.unmodifiableMap(methods); | ||
this.getters = Collections.unmodifiableMap(getters); | ||
this.setters = Collections.unmodifiableMap(setters); | ||
} | ||
|
||
public Struct getStruct() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added so we can get the painless_class
from Debug.explain
.
* Thrown by {@link Debug#explain(Object)} to explain an object. Subclass of {@linkplain Error} so it cannot be caught by painless | ||
* scripts. | ||
*/ | ||
public class PainlessExplainError extends Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted so it isn't in the public API.
// Note that it is safe to catch any of the following errors since Painless is stateless. | ||
} catch (Debug.PainlessExplainError e) { | ||
throw convertToScriptException(e, e.getMetadata()); | ||
} catch (PainlessExplainError e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just fix the comment location here.
/** | ||
* Throw an {@link Error} that "explains" an object. | ||
*/ | ||
public static void explain(Object objectToExplain) throws PainlessExplainError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved so it is part of the public API.
I'm thinking at some point of writing a test that validates that the generated documentation is up to date but I wanted to get this up for review now. I'm happy to add the test as part of this PR if someone thinks I should or do it as a followup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks good. I'm wondering if we can improve the asciidoc layout a bit. What do you think of something like this:
for which the asciidoc looks like this:
[[painless-api-reference-AttributedString]]++link:{java8-javadoc}/java/text/AttributedString.html#AttributedString[AttributedString]++::
* [[painless-api-reference-AttributedString-AttributedString-1]]++link:{java8-javadoc}/java/text/AttributedString.html#AttributedString%2Djava.lang.String%2D[AttributedString](<<painless-api-reference-String,`String`>>)++ (link:{java9-javadoc}/java/text/AttributedString.html#AttributedString%2Djava.lang.String%2D[java 9])
* [[painless-api-reference-AttributedString-AttributedString-2]]++link:{java8-javadoc}/java/text/AttributedString.html#AttributedString%2Djava.lang.String%2Djava.util.Map%2D[AttributedString](<<painless-api-reference-String,String>>, <<painless-api-reference-Map,Map>>)++ (link:{java9-javadoc}/java/text/AttributedString.html#AttributedString%2Djava.lang.String%2Djava.util.Map%2D[java 9])
:elasticsearch-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/{version} | ||
:painless-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/painless/lang-painless/{version} | ||
endif::[] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
@@ -63,3 +84,5 @@ include::glossary.asciidoc[] | |||
////// | |||
|
|||
include::redirects.asciidoc[] | |||
|
|||
include::painless-api-reference.asciidoc[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move the include above redirects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
@@ -0,0 +1,17 @@ | |||
["appendix",role="exclude",id="painless-api-reference"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
role="exclude"
means "don't add it to the ToC, but we do want it in the ToC, so that should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. When I first wrote this I was going under the assumption that we didn't want it in the ToC but I'm not really sure why I assumed that...
//// | ||
|
||
* [[painless-api-reference-List]]List[afterthought]##(link:{java8-javadoc}/java/util/List.html#List[reference])## | ||
** [[painless-api-reference-List-add-2]]void link:{java8-javadoc}/java/util/List.html#add%2Dint%2Djava.lang.Object%2D[add](int, def) (link:{java9-javadoc}/java/util/List.html#add%2Dint%2Djava.lang.Object%2D[java 9]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is afterthought
?
I don't want to make clicking on the name of the class jump to the class's javadoc because I think the class level javadoc (as opposed to the method level javadoc) can be a bit confusing. I added that
If we already have a class for this or would prefer to do it in another way I'm fine with whatever works. It looks like the other asciidoc layout change you propose is the |
I didn't know that syntax worked! I thought you'd have to specify a
I found the
I also changed the class name to use a definition list:
and the methods and constructors to use a single |
I think I'll do that.
Cool. That makes sense to me. |
It is confusing and break screen readers.
@jdconrad can you have a look at the changes that I made to the java code here? I don't think the doc generating class is all that interesting, but the rest of the java changes could use a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. LGTM! This is going to be a large improvement for our users, so a huge thanks @nik9000.
I'm genuinely excited to get this in! I'll wait another day in case @clintongormley has more ideas. I believe I've made all the changes he asked for at this point. Thanks for looking at the Java code. I wanted to make sure I wasn't doing anything crazy but I think it is fairly safe because none of this is exposed to the scripts. |
LGTM Nik! Thanks for doing this. I have one remaining question, unsure about it in my own mind (and shouldn't impact this PR). It's a long page and I'm wondering about making it easier to navigate, eg listing the class names at the top with links to the relevant section. Like i say, I'm undecided because users have scroll bars and find-in-this-page anyway, so maybe the extra clutter isn't worth it. |
Yeah, I thought the same thing. My hope is that folks find their way to this page either by deep linking or by find-in-this-page style operations. |
Adds "Appending B. Painless API Reference", a reference of all classes and methods available from Painless. Removes links to java packages because they contain methods that we don't expose and don't contain methods that we do expose (the ones in Augmentation). Instead this generates a list of every class and every exposed method using the same type information available to the interpreter/compiler/whatever-we-call-it. From there you can jump to the relevant docs. Right now you build all the asciidoc files by running ``` gradle generatePainlessApi ``` These files are expected to be committed because we build the docs without running `gradle`. Also changes the output of `Debug.explain` so that it is easy to search for the class in the generated reference documentation. You can also run it in an IDE safely if you pass the path to the directory in which to generate the docs as the first parameter. It'll blow away the entire directory an recreate it from scratch so be careful. And then you can build the docs by running something like: ``` ../docs/build_docs.pl --out ../built_docs/ --doc docs/reference/index.asciidoc --open ``` That is, if you have checked out https://github.com/elastic/docs in `../docs`. Wait a minute or two and your browser will pop open in with all of Elasticsearch's reference documentation. If you go to `http://localhost:8000/painless-api-reference.html` you can see this list. Or you can get there by following the links to `Modules` and `Scripting` and `Painless` and then clicking the link in the paragraphs below titled `Appendix B. Painless API Reference`. I like having these in asciidoc because we can deep link to them from the rest of the guide with constructs like `<<painless-api-reference-Object-hashCode-0>>` and `<<painless-api-reference->>` and we get link checking. Then the only brittle link maintenance bit is the link generation for javadoc. Which sucks. But I think it is important that we link to the methods directly so they are easy to find. Relates to #22720
* master: (47 commits) Remove non needed import use expectThrows instead of manually testing exception Fix checkstyle and a test Update after review Read ec2 discovery address from aws instance tags Invalidate cached query results if query timed out (elastic#22807) Add remaining generated painless API Generate reference links for painless API (elastic#22775) [TEST] Fix ElasticsearchExceptionTests Add parsing method for ElasticsearchException.generateThrowableXContent() (elastic#22783) Improve connection closing in `RemoteClusterConnection` (elastic#22804) Docs: Cluster allocation explain should be on one page Remove DFS_QUERY_AND_FETCH as a search type (elastic#22787) Add repository-url module and move URLRepository (elastic#22752) fix date-processor to a new default year for every new pipeline execution. (elastic#22601) Add tests for top_hits aggregation (elastic#22754) [TEST] Added this for 93a28b0 submitted via elastic#22772 Fix typo in comment in OsProbe.java Add new ruby search library to community clients doc (elastic#22765) RangeQuery WITHIN case now normalises query (elastic#22431) ...
Adds "Appendix B. Painless API Reference", a reference of all classes
and methods available from Painless. Removes links to java packages
because they contain methods that we don't expose and don't contain
methods that we do expose (the ones in Augmentation). Instead this
generates a list of every class and every exposed method using the same
type information available to the
interpreter/compiler/whatever-we-call-it. From there you can jump to
the relevant docs.
Right now you build all the asciidoc files by running
These files are expected to be committed because we build the docs
without running
gradle
.You can also run it in an IDE safely if you pass the path to the
directory in which to generate the docs as the first parameter. It'll
blow away the entire directory an recreate it from scratch so be careful.
And then you can build the docs by running something like:
That is, if you have checked out https://github.com/elastic/docs in
../docs
. Wait a minute or two and your browser will pop open in withall of Elasticsearch's reference documentation. If you go to
http://localhost:8000/painless-api-reference.html
you can see thislist. Or you can get there by following the links to
Modules
andScripting
andPainless
and then clicking the link in the paragraphsbelow titled
Appendix B. Painless API Reference
.I like having these in asciidoc because we can deep link to them from the
rest of the guide with constructs like
<<painless-api-reference-Object-hashCode-0>>
and<<painless-api-reference->>
and we get link checking. Then the onlybrittle link maintenance bit is the link generation for javadoc. Which
sucks. But I think it is important that we link to the methods directly
so they are easy to find.