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

SOLR-14673: Add bin/solr stream CLI #2479

Merged
merged 49 commits into from
Nov 13, 2024
Merged

SOLR-14673: Add bin/solr stream CLI #2479

merged 49 commits into from
Nov 13, 2024

Conversation

epugh
Copy link
Contributor

@epugh epugh commented May 25, 2024

https://issues.apache.org/jira/browse/SOLR-14673

Description

Bring in code that @joel-bernstein wrote, but using the SolrCLI infrastructure. The original code is a patch in the associated JIRA.

Solution

Another CLI client ;-)

Tests

Copied over the basic tests from the patch. I still need to write an integration style test and ideally one that exercies the basic auth.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

@github-actions github-actions bot added the documentation Improvements or additions to documentation label May 28, 2024
@gerlowskija
Copy link
Contributor

gerlowskija commented Jun 3, 2024

A few high-level questions/concerns:

  1. bin/solr already has an "api" tool, which can be used to invoke streaming expressions e.g. bin/solr api -get "$SOLR_URL/techproducts/stream?expr=search(techproducts)". I'm all for syntactic-sugar, but I wonder whether this is worth the maintenance cost if the main thing that it "buys" us is saving people from having to provide the full API path as the "api" tool requires?

  2. If I'm reading the PR correctly, it looks like one other capability of the proposed bin/solr stream tool is that it can evaluate streams "locally" in some cases i.e. without a full running Solr. Which is pretty cool - you could imagine a real super-user doing some pretty involved ETL that builds off of an expression like: update(techproducts, unique(cat(...))).

    But I'd worry about some of the documentation challenges surrounding this. For instance, how would a user know which expressions can be run locally, and which require a Solr to execute on? For expressions that have a mix of both locally and remotely-executed clauses, is there any way for a user to know which clauses are executed where?

    To clarify - I think the upside here is pretty cool, I'm just worried that upside is hard to realize without some extensive work on the documentation end to make it usable by folks in practice.

@epugh
Copy link
Contributor Author

epugh commented Jun 5, 2024

Thanks for sharing the feedback @gerlowskija ! I think the value of the tool is only there if your second comment about being able to run a streaming expression locally is valid, and then having it do what yoru first comment highlights falls out easy, otherwise it really is a thin wrapper/duplication of the bin/solr api call. Especially without any special value add in formatting tuples or error handling etc.

I do believe the second part is the really cool thing, that I can run a streaming expression locally and use it to process some data.

We clearly need some way of specifying where the processing is happening, in the cluster or locally. I was trying to think if we have any other places in Solr where we define "Where am I doing work" that might provide a name for a parameter. bin/solr stream --environment cluster BLAH ? The search() expression has a qt parameter.. bin/solr stream -qt=/stream BLAH ?

Reading through docs more, we have the parralel() and it refers to workers. Maybe the command should be something like bin/solr stream --workers=local BLAH which would run on your laptop, and if you don't specify --workers then it runs on the cluster via /stream?

I have found that lots of streaming expressions don't require a Solr connection, especially during development. I'm just iterating on the logic, and I'm starting and ending iwth tuples.. it's only later when I get the mappings etc working that I then move to adding in my search() or update() clauses.

Also, as far as docs go, we have a LONG way to go in Streaming expressions. It's both the best docuemnted code, with all the howtos and guides, but also, I find a million expressions that exist but don't show up in our reference docs ;-).

epugh added 3 commits June 20, 2024 09:16
I went with the plural name --workers solr, and then you pass in a collection.   However, I could imagine that this becomes --workers my_collection,films,worker_collection on your local solr...    Not quite sure what passing more then one in means however...
@epugh epugh marked this pull request as ready for review June 20, 2024 13:39
@epugh
Copy link
Contributor Author

epugh commented Aug 10, 2024

@gerlowskija since you provided some early review, do you think the docs I've added etc are enough that I can merge this in?

@epugh epugh requested a review from gerlowskija September 12, 2024 13:34
Copy link
Contributor

@gerlowskija gerlowskija 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 those added docs @epugh . They're a huge help, and I suggested a few tweaks that might help even more.

One remaining question I have - wdyt about marking the tool syntax as "experimental" in some way? Seeing all the hard work you've put into improving syntax on the other tools, and considering that we might not notice some rough edges to the syntax of this tool until it's out in the wild a bit...might be prudent to give this script equivalent of "@lucene.experimental" so that we wouldn't need to worry about backcompat if we want to make any future tweaks?

The Stream tool allows you to run a xref:streaming-expressions.adoc[] and see the results from the command line.
It is very similar to the xref:stream-screen.adoc[], but is part of the `bin/solr` CLI.

To run it, open a window and enter:
Copy link
Contributor

Choose a reason for hiding this comment

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

[0] "window" -> "terminal" or maybe "shell"?

-u,--credentials <credentials> Credentials in the format username:password. Example: --credentials solr:SolrRocks
-url,--solr-url <HOST> Base Solr URL, which can be used to determine the zk-host if that's not known;
defaults to: http://localhost:8983.
-e,--execution <CONTEXT> Execution context is either 'local' or 'solr'. Default is 'solr'
Copy link
Contributor

@gerlowskija gerlowskija Sep 16, 2024

Choose a reason for hiding this comment

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

[0] I don't love this terminology, but I don't have anything better in mind (yet). "Local" to me could be misconstrued by folks running 'bin/solr' on a box that also happens to have Solr running.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thoughts on:

