-
Notifications
You must be signed in to change notification settings - Fork 819
SOLR-18055 Use solr.ssl.enabled property for url scheme detection #4272
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
base: main
Are you sure you want to change the base?
Changes from all commits
b036676
deba3e4
d362ed8
a5ec761
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,8 +1,15 @@ | ||||
| # See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc | ||||
| title: Improved CloudSolrClient's urlScheme detection by using the scheme of provided Solr URLs, or looking at "solr.ssl.enabled". | ||||
| title: Improved url scheme detection in client API and core components | ||||
| type: changed | ||||
| authors: | ||||
| - name: Vishnu Priya Chandra Sekar | ||||
| links: | ||||
| - name: SOLR-18056 | ||||
| url: https://issues.apache.org/jira/browse/SOLR-18056 | ||||
| - name: SOLR-18055 | ||||
| url: https://issues.apache.org/jira/browse/SOLR-18055 | ||||
| important_notes: | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the first I've seen of this... and you are the first to attempt to use it :-) Our only references to it thus far don't even truly say what it's for. Well the "deprecated" part does... albeit I think I said it's premature to deprecate that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, there is no other field I could use for.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. multiple sentences if fine: Line 66 in a1df852
|
||||
| - Improved CloudSolrClient's urlScheme detection by using the scheme of provided Solr URLs, or looking at "solr.ssl.enabled". | ||||
| - Improved ZkStateReader's urlScheme detection by giving higher precedence to "solr.ssl.enabled" over cluster property | ||||
| - Improved HttpShardHandlerFactory's urlScheme detection by giving higher precedence to "solr.ssl.enabled" over explicit configuration (ie., solr.xml) | ||||
| - Deprecated usage of the cluster property for urlScheme in ZkController, ReplicaMutator, SliceMutator, and SystemInfoProvider; these now rely on ClusterStateProvider#getUrlScheme | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| import org.apache.solr.common.cloud.ZkStateReader; | ||
| import org.apache.solr.common.params.ShardParams; | ||
| import org.apache.solr.common.params.SolrParams; | ||
| import org.apache.solr.common.util.EnvUtils; | ||
| import org.apache.solr.common.util.ExecutorUtil; | ||
| import org.apache.solr.common.util.IOUtils; | ||
| import org.apache.solr.common.util.NamedList; | ||
|
|
@@ -107,6 +108,9 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory | |
| // URL scheme to be used in distributed search. | ||
| static final String INIT_URL_SCHEME = "urlScheme"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious; was
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like [1] https://solr.apache.org/guide/solr/latest/configuration-guide/configuring-solr-xml.html
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Thanks for looking into it. |
||
|
|
||
| // system property to enable ssl or tls for communication within Solr | ||
| static final String SOLR_SSL_ENABLED = "solr.ssl.enabled"; | ||
|
|
||
| // The core size of the threadpool servicing requests | ||
| static final String INIT_CORE_POOL_SIZE = "corePoolSize"; | ||
|
|
||
|
|
@@ -225,12 +229,7 @@ private void initReplicaListTransformers(NamedList<?> routingConfig) { | |
| public void init(PluginInfo info) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| NamedList<?> args = info.initArgs; | ||
| // note: the sys prop is only used in testing | ||
| this.scheme = getParameter(args, INIT_URL_SCHEME, System.getProperty(INIT_URL_SCHEME), sb); | ||
| if (this.scheme != null && this.scheme.endsWith("://")) { | ||
| this.scheme = this.scheme.replace("://", ""); | ||
| } | ||
|
|
||
| this.scheme = getUrlScheme(args, sb); | ||
| String strategy = | ||
| getParameter( | ||
| args, "metricNameStrategy", UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY, sb); | ||
|
|
@@ -433,6 +432,31 @@ private String buildUrl(String url) { | |
| return url; | ||
| } | ||
|
|
||
| /** | ||
| * Get url scheme of host | ||
| * | ||
| * <p>Examples: | ||
| * | ||
| * <ul> | ||
| * <li>Returns {@code "https"} when SSL is enabled via configuration. | ||
| * <li>Returns {@code null} when ssl is disabled or no explicit configuration is provided in | ||
| * solr.xml. | ||
| * </ul> | ||
|
Comment on lines
+437
to
+444
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, this is way too much documentation for a private method |
||
| * | ||
| * @return http or https or null | ||
| */ | ||
| private String getUrlScheme(NamedList<?> args, StringBuilder sb) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe prefix with 'init' not 'get' to emphasize this is for initialization and not any method in this class that might want it. On further reflection, there's
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense :) |
||
| final Boolean isSolrSslEnabled = EnvUtils.getPropertyAsBool(SOLR_SSL_ENABLED, null); | ||
| if (isSolrSslEnabled != null) { | ||
| return isSolrSslEnabled ? "https" : "http"; | ||
| } | ||
| String urlScheme = getParameter(args, INIT_URL_SCHEME, System.getProperty(INIT_URL_SCHEME), sb); | ||
| if (urlScheme != null && urlScheme.endsWith("://")) { | ||
| urlScheme = urlScheme.replace("://", ""); | ||
| } | ||
| return urlScheme; | ||
| } | ||
|
|
||
| @Override | ||
| public void initializeMetrics(SolrMetricsContext parentContext, Attributes attributes) { | ||
| solrMetricsContext = parentContext.getChildContext(this); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -995,4 +995,23 @@ public void testFetchLowestSolrVersion_noLiveNodes() throws Exception { | |
| var lowestVersion = reader.fetchLowestSolrVersion(); | ||
| assertFalse("Expected no lowest version when no live nodes exist", lowestVersion.isPresent()); | ||
| } | ||
|
|
||
| public void testGetUrlScheme_validSystemProperty() { | ||
| String expectedUrlScheme = isSSLMode() ? "https" : "http"; | ||
| assertEquals(expectedUrlScheme, fixture.reader.getUrlScheme()); | ||
| } | ||
|
|
||
| public void testGetUrlScheme_noClusterAndSystemProperty() { | ||
| // By default, the base class sets the system property for ssl | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than the flip flop... you could just add an |
||
| if (isSSLMode()) { | ||
| System.clearProperty("solr.ssl.enabled"); | ||
| } | ||
| try { | ||
| assertEquals("http", fixture.reader.getUrlScheme()); | ||
| } finally { | ||
| if (isSSLMode()) { | ||
| System.setProperty("solr.ssl.enabled", "true"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
IMO this has become much more vague to a reader of the changelog who is anyone other than you and me. The "title" label is misleading -- add more sentences.
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.
How about this "Standardize urlScheme detection with precedence for "solr.ssl.enabled" ?