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-17611 SolrJ User-Agent, pass Solr version #2927

Merged
merged 9 commits into from
Jan 16, 2025
Merged

Conversation

dsmiley
Copy link
Contributor

@dsmiley dsmiley commented Dec 28, 2024

https://issues.apache.org/jira/browse/SOLR-17611 (read this for context)

No tests. I suppose the best test would be something in the smoke test which is at release time where we definitely have the "specification version" in the JAR manifest. Once we have something that detects the version to behave differently, we will need it to work in a unit test environment too, where we want the latest behavior but don't have a spec version in a manifest.
Maybe the PR should include something in SolrVersion to parse it as well?

@jdyer1
Copy link
Contributor

jdyer1 commented Jan 9, 2025

There are asserts in the unit tests for the user-agent, so changing it will cause failures I think. See HttpSolrClientTestBase#expectedUserAgent. If we put the specification version in a protected static variable, the unit test can easily override it, which might be adequate enough of a unit testing strategy? I was looking around and maybe ByteBuddy's PackageDefinitionStrategy could be used to mock this? Even if possible (I have no idea) I guess that would be more effort than it is worth! I agree something in the smoke tester would be the best way to verify correctness.

public static final String REQ_PRINCIPAL_KEY = "solr-req-principal";
private static final String USER_AGENT =
"Solr["
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this go in the superclass so it doesn't have to exist twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd hate to create constants merely for the parts of this string that we concatenate -- I hate that coding practice, to be blunt. I could see a utility method that composes them. But any way it's tested so I'm not sure what the risk/concern of not doing what you suggest is. This is a one-liner BTW.

return null;
}
try {
return SolrVersion.valueOf(header.substring(header.lastIndexOf(' ') + 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

If this gets an older client it will return 1.0 or 2.0, which can be somewhat misleading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah; I thought it would have no consequence so I did nothing about it. At least by returning a SolrVersion instead of null, we communicate indirectly that it's at least SolrJ. I could add a javadoc comment on 1.0 and 2.0 being used prior to 9.8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this to the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW that method has no callers; isn't tested. I did manually test it. Obviously I intend to have it be used soon.

@dsmiley
Copy link
Contributor Author

dsmiley commented Jan 15, 2025

Ready to merge; will do within a couple days if I hear nothing.

@dsmiley dsmiley merged commit 32aee2d into apache:main Jan 16, 2025
3 of 4 checks passed
@dsmiley dsmiley deleted the userAgent branch January 16, 2025 21:44
dsmiley added a commit that referenced this pull request Jan 16, 2025
SolrJ's HTTP User-Agent header now uses the version of SolrJ (Solr) instead of 1.0 or 2.0.  There's a corresponding HttpSolrCall.getUserAgentSolrVersion to parse it.

(cherry picked from commit 32aee2d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants