-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Get Node List in the Cluster
API (#13015)
- Loading branch information
Showing
7 changed files
with
126 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Get Node List in the Cluster | ||
|
||
The OAP cluster is a set of OAP servers that work together to provide a scalable and reliable service. The OAP cluster | ||
supports [various cluster coordinator](../setup/backend/backend-cluster.md) to manage the cluster membership and the | ||
communication. | ||
This API provides capability to query the node list in the cluster from every OAP node perspective. If the cluster | ||
coordinator doesn't work properly, the node list may be incomplete or incorrect. So, we recommend you to check the | ||
node list when set up a cluster. | ||
|
||
This API is used to get the unified and effective TTL configurations. | ||
|
||
- URL, `http://{core restHost}:{core restPort}/status/cluster/nodes` | ||
- HTTP GET method. | ||
|
||
```json | ||
{ | ||
"nodes": [ | ||
{ | ||
"host": "10.0.12.23", | ||
"port": 11800, | ||
"isSelf": true | ||
}, | ||
{ | ||
"host": "10.0.12.25", | ||
"port": 11800, | ||
"isSelf": false | ||
}, | ||
{ | ||
"host": "10.0.12.37", | ||
"port": 11800, | ||
"isSelf": false | ||
} | ||
] | ||
} | ||
``` | ||
|
||
The `nodes` list all the nodes in the cluster. The size of the list should be exactly same as your cluster setup. | ||
The `host` and `port` are the address of the OAP node, which are used for OAP nodes communicating with each other. The | ||
`isSelf` is a flag to indicate whether the node is the current node, others are remote nodes. |
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
71 changes: 71 additions & 0 deletions
71
...plugin/src/main/java/org/apache/skywalking/oap/query/debug/ClusterStatusQueryHandler.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,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.skywalking.oap.query.debug; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.linecorp.armeria.common.HttpRequest; | ||
import com.linecorp.armeria.common.HttpResponse; | ||
import com.linecorp.armeria.common.MediaType; | ||
import com.linecorp.armeria.server.annotation.ExceptionHandler; | ||
import com.linecorp.armeria.server.annotation.Get; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.skywalking.oap.server.core.CoreModule; | ||
import org.apache.skywalking.oap.server.core.remote.client.Address; | ||
import org.apache.skywalking.oap.server.core.remote.client.RemoteClientManager; | ||
import org.apache.skywalking.oap.server.library.module.ModuleManager; | ||
|
||
@Slf4j | ||
@ExceptionHandler(StatusQueryExceptionHandler.class) | ||
public class ClusterStatusQueryHandler { | ||
private final ModuleManager moduleManager; | ||
private RemoteClientManager remoteClientManager; | ||
|
||
public ClusterStatusQueryHandler(final ModuleManager manager) { | ||
this.moduleManager = manager; | ||
} | ||
|
||
private RemoteClientManager getRemoteClientManager() { | ||
if (remoteClientManager == null) { | ||
remoteClientManager = moduleManager.find(CoreModule.NAME) | ||
.provider() | ||
.getService(RemoteClientManager.class); | ||
} | ||
return remoteClientManager; | ||
} | ||
|
||
@Get("/status/cluster/nodes") | ||
public HttpResponse buildClusterNodeList(HttpRequest request) { | ||
JsonObject clusterInfo = new JsonObject(); | ||
|
||
JsonArray nodeList = new JsonArray(); | ||
clusterInfo.add("nodes", nodeList); | ||
getRemoteClientManager().getRemoteClient().stream().map(c -> { | ||
final Address address = c.getAddress(); | ||
JsonObject node = new JsonObject(); | ||
node.addProperty("host", address.getHost()); | ||
node.addProperty("port", address.getPort()); | ||
node.addProperty("isSelf", address.isSelf()); | ||
return node; | ||
}).forEach(nodeList::add); | ||
|
||
return HttpResponse.of(MediaType.JSON_UTF_8, clusterInfo.toString()); | ||
} | ||
|
||
} |
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