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

Sermant framework supports route and load balance config based xDS protocol #1605

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds;

import io.sermant.core.service.xds.entity.XdsLbPolicy;

/**
* xDS load balance service
*
* @author daizhenyu
* @since 2024-07-30
**/
public interface XdsLoadBalanceService {
/**
* get lb policy of cluster
*
* @param clusterName cluster name
* @return route rules
*/
XdsLbPolicy getClusterLbPolicy(String clusterName);

/**
* get lb policy of service (base cluster)
*
* @param serviceName service name
* @return route rules
*/
XdsLbPolicy getServiceLbPolicy(String serviceName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds;

import io.sermant.core.service.xds.entity.XdsRoute;

import java.util.List;

/**
* xDS route service
*
* @author daizhenyu
* @since 2024-07-30
**/
public interface XdsRouteService {
/**
* get route rules of service
*
* @param serviceName service name
* @return route rules
*/
List<XdsRoute> getServiceRoute(String serviceName);

/**
* get lb policy of cluster
*
* @param clusterName cluster name
* @return route rules
*/
boolean isLocalityRoute(String clusterName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds.entity;

/**
* XdsCluster corresponds to io.envoyproxy.envoy.config.cluster.v3.Cluster
*
* @author daizhenyu
* @since 2024-08-06
**/
public class XdsCluster {
private String clusterName;

private String serviceName;

private XdsLbPolicy lbPolicy;

private boolean isLocalityLb;

public String getClusterName() {
return clusterName;
}

public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}

public String getServiceName() {
return serviceName;
}

public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public XdsLbPolicy getLbPolicy() {
return lbPolicy;
}

public void setLbPolicy(XdsLbPolicy lbPolicy) {
this.lbPolicy = lbPolicy;
}

public boolean isLocalityLb() {
return isLocalityLb;
}

public void setLocalityLb(boolean localityLb) {
isLocalityLb = localityLb;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds.entity;

import java.util.Map;
import java.util.Set;

/**
* XdsClusterLoadAssigment corresponds to io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment
*
* @author daizhenyu
* @since 2024-08-15
**/
public class XdsClusterLoadAssigment {
private String serviceName;

private String clusterName;

private Map<XdsLocality, Set<ServiceInstance>> localityInstances;

public String getServiceName() {
return serviceName;
}

public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public String getClusterName() {
return clusterName;
}

public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}

public Map<XdsLocality, Set<ServiceInstance>> getLocalityInstances() {
return localityInstances;
}

public void setLocalityInstances(
Map<XdsLocality, Set<ServiceInstance>> localityInstances) {
this.localityInstances = localityInstances;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds.entity;

import io.sermant.core.service.xds.entity.match.MatchStrategy;

import java.util.Map;

/**
* xDS HeaderMatcher
*
* @author daizhenyu
* @since 2024-08-15
**/
public class XdsHeaderMatcher {
private final String name;

private final MatchStrategy matchStrategy;

/**
* parameterized constructor
*
* @param name header name
* @param matchStrategy match strategy
*/
public XdsHeaderMatcher(String name, MatchStrategy matchStrategy) {
this.name = name;
this.matchStrategy = matchStrategy;
}

/**
* the request header matches the route configuration header or not.
*
* @param headers request headers
* @return isMatch
*/
public boolean isMatch(Map<String, String> headers) {
if (headers.containsKey(name)) {
return matchStrategy.isMatch(headers.get(name));
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds.entity;

/**
* xDS HttpConnectionManager
*
* @author daizhenyu
* @since 2024-08-15
**/
public class XdsHttpConnectionManager {
private String routeConfigName;

public String getRouteConfigName() {
return routeConfigName;
}

public void setRouteConfigName(String routeConfigName) {
this.routeConfigName = routeConfigName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds.entity;

/**
* xDS LbPolicy
*
* @author daizhenyu
* @since 2024-08-15
**/
public enum XdsLbPolicy {
/**
* random
*/
RANDOM,
/**
* round_robin
*/
ROUND_ROBIN,
/**
* least_request
*/
LEAST_REQUEST,
/**
* ring_hash
*/
RING_HASH,
/**
* maglev
*/
MAGLEV,
/**
* unrecognized
*/
UNRECOGNIZED;
}
Loading
Loading