Execution context is either 'local' (i.e CLI process) or 'solr'.

Copy link
Contributor

Choose a reason for hiding this comment

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

I noodled on this a bit but still couldn't come up with anything I liked better, so maybe you picked the best option. +1 for the current enum values with the "(i.e. CLI process)" clarification you suggested.


Caveats:

* You don't get to use any of the parallelization support that is available when you run the expression on the cluster.
Copy link
Contributor

Choose a reason for hiding this comment

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

[Q] Is this only a limitation of --execution=local is specified?

Hello World
----

This also works with a `.expr` files.
Copy link
Contributor

Choose a reason for hiding this comment

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

[0] "also works with a .expr files." -> "also works when using .expr files."

)
----

Running this expression will read in the local file and send the first two lines to the collection `gettingstarted`.
Copy link
Contributor

Choose a reason for hiding this comment

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

[0] Might be worth hitting this point a little more strongly: even "local" processing is likely to reach out to a remote host.

Maybe something like:

All streaming expressions are processed "locally" if that execution mode is selected.
However, "local" processing does not imply a networking sandbox.
Many streaming expressions, such as search and update, will make network requests to remote Solr nodes if configured to do so, even in "local" execution mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, I took a stab at it... If I didn't quite nail it, please edit it but with myabe the suggestion thing?

== Using the bin/solr stream Tool

NOTE: The Stream Tool is classified as "experimental".
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth putting this at the top of the page. Seems a little "buried" as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

love it

Copy link
Contributor

@gerlowskija gerlowskija left a comment

Choose a reason for hiding this comment

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

LGTM.

Left one last comment about the "experimental" designation, but feel free to ignore.

@epugh epugh changed the base branch from main to branch_9x November 8, 2024 12:36
@epugh epugh changed the base branch from branch_9x to main November 8, 2024 12:36
Copy link
Contributor

@malliaridis malliaridis left a comment

Choose a reason for hiding this comment

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

I'll try the stream command next, but here are a few points to look into while I'm trying stream expressions out. :)

solr/core/src/java/org/apache/solr/cli/StreamTool.java Outdated Show resolved Hide resolved
solr/core/src/java/org/apache/solr/cli/StreamTool.java Outdated Show resolved Hide resolved
solr/core/src/java/org/apache/solr/cli/StreamTool.java Outdated Show resolved Hide resolved
Comment on lines 153 to 169
LineNumberReader bufferedReader = null;
String expr;
try {
Reader inputStream =
expressionArgument.toLowerCase(Locale.ROOT).endsWith("expr")
? new InputStreamReader(
new FileInputStream(expressionArgument), Charset.defaultCharset())
: new StringReader(expressionArgument);

bufferedReader = new LineNumberReader(inputStream);
expr = StreamTool.readExpression(bufferedReader, cli.getArgs());
echoIfVerbose("Running Expression: " + expr);
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a lot happening in the runImpl, maybe extracting the two blocks into separate private methods would keep a better overview? (this is block no 1)

solr/core/src/java/org/apache/solr/cli/StreamTool.java Outdated Show resolved Hide resolved
public static String[] getOutputFields(CommandLine cli) {
if (cli.hasOption("fields")) {

String fl = cli.getOptionValue("fields");
Copy link
Contributor

Choose a reason for hiding this comment

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

Use option object instead for consistency.

solr/core/src/java/org/apache/solr/cli/StreamTool.java Outdated Show resolved Hide resolved
solr/benchmark/.factorypath Outdated Show resolved Hide resolved
Comment on lines +227 to +231

@SuppressWarnings({"rawtypes"})
public Map getLetParams() {
return this.letParams;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This method has no usage, is it needed? And if so, should we not simply add the types to Map<String, Object> rather than suppressing them?

@malliaridis
Copy link
Contributor

malliaridis commented Nov 8, 2024

A few more notes:

  • bin/solr stream --help does not include any reference to the stream expression argument required at position 0 (or any other position that is valid)
  • When providing an invalid stream expression, error message is not helpful
     bin\solr.cmd stream "search(q=*:*)" -e local -s http://localhost:8983 -c techproducts
    (missing collection in expression) returns "Unable to construct instance of org.apache.solr.client.solrj.io.stream.SearchFacadeStream"
    • I would like a message that at least says something like "double check your stream expression" if it is one of the causes
  • For my understanding, is it a technical limitation that -e local does not require a collection (-c), but -e solr requires one?
  • I also noticed that providing -s requires a URI scheme, but -z does not allow one. Is this inconsistency for all commands?

@epugh
Copy link
Contributor Author

epugh commented Nov 13, 2024

@gerlowskija @malliaridis What do you think about using the word "environment" versus "context" for the option you pass for execution? I.e, your environment is either local or solr... Context to me means more like "this is athing that you set up that has lots of variables".... "enviroment" is where you run it...?

@epugh
Copy link
Contributor Author

epugh commented Nov 13, 2024

Leaning towards "execution" and either "local" or "remote".

@epugh
Copy link
Contributor Author

epugh commented Nov 13, 2024

@malliaridis in reference to your question, yeah -z never has a scheme, but -s always does. Why exactly, not totally sure.. I guess that ZK communciates over same port regardless of ssl or not?

@epugh epugh merged commit 4b9e539 into apache:main Nov 13, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants