From 6d0636ebabd06d3eb9ba98eedfc44d7ea4ed88d7 Mon Sep 17 00:00:00 2001 From: shiling02404 <153594697@qq.com> Date: Tue, 21 Jun 2022 21:41:07 +0800 Subject: [PATCH] add id when registering services to consul (#1802) --- nameresolution/consul/consul.go | 4 +++- nameresolution/consul/consul_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nameresolution/consul/consul.go b/nameresolution/consul/consul.go index 163feaeb6..cdeff42e1 100644 --- a/nameresolution/consul/consul.go +++ b/nameresolution/consul/consul.go @@ -244,12 +244,13 @@ func getRegistrationConfig(cfg configSpec, props map[string]string) (*consul.Age return nil, fmt.Errorf("error parsing %s: %w", nr.DaprHTTPPort, err) } + id := appID + "-" + host + "-" + httpPort // if no health checks configured add dapr sidecar health check by default if len(cfg.Checks) == 0 { cfg.Checks = []*consul.AgentServiceCheck{ { Name: "Dapr Health Status", - CheckID: fmt.Sprintf("daprHealth:%s", appID), + CheckID: fmt.Sprintf("daprHealth:%s", id), Interval: "15s", HTTP: fmt.Sprintf("http://%s:%s/v1.0/healthz", host, httpPort), }, @@ -262,6 +263,7 @@ func getRegistrationConfig(cfg configSpec, props map[string]string) (*consul.Age } return &consul.AgentServiceRegistration{ + ID: id, Name: appID, Address: host, Port: appPortInt, diff --git a/nameresolution/consul/consul_test.go b/nameresolution/consul/consul_test.go index 028bfc2e8..b6baece19 100644 --- a/nameresolution/consul/consul_test.go +++ b/nameresolution/consul/consul_test.go @@ -501,7 +501,7 @@ func TestGetConfig(t *testing.T) { assert.Equal(t, 1, len(actual.Registration.Checks)) check := actual.Registration.Checks[0] assert.Equal(t, "Dapr Health Status", check.Name) - assert.Equal(t, "daprHealth:test-app", check.CheckID) + assert.Equal(t, "daprHealth:test-app-"+metadata.Properties[nr.HostAddress]+"-"+metadata.Properties[nr.DaprHTTPPort], check.CheckID) assert.Equal(t, "15s", check.Interval) assert.Equal(t, fmt.Sprintf("http://%s:%s/v1.0/healthz", metadata.Properties[nr.HostAddress], metadata.Properties[nr.DaprHTTPPort]), check.HTTP)