-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically switch jmx/sensor names based on dual read mode and sourc…
…e type (#926) * Differentiate LB metrics between ZK and xDS read flows * dynamically switch jmx/sensor names based on dual read mode and source type * move watcher management logic to a manager class * pass updated dual read mode to watcher callbacks
- Loading branch information
Showing
14 changed files
with
1,129 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
d2/src/main/java/com/linkedin/d2/jmx/D2ClientJmxDualReadModeWatcherManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright (c) 2023 LinkedIn Corp. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.linkedin.d2.jmx; | ||
|
||
import com.linkedin.d2.balancer.LoadBalancerStateItem; | ||
import com.linkedin.d2.balancer.dualread.DualReadModeProvider; | ||
import com.linkedin.d2.balancer.dualread.DualReadStateManager; | ||
import com.linkedin.d2.balancer.properties.ClusterProperties; | ||
import com.linkedin.d2.balancer.properties.ServiceProperties; | ||
import com.linkedin.d2.balancer.properties.UriProperties; | ||
import com.linkedin.d2.balancer.simple.ClusterInfoItem; | ||
import com.linkedin.d2.balancer.simple.SimpleLoadBalancer; | ||
import com.linkedin.d2.balancer.simple.SimpleLoadBalancerState; | ||
import com.linkedin.d2.balancer.strategies.LoadBalancerStrategy; | ||
import com.linkedin.d2.discovery.stores.file.FileStore; | ||
import java.util.function.BiConsumer; | ||
import javax.annotation.Nonnull; | ||
|
||
|
||
/** | ||
* Manage d2 client jmx dual read mode watchers for different types of load balancing related properties. | ||
*/ | ||
public interface D2ClientJmxDualReadModeWatcherManager | ||
{ | ||
|
||
void updateWatcher(SimpleLoadBalancer balancer, BiConsumer<SimpleLoadBalancer, DualReadModeProvider.DualReadMode> callback); | ||
|
||
void updateWatcher(SimpleLoadBalancerState state, BiConsumer<SimpleLoadBalancerState, DualReadModeProvider.DualReadMode> callback); | ||
|
||
void updateWatcher(String serviceName, String scheme, LoadBalancerStrategy strategy, | ||
BiConsumer<LoadBalancerStrategy, DualReadModeProvider.DualReadMode> callback); | ||
|
||
void updateWatcher(String clusterName, ClusterInfoItem clusterInfoItem, | ||
BiConsumer<ClusterInfoItem, DualReadModeProvider.DualReadMode> callback); | ||
|
||
void updateWatcher(String serviceName, LoadBalancerStateItem<ServiceProperties> serviceProperties, | ||
BiConsumer<LoadBalancerStateItem<ServiceProperties>, DualReadModeProvider.DualReadMode> callback); | ||
|
||
void updateWatcherForFileStoreUriProperties(FileStore<UriProperties> uriStore, | ||
BiConsumer<FileStore<UriProperties>, DualReadModeProvider.DualReadMode> callback); | ||
|
||
void updateWatcherForFileStoreClusterProperties(FileStore<ClusterProperties> clusterStore, | ||
BiConsumer<FileStore<ClusterProperties>, DualReadModeProvider.DualReadMode> callback); | ||
|
||
void updateWatcherForFileStoreServiceProperties(FileStore<ServiceProperties> serviceStore, | ||
BiConsumer<FileStore<ServiceProperties>, DualReadModeProvider.DualReadMode> callback); | ||
|
||
void removeWatcherForLoadBalancerStrategy(String serviceName, String scheme); | ||
|
||
void removeWatcherForClusterInfoItem(String clusterName); | ||
|
||
void removeWatcherForServiceProperties(String serviceName); | ||
|
||
|
||
final class D2ClientJmxDualReadModeWatcher<T> implements DualReadStateManager.DualReadModeWatcher | ||
{ | ||
private T _latestJmxProperty; | ||
private final BiConsumer<T, DualReadModeProvider.DualReadMode> _callback; | ||
|
||
D2ClientJmxDualReadModeWatcher(T initialJmxProperty, BiConsumer<T, DualReadModeProvider.DualReadMode>callback) | ||
{ | ||
_latestJmxProperty = initialJmxProperty; | ||
_callback = callback; | ||
} | ||
|
||
public T getLatestJmxProperty() | ||
{ | ||
return _latestJmxProperty; | ||
} | ||
|
||
public void setLatestJmxProperty(T latestJmxProperty) | ||
{ | ||
_latestJmxProperty = latestJmxProperty; | ||
} | ||
|
||
@Override | ||
public void onChanged(@Nonnull DualReadModeProvider.DualReadMode mode) | ||
{ | ||
_callback.accept(_latestJmxProperty, mode); | ||
} | ||
} | ||
} |
Oops, something went wrong.