You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2019/07/24 10:41:17 UTC
[servicecomb-service-center] branch master updated: support env
overwrite instance ttl
This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new e40214d support env overwrite instance ttl
new e946843 Merge pull request #565 from lizihuai/master
e40214d is described below
commit e40214d3fce26bcdf7670fb65c9869612cae3895
Author: lizihuai <13...@qq.com>
AuthorDate: Wed Jul 24 15:50:48 2019 +0800
support env overwrite instance ttl
---
server/service/instance.go | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/server/service/instance.go b/server/service/instance.go
index e67d64e..fbd556d 100644
--- a/server/service/instance.go
+++ b/server/service/instance.go
@@ -36,10 +36,15 @@ import (
serviceUtil "github.com/apache/servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
"math"
+ "os"
"strconv"
"time"
)
+var (
+ ttlFromEnv, _ = strconv.ParseInt(os.Getenv("INSTANCE_TTL"), 10, 0)
+)
+
type InstanceService struct {
}
@@ -104,9 +109,9 @@ func (s *InstanceService) Register(ctx context.Context, in *pb.RegisterInstanceR
if len(instance.InstanceId) > 0 {
// keep alive the lease ttl
// there are two reasons for sending a heartbeat here:
- // 1. in the scenario the instance has been removed,
+ // 1. in the scenario the instance has been removed,
// the cast of registration operation can be reduced.
- // 2. in the self-protection scenario, the instance is unhealthy
+ // 2. in the self-protection scenario, the instance is unhealthy
// and needs to be re-registered.
resp, err := s.Heartbeat(ctx, &pb.HeartbeatRequest{ServiceId: instance.ServiceId, InstanceId: instance.InstanceId})
switch resp.Response.Code {
@@ -137,6 +142,9 @@ func (s *InstanceService) Register(ctx context.Context, in *pb.RegisterInstanceR
}
ttl := int64(instance.HealthCheck.Interval * (instance.HealthCheck.Times + 1))
+ if ttlFromEnv > 0 {
+ ttl = ttlFromEnv
+ }
instanceFlag := fmt.Sprintf("ttl %ds, endpoints %v, host '%s', serviceId %s",
ttl, instance.Endpoints, instance.HostName, instance.ServiceId)