Skip to content

Commit

Permalink
Merge pull request #134 from jd-opensource/131-service-registration-a…
Browse files Browse the repository at this point in the history
…dds-startup-time-weight-and-warm-up-settings

Service registration adds startup time, weight, and warm-up settings
  • Loading branch information
hexiaofeng authored Nov 3, 2024
2 parents 436db22 + 3b4a367 commit 67790b8
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,23 @@ public interface Constants {
*/
String LABEL_SERVICE_CONSUMER = LABEL_SERVICE_PREFIX + "consumer";

/**
* Key for the timestamp property of the endpoint.
*/
String LABEL_TIMESTAMP = "timestamp";
/**
* Key for the weight property of the endpoint.
*/
String LABEL_WEIGHT = "weight";
/**
* Key for the warmup period property of the endpoint.
*/
String LABEL_WARMUP = "warmup";

/**
* Default value for labels.
*/
String DEFAULT_VALUE = "";

}

Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class AppService {
*/
private String protocol;

private Integer weight;

private Integer warmupDuration;

/**
* Metadata associated with the service.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,16 @@ public class Application {
@Setter
private volatile AppStatus status = AppStatus.STARTING;

@Setter
private Long timestamp;

/**
* Default constructor initializes the process ID and instance with a unique application ID.
*/
public Application() {
this.pid = pid();
this.instance = APP_ID;
this.timestamp = System.currentTimeMillis();
}

/**
Expand Down Expand Up @@ -204,6 +208,7 @@ public void labelSync(BiConsumer<String, String> consumer) {
private void labelInstance(BiConsumer<String, String> consumer) {
accept(consumer, Constants.LABEL_APPLICATION, name);
accept(consumer, Constants.LABEL_INSTANCE_ID, instance);
accept(consumer, Constants.LABEL_TIMESTAMP, timestamp == null ? null : String.valueOf(timestamp));
}

/**
Expand All @@ -214,9 +219,9 @@ private void labelInstance(BiConsumer<String, String> consumer) {
*/
private void labelService(BiConsumer<String, String> consumer, boolean group) {
if (service != null) {
if (group) {
accept(consumer, Constants.LABEL_SERVICE_GROUP, service.getGroup());
}
accept(consumer, Constants.LABEL_WEIGHT, service.getWeight() == null ? null : service.getWeight().toString());
accept(consumer, Constants.LABEL_WARMUP, service.getWarmupDuration() == null ? null : service.getWarmupDuration().toString());
accept(consumer, Constants.LABEL_SERVICE_GROUP, !group ? null : service.getGroup());
Map<String, String> serviceMeta = service.getMeta();
if (serviceMeta != null) {
serviceMeta.forEach(consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@
*/
public interface Endpoint extends Matcher<TagCondition>, Attributes {

/**
* Key for the timestamp property of the endpoint.
*/
String KEY_TIMESTAMP = "timestamp";

/**
* Key for the weight property of the endpoint.
*/
String KEY_WEIGHT = "weight";

/**
* Key for the warmup period property of the endpoint.
*/
String KEY_WARMUP = "warmup";

/**
* Key for the counter attribute of the endpoint.
*/
Expand All @@ -61,7 +46,7 @@ public interface Endpoint extends Matcher<TagCondition>, Attributes {
/**
* Default warmup period for the endpoint in milliseconds.
*/
int DEFAULT_WARMUP = 10 * 60 * 1000;
int DEFAULT_WARMUP = 2 * 60 * 1000;

/**
* Default weight for the endpoint.
Expand Down Expand Up @@ -111,7 +96,7 @@ default String getAddress() {
* @return The timestamp, or null if not available.
*/
default Long getTimestamp() {
return Converts.getLong(getLabel(KEY_TIMESTAMP), null);
return Converts.getLong(getLabel(Constants.LABEL_TIMESTAMP), null);
}

/**
Expand All @@ -120,7 +105,7 @@ default Long getTimestamp() {
* @return the warm-up time in seconds, or the default value if not specified
*/
default Integer getWarmup() {
return Converts.getInteger(getLabel(KEY_WARMUP), DEFAULT_WARMUP);
return Converts.getInteger(getLabel(Constants.LABEL_WARMUP), DEFAULT_WARMUP);
}

/**
Expand Down Expand Up @@ -156,7 +141,7 @@ default Integer getWeight(ServiceRequest request) {
* @return the origin weight, or the default value if not specified
*/
default Integer getOriginWeight(ServiceRequest request) {
return Converts.getInteger(getLabel(KEY_WEIGHT), DEFAULT_WEIGHT);
return Converts.getInteger(getLabel(Constants.LABEL_WEIGHT), DEFAULT_WEIGHT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
<properties>
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
<os.detected.classifier>osx-x86_64</os.detected.classifier>
<!-- <os.detected.classifier>osx-x86_64</os.detected.classifier>-->
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<protoc.version>3.25.5</protoc.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -47,7 +48,7 @@
<version>${protobuf-maven-plugin.version}</version>
<configuration>
<pluginId>grpc-java</pluginId>
<protocArtifact>com.google.protobuf:protoc:3.9.1:exe:${os.detected.classifier}</protocArtifact>
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
Expand Down
2 changes: 2 additions & 0 deletions joylive-package/src/main/assembly/config/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ app.service.name=${APPLICATION_SERVICE_NAME:${APPLICATION_NAME}}
app.service.namespace=${APPLICATION_SERVICE_NAMESPACE:default}
app.service.group=${APPLICATION_SERVICE_GROUP:default}
app.service.gateway=${APPLICATION_SERVICE_GATEWAY:NONE}
app.service.weight=${APPLICATION_SERVICE_WEIGHT:}
app.service.warmupDuration=${APPLICATION_SERVICE_WARMUP_DURATION:}
app.location.cloud=${APPLICATION_LOCATION_CLOUD:}
app.location.region=${APPLICATION_LOCATION_REGION}
app.location.zone=${APPLICATION_LOCATION_ZONE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.jd.live.agent.core.Constants;
import com.jd.live.agent.core.util.option.Converts;
import com.jd.live.agent.governance.instance.AbstractEndpoint;
import com.jd.live.agent.governance.instance.EndpointState;
Expand Down Expand Up @@ -64,16 +65,16 @@ public int getPort() {
public Long getTimestamp() {
String timestamp = getLabel(REMOTE_TIMESTAMP_KEY);
if (timestamp == null || timestamp.isEmpty()) {
timestamp = getLabel(KEY_TIMESTAMP);
timestamp = getLabel(Constants.LABEL_TIMESTAMP);
}
return Converts.getLong(timestamp, null);
}

@Override
public Integer getOriginWeight(ServiceRequest request) {
String weight = url.getMethodParameter(request.getMethod(), KEY_WEIGHT, null);
String weight = url.getMethodParameter(request.getMethod(), Constants.LABEL_WEIGHT, null);
if (weight == null || weight.isEmpty()) {
weight = url.getParameter(KEY_WEIGHT);
weight = url.getParameter(Constants.LABEL_WEIGHT);
}
return Converts.getInteger(weight, DEFAULT_WEIGHT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.jd.live.agent.plugin.router.dubbo.v2_7.instance;

import com.jd.live.agent.core.Constants;
import com.jd.live.agent.core.util.option.Converts;
import com.jd.live.agent.governance.instance.AbstractEndpoint;
import com.jd.live.agent.governance.instance.EndpointState;
Expand Down Expand Up @@ -62,9 +63,9 @@ public int getPort() {
@Override
public Integer getOriginWeight(ServiceRequest request) {
URL target = invoker instanceof ClusterInvoker ? ((ClusterInvoker<?>) invoker).getRegistryUrl() : url;
String weight = target.getMethodParameter(request.getMethod(), KEY_WEIGHT, null);
String weight = target.getMethodParameter(request.getMethod(), Constants.LABEL_WEIGHT, null);
if (weight == null || weight.isEmpty()) {
weight = getLabel(KEY_WEIGHT);
weight = getLabel(Constants.LABEL_WEIGHT);
}
return Converts.getInteger(weight, DEFAULT_WEIGHT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.jd.live.agent.plugin.router.dubbo.v3.instance;

import com.jd.live.agent.core.Constants;
import com.jd.live.agent.core.util.option.Converts;
import com.jd.live.agent.governance.instance.AbstractEndpoint;
import com.jd.live.agent.governance.instance.EndpointState;
Expand Down Expand Up @@ -62,9 +63,9 @@ public int getPort() {
@Override
public Integer getOriginWeight(ServiceRequest request) {
URL target = invoker instanceof ClusterInvoker ? ((ClusterInvoker<?>) invoker).getRegistryUrl() : url;
String weight = target.getMethodParameter(request.getMethod(), KEY_WEIGHT, null);
String weight = target.getMethodParameter(request.getMethod(), Constants.LABEL_WEIGHT, null);
if (weight == null || weight.isEmpty()) {
weight = getLabel(KEY_WEIGHT);
weight = getLabel(Constants.LABEL_WEIGHT);
}
return Converts.getInteger(weight, DEFAULT_WEIGHT);
}
Expand Down

0 comments on commit 67790b8

Please sign in to comment.