mirror of https://github.com/hashicorp/consul
agent: Support multiple tags per service registration
parent
7f399a0ecc
commit
8db2e3bd58
|
@ -19,7 +19,7 @@ func TestHTTPAgentServices(t *testing.T) {
|
||||||
srv1 := &structs.NodeService{
|
srv1 := &structs.NodeService{
|
||||||
ID: "mysql",
|
ID: "mysql",
|
||||||
Service: "mysql",
|
Service: "mysql",
|
||||||
Tag: "master",
|
Tags: []string{"master"},
|
||||||
Port: 5000,
|
Port: 5000,
|
||||||
}
|
}
|
||||||
srv.agent.state.AddService(srv1)
|
srv.agent.state.AddService(srv1)
|
||||||
|
@ -394,7 +394,7 @@ func TestHTTPAgentRegisterService(t *testing.T) {
|
||||||
}
|
}
|
||||||
args := &ServiceDefinition{
|
args := &ServiceDefinition{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tag: "master",
|
Tags: []string{"master"},
|
||||||
Port: 8000,
|
Port: 8000,
|
||||||
Check: CheckType{
|
Check: CheckType{
|
||||||
TTL: 15 * time.Second,
|
TTL: 15 * time.Second,
|
||||||
|
|
|
@ -108,7 +108,7 @@ func TestAgent_AddService(t *testing.T) {
|
||||||
srv := &structs.NodeService{
|
srv := &structs.NodeService{
|
||||||
ID: "redis",
|
ID: "redis",
|
||||||
Service: "redis",
|
Service: "redis",
|
||||||
Tag: "foo",
|
Tags: []string{"foo"},
|
||||||
Port: 8000,
|
Port: 8000,
|
||||||
}
|
}
|
||||||
chk := &CheckType{TTL: time.Minute}
|
chk := &CheckType{TTL: time.Minute}
|
||||||
|
|
|
@ -249,7 +249,7 @@ func TestCatalogServiceNodes(t *testing.T) {
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
Service: "api",
|
Service: "api",
|
||||||
Tag: "a",
|
Tags: []string{"a"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var out struct{}
|
var out struct{}
|
||||||
|
@ -293,7 +293,7 @@ func TestCatalogNodeServices(t *testing.T) {
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
Service: "api",
|
Service: "api",
|
||||||
Tag: "a",
|
Tags: []string{"a"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var out struct{}
|
var out struct{}
|
||||||
|
|
|
@ -197,7 +197,7 @@ func TestDecodeConfig(t *testing.T) {
|
||||||
|
|
||||||
func TestDecodeConfig_Service(t *testing.T) {
|
func TestDecodeConfig_Service(t *testing.T) {
|
||||||
// Basics
|
// Basics
|
||||||
input := `{"service": {"id": "red1", "name": "redis", "tag": "master", "port":8000, "check": {"script": "/bin/check_redis", "interval": "10s", "ttl": "15s" }}}`
|
input := `{"service": {"id": "red1", "name": "redis", "tags": ["master"], "port":8000, "check": {"script": "/bin/check_redis", "interval": "10s", "ttl": "15s" }}}`
|
||||||
config, err := DecodeConfig(bytes.NewReader([]byte(input)))
|
config, err := DecodeConfig(bytes.NewReader([]byte(input)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -216,7 +216,7 @@ func TestDecodeConfig_Service(t *testing.T) {
|
||||||
t.Fatalf("bad: %v", serv)
|
t.Fatalf("bad: %v", serv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if serv.Tag != "master" {
|
if !strContains(serv.Tags, "master") {
|
||||||
t.Fatalf("bad: %v", serv)
|
t.Fatalf("bad: %v", serv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ func TestDNS_ServiceLookup(t *testing.T) {
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "master",
|
Tags: []string{"master"},
|
||||||
Port: 12345,
|
Port: 12345,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) {
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "master",
|
Tags: []string{"master"},
|
||||||
Port: 12345,
|
Port: 12345,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) {
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
ID: "db2",
|
ID: "db2",
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "slave",
|
Tags: []string{"slave"},
|
||||||
Port: 12345,
|
Port: 12345,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) {
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
ID: "db3",
|
ID: "db3",
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "slave",
|
Tags: []string{"slave"},
|
||||||
Port: 12346,
|
Port: 12346,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) {
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "master",
|
Tags: []string{"master"},
|
||||||
Port: 12345,
|
Port: 12345,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) {
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
ID: "db2",
|
ID: "db2",
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "slave",
|
Tags: []string{"slave"},
|
||||||
Port: 12345,
|
Port: 12345,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) {
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
ID: "db3",
|
ID: "db3",
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "slave",
|
Tags: []string{"slave"},
|
||||||
Port: 12346,
|
Port: 12346,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ func TestDNS_ServiceLookup_FilterCritical(t *testing.T) {
|
||||||
Address: "127.0.0.1",
|
Address: "127.0.0.1",
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "master",
|
Tags: []string{"master"},
|
||||||
Port: 12345,
|
Port: 12345,
|
||||||
},
|
},
|
||||||
Check: &structs.HealthCheck{
|
Check: &structs.HealthCheck{
|
||||||
|
@ -502,7 +502,7 @@ func TestDNS_ServiceLookup_FilterCritical(t *testing.T) {
|
||||||
Address: "127.0.0.2",
|
Address: "127.0.0.2",
|
||||||
Service: &structs.NodeService{
|
Service: &structs.NodeService{
|
||||||
Service: "db",
|
Service: "db",
|
||||||
Tag: "master",
|
Tags: []string{"master"},
|
||||||
Port: 12345,
|
Port: 12345,
|
||||||
},
|
},
|
||||||
Check: &structs.HealthCheck{
|
Check: &structs.HealthCheck{
|
||||||
|
|
|
@ -29,7 +29,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
||||||
srv1 := &structs.NodeService{
|
srv1 := &structs.NodeService{
|
||||||
ID: "mysql",
|
ID: "mysql",
|
||||||
Service: "mysql",
|
Service: "mysql",
|
||||||
Tag: "master",
|
Tags: []string{"master"},
|
||||||
Port: 5000,
|
Port: 5000,
|
||||||
}
|
}
|
||||||
agent.state.AddService(srv1)
|
agent.state.AddService(srv1)
|
||||||
|
@ -42,7 +42,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
||||||
srv2 := &structs.NodeService{
|
srv2 := &structs.NodeService{
|
||||||
ID: "redis",
|
ID: "redis",
|
||||||
Service: "redis",
|
Service: "redis",
|
||||||
Tag: "",
|
Tags: nil,
|
||||||
Port: 8000,
|
Port: 8000,
|
||||||
}
|
}
|
||||||
agent.state.AddService(srv2)
|
agent.state.AddService(srv2)
|
||||||
|
@ -59,7 +59,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
||||||
srv3 := &structs.NodeService{
|
srv3 := &structs.NodeService{
|
||||||
ID: "web",
|
ID: "web",
|
||||||
Service: "web",
|
Service: "web",
|
||||||
Tag: "",
|
Tags: nil,
|
||||||
Port: 80,
|
Port: 80,
|
||||||
}
|
}
|
||||||
agent.state.AddService(srv3)
|
agent.state.AddService(srv3)
|
||||||
|
@ -68,7 +68,7 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
||||||
srv4 := &structs.NodeService{
|
srv4 := &structs.NodeService{
|
||||||
ID: "lb",
|
ID: "lb",
|
||||||
Service: "lb",
|
Service: "lb",
|
||||||
Tag: "",
|
Tags: nil,
|
||||||
Port: 443,
|
Port: 443,
|
||||||
}
|
}
|
||||||
args.Service = srv4
|
args.Service = srv4
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
type ServiceDefinition struct {
|
type ServiceDefinition struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
Tag string
|
Tags []string
|
||||||
Port int
|
Port int
|
||||||
Check CheckType
|
Check CheckType
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func (s *ServiceDefinition) NodeService() *structs.NodeService {
|
||||||
ns := &structs.NodeService{
|
ns := &structs.NodeService{
|
||||||
ID: s.ID,
|
ID: s.ID,
|
||||||
Service: s.Name,
|
Service: s.Name,
|
||||||
Tag: s.Tag,
|
Tags: s.Tags,
|
||||||
Port: s.Port,
|
Port: s.Port,
|
||||||
}
|
}
|
||||||
if ns.ID == "" && ns.Service != "" {
|
if ns.ID == "" && ns.Service != "" {
|
||||||
|
|
|
@ -29,3 +29,13 @@ func aeScale(interval time.Duration, n int) time.Duration {
|
||||||
func randomStagger(intv time.Duration) time.Duration {
|
func randomStagger(intv time.Duration) time.Duration {
|
||||||
return time.Duration(uint64(rand.Int63()) % uint64(intv))
|
return time.Duration(uint64(rand.Int63()) % uint64(intv))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// strContains checks if a list contains a string
|
||||||
|
func strContains(l []string, s string) bool {
|
||||||
|
for _, v := range l {
|
||||||
|
if v == s {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue