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

Enable service discovery in controller too #8193

Merged

Conversation

dongxiaoman
Copy link
Contributor

@dongxiaoman dongxiaoman commented Feb 11, 2022

Description

Enable controller service auto-discovery in Jersey framework.
Also refactored the Broker's ServiceAutoDiscoveryFeature into a shared class for Pinot

Background

This is following #8107 to enable the service auto-creation in controller too.
It is found out that we may need to hook in new services in Pinot Controllers too.

The context can be found in previous PR, I will copy/paste the same text here for reference:

  1. Main idea is behind mkyong's article in detail in here
  2. Added a property boolean named pinot.controller.service.auto.discovery to enable this behavior

Steps needed to make a class auto-created in PinotController:

  1. Add hk2-metadata-generator module as a dependency in your JAR file
  2. Tag your class with @org.jvnet.hk2.annotations.Service tag
  3. Set pinot.controller.service.auto.discovery=true in your Controller's property config
  4. Make sure your JAR file is loaded in class path(of coz)
  5. (Optional) inject your class instance to other places

Upgrade Notes

Does this PR prevent a zero down-time upgrade? (Assume upgrade order: Controller, Broker, Server, Minion)

  • Yes (Please label as backward-incompat, and complete the section below on Release Notes)

Does this PR fix a zero-downtime upgrade introduced earlier?

  • Yes (Please label this as backward-incompat, and complete the section below on Release Notes)

  • Yes (Please label this PR as release-notes and complete the section on Release Notes)

Release Notes

  • New configuration options: pinot.controller.service.auto.discovery so Jersey services can be created automatically and then later injected to Endpoints.

Documentation

@dongxiaoman dongxiaoman changed the title enable service discovery in controller too Enable service discovery in controller too Feb 11, 2022
@codecov-commenter
Copy link

codecov-commenter commented Feb 11, 2022

Codecov Report

Merging #8193 (9638065) into master (22b17c3) will decrease coverage by 1.19%.
The diff coverage is 33.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #8193      +/-   ##
============================================
- Coverage     71.36%   70.16%   -1.20%     
- Complexity     4308     4311       +3     
============================================
  Files          1623     1624       +1     
  Lines         84365    84369       +4     
  Branches      12657    12658       +1     
============================================
- Hits          60208    59199    -1009     
- Misses        20032    21077    +1045     
+ Partials       4125     4093      -32     
Flag Coverage Δ
integration1 ?
integration2 27.55% <60.00%> (-0.03%) ⬇️
unittests1 67.90% <0.00%> (+0.01%) ⬆️
unittests2 14.27% <0.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../controller/api/ControllerAdminApiApplication.java 89.09% <0.00%> (-3.37%) ⬇️
...ker/api/resources/BrokerEchoWithAutoDiscovery.java 0.00% <0.00%> (ø)
...api/resources/ControllerEchoWithAutoDiscovery.java 0.00% <0.00%> (ø)
...pache/pinot/core/api/AutoLoadedServiceForTest.java 0.00% <0.00%> (ø)
...va/org/apache/pinot/spi/utils/CommonConstants.java 23.63% <ø> (ø)
...pinot/broker/broker/BrokerAdminApiApplication.java 93.02% <100.00%> (ø)
...he/pinot/core/api/ServiceAutoDiscoveryFeature.java 81.81% <100.00%> (ø)
...pinot/minion/exception/TaskCancelledException.java 0.00% <0.00%> (-100.00%) ⬇️
...nverttorawindex/ConvertToRawIndexTaskExecutor.java 0.00% <0.00%> (-100.00%) ⬇️
...e/pinot/common/minion/MergeRollupTaskMetadata.java 0.00% <0.00%> (-94.74%) ⬇️
... and 106 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22b17c3...9638065. Read the comment docs.

@@ -68,8 +69,8 @@
* pinot-integration-tests/src/main/java/org/apache/pinot/broker/integration/tests/BrokerTestAutoLoadedService.java
* </code>
*/
public class BrokerServiceAutoDiscoveryFeature implements Feature {
private static final Logger LOGGER = LoggerFactory.getLogger(BrokerServiceAutoDiscoveryFeature.class);
public class ServiceAutoDiscoveryFeature implements Feature {
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen if we have PinotServiceManager deploying controller/broker/server in the same JVM and all of them trying to load this ServiceAutoDiscoveryFeature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A very good point. I added some code (static boolean) to make sure discovery is done once per JVM, and did the integration test that starts Broker+Controller in the same test.
The result shows that only one of the Broker/Controller can find service properly.
It seems that based on Jersey, Services/Features are isolated per Application (tied to ResourceConfig) level, so if there are two applications, the discovery has to be done twice.

@dongxiaoman dongxiaoman force-pushed the xd-controller-service-discovery branch from 7502ff1 to b28d6dd Compare February 11, 2022 22:43
throws Exception {
String response = sendGetRequest(_controllerBaseApiUrl + "/test/echo/doge");
Assert.assertEquals(response, "doge");
response = sendGetRequest(_brokerBaseApiUrl + "/test/echo/doge");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xiangfu0 the test here will fail if we do initialization only once

@dongxiaoman dongxiaoman force-pushed the xd-controller-service-discovery branch from 31f3b2e to 9638065 Compare February 11, 2022 23:02
startBrokers(1);
startServers(1);

}
Copy link
Member

Choose a reason for hiding this comment

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

I’m surprised the linter passed, there should be a blank line here. We will need to check if checkstyle can catch this.

Copy link
Contributor

Choose a reason for hiding this comment

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

#8197

You triggered my OCD...

@richardstartin
Copy link
Member

High level question: does this affect startup time?

@xiangfu0
Copy link
Contributor

High level question: does this affect startup time?

I think this more comes from each customized Feature implementation?

@richardstartin
Copy link
Member

High level question: does this affect startup time?

I think this more comes from each customized Feature implementation?

Is there a discovery cost?

@dongxiaoman
Copy link
Contributor Author

dongxiaoman commented Feb 14, 2022

@richardstartin the discovery is only tried on the class written in META-INF/hk2-locator/default file. In my example the file contains [org.apache.pinot.broker.write.api.context.WriteApiContextProvider]S. The file is written automatically for the class tagged with @service tag.Based on code reading, it reads from that file and try to load it. There is no "scan blindly" in place, so it should be a fixed small cost.
Strictly speaking, this feature is not "AutoDiscovery", it is something "Loading-In-RunTime-with-Specified-Class-Name-in Resource"

@dongxiaoman dongxiaoman force-pushed the xd-controller-service-discovery branch from 9638065 to 89ebdc0 Compare February 14, 2022 17:31
@richardstartin
Copy link
Member

Great, no concerns my end then.

@dongxiaoman
Copy link
Contributor Author

@xiangfu0 Gentle ping: build and test passed

@richardstartin richardstartin merged commit 561621b into apache:master Feb 15, 2022
xiangfu0 pushed a commit to xiangfu0/pinot that referenced this pull request Feb 23, 2022
* enable service discovery in controller too

* fix spotless check

* extra test to show that initialization are needed twice for two services

* fix checkstyle
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