Merge pull request #3994 from hashicorp/f-rename-servicemeta

Renames agent API layer for service metadata to "meta" for consistency
pull/3920/merge
Preetha 2018-03-29 14:07:57 -05:00 committed by GitHub
commit 1609b2c6b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 31 additions and 33 deletions

View File

@ -515,7 +515,7 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re
// Get the node service. // Get the node service.
ns := args.NodeService() ns := args.NodeService()
if err := structs.ValidateMetadata(ns.ServiceMeta, false); err != nil { if err := structs.ValidateMetadata(ns.Meta, false); err != nil {
resp.WriteHeader(http.StatusBadRequest) resp.WriteHeader(http.StatusBadRequest)
fmt.Fprint(resp, fmt.Errorf("Invalid Service Meta: %v", err)) fmt.Fprint(resp, fmt.Errorf("Invalid Service Meta: %v", err))
return nil, nil return nil, nil

View File

@ -4096,9 +4096,9 @@ func TestSanitize(t *testing.T) {
"Checks": [], "Checks": [],
"EnableTagOverride": false, "EnableTagOverride": false,
"ID": "", "ID": "",
"Meta": {},
"Name": "foo", "Name": "foo",
"Port": 0, "Port": 0,
"ServiceMeta": {},
"Tags": [], "Tags": [],
"Token": "hidden" "Token": "hidden"
} }

View File

@ -614,7 +614,7 @@ func (s *Store) ensureServiceTxn(tx *memdb.Txn, idx uint64, node string, svc *st
return fmt.Errorf("failed service lookup: %s", err) return fmt.Errorf("failed service lookup: %s", err)
} }
if err = structs.ValidateMetadata(svc.ServiceMeta, false); err != nil { if err = structs.ValidateMetadata(svc.Meta, false); err != nil {
return fmt.Errorf("Invalid Service Meta for node %s and serviceID %s: %v", node, svc.ID, err) return fmt.Errorf("Invalid Service Meta for node %s and serviceID %s: %v", node, svc.ID, err)
} }
// Create the service node entry and populate the indexes. Note that // Create the service node entry and populate the indexes. Note that

View File

@ -69,17 +69,17 @@ func TestStateStore_EnsureRegistration(t *testing.T) {
} }
verifyNode() verifyNode()
// Add in a invalid service definition with too long Key value for ServiceMeta // Add in a invalid service definition with too long Key value for Meta
req.Service = &structs.NodeService{ req.Service = &structs.NodeService{
ID: "redis1", ID: "redis1",
Service: "redis", Service: "redis",
Address: "1.1.1.1", Address: "1.1.1.1",
Port: 8080, Port: 8080,
ServiceMeta: map[string]string{strings.Repeat("a", 129): "somevalue"}, Meta: map[string]string{strings.Repeat("a", 129): "somevalue"},
Tags: []string{"master"}, Tags: []string{"master"},
} }
if err := s.EnsureRegistration(9, req); err == nil { if err := s.EnsureRegistration(9, req); err == nil {
t.Fatalf("Service should not have been registered since ServiceMeta is invalid") t.Fatalf("Service should not have been registered since Meta is invalid")
} }
// Add in a service definition. // Add in a service definition.

View File

@ -6,7 +6,7 @@ type ServiceDefinition struct {
Name string Name string
Tags []string Tags []string
Address string Address string
ServiceMeta map[string]string Meta map[string]string
Port int Port int
Check CheckType Check CheckType
Checks CheckTypes Checks CheckTypes
@ -20,7 +20,7 @@ func (s *ServiceDefinition) NodeService() *NodeService {
Service: s.Name, Service: s.Name,
Tags: s.Tags, Tags: s.Tags,
Address: s.Address, Address: s.Address,
ServiceMeta: s.ServiceMeta, Meta: s.Meta,
Port: s.Port, Port: s.Port,
EnableTagOverride: s.EnableTagOverride, EnableTagOverride: s.EnableTagOverride,
} }

View File

@ -412,7 +412,7 @@ func (s *ServiceNode) ToNodeService() *NodeService {
Tags: s.ServiceTags, Tags: s.ServiceTags,
Address: s.ServiceAddress, Address: s.ServiceAddress,
Port: s.ServicePort, Port: s.ServicePort,
ServiceMeta: s.ServiceMeta, Meta: s.ServiceMeta,
EnableTagOverride: s.ServiceEnableTagOverride, EnableTagOverride: s.ServiceEnableTagOverride,
RaftIndex: RaftIndex{ RaftIndex: RaftIndex{
CreateIndex: s.CreateIndex, CreateIndex: s.CreateIndex,
@ -429,7 +429,7 @@ type NodeService struct {
Service string Service string
Tags []string Tags []string
Address string Address string
ServiceMeta map[string]string Meta map[string]string
Port int Port int
EnableTagOverride bool EnableTagOverride bool
@ -446,7 +446,7 @@ func (s *NodeService) IsSame(other *NodeService) bool {
!reflect.DeepEqual(s.Tags, other.Tags) || !reflect.DeepEqual(s.Tags, other.Tags) ||
s.Address != other.Address || s.Address != other.Address ||
s.Port != other.Port || s.Port != other.Port ||
!reflect.DeepEqual(s.ServiceMeta, other.ServiceMeta) || !reflect.DeepEqual(s.Meta, other.Meta) ||
s.EnableTagOverride != other.EnableTagOverride { s.EnableTagOverride != other.EnableTagOverride {
return false return false
} }
@ -466,7 +466,7 @@ func (s *NodeService) ToServiceNode(node string) *ServiceNode {
ServiceTags: s.Tags, ServiceTags: s.Tags,
ServiceAddress: s.Address, ServiceAddress: s.Address,
ServicePort: s.Port, ServicePort: s.Port,
ServiceMeta: s.ServiceMeta, ServiceMeta: s.Meta,
ServiceEnableTagOverride: s.EnableTagOverride, ServiceEnableTagOverride: s.EnableTagOverride,
RaftIndex: RaftIndex{ RaftIndex: RaftIndex{
CreateIndex: s.CreateIndex, CreateIndex: s.CreateIndex,

View File

@ -187,7 +187,7 @@ func TestStructs_ServiceNode_PartialClone(t *testing.T) {
} }
sn.ServiceMeta["new_meta"] = "new_value" sn.ServiceMeta["new_meta"] = "new_value"
if reflect.DeepEqual(sn, clone) { if reflect.DeepEqual(sn, clone) {
t.Fatalf("clone wasn't independent of the original for ServiceMeta") t.Fatalf("clone wasn't independent of the original for Meta")
} }
} }
@ -214,7 +214,7 @@ func TestStructs_NodeService_IsSame(t *testing.T) {
Service: "theservice", Service: "theservice",
Tags: []string{"foo", "bar"}, Tags: []string{"foo", "bar"},
Address: "127.0.0.1", Address: "127.0.0.1",
ServiceMeta: map[string]string{ Meta: map[string]string{
"meta1": "value1", "meta1": "value1",
"meta2": "value2", "meta2": "value2",
}, },
@ -232,7 +232,7 @@ func TestStructs_NodeService_IsSame(t *testing.T) {
Address: "127.0.0.1", Address: "127.0.0.1",
Port: 1234, Port: 1234,
EnableTagOverride: true, EnableTagOverride: true,
ServiceMeta: map[string]string{ Meta: map[string]string{
// We don't care about order // We don't care about order
"meta2": "value2", "meta2": "value2",
"meta1": "value1", "meta1": "value1",
@ -268,7 +268,7 @@ func TestStructs_NodeService_IsSame(t *testing.T) {
check(func() { other.Tags = []string{"foo"} }, func() { other.Tags = []string{"foo", "bar"} }) check(func() { other.Tags = []string{"foo"} }, func() { other.Tags = []string{"foo", "bar"} })
check(func() { other.Address = "XXX" }, func() { other.Address = "127.0.0.1" }) check(func() { other.Address = "XXX" }, func() { other.Address = "127.0.0.1" })
check(func() { other.Port = 9999 }, func() { other.Port = 1234 }) check(func() { other.Port = 9999 }, func() { other.Port = 1234 })
check(func() { other.ServiceMeta["meta2"] = "wrongValue" }, func() { other.ServiceMeta["meta2"] = "value2" }) check(func() { other.Meta["meta2"] = "wrongValue" }, func() { other.Meta["meta2"] = "value2" })
check(func() { other.EnableTagOverride = false }, func() { other.EnableTagOverride = true }) check(func() { other.EnableTagOverride = false }, func() { other.EnableTagOverride = true })
} }

View File

@ -66,7 +66,7 @@ type AgentServiceRegistration struct {
Port int `json:",omitempty"` Port int `json:",omitempty"`
Address string `json:",omitempty"` Address string `json:",omitempty"`
EnableTagOverride bool `json:",omitempty"` EnableTagOverride bool `json:",omitempty"`
ServiceMeta map[string]string `json:",omitempty"` Meta map[string]string `json:",omitempty"`
Check *AgentServiceCheck Check *AgentServiceCheck
Checks AgentServiceChecks Checks AgentServiceChecks
} }

View File

@ -53,7 +53,7 @@ $ curl \
"Service": "redis", "Service": "redis",
"Tags": [], "Tags": [],
"Address": "", "Address": "",
"ServiceMeta": { "Meta": {
"redis_version": "4.0" "redis_version": "4.0"
}, },
"Port": 8000 "Port": 8000
@ -99,7 +99,7 @@ The table below shows this endpoint's support for
provided, the agent's address is used as the address for the service during provided, the agent's address is used as the address for the service during
DNS queries. DNS queries.
- `ServiceMeta` `(map<string|string>: nil)` - Specifies arbitrary KV metadata - `Meta` `(map<string|string>: nil)` - Specifies arbitrary KV metadata
linked to the service instance. linked to the service instance.
- `Port` `(int: 0)` - Specifies the port of the service. - `Port` `(int: 0)` - Specifies the port of the service.
@ -153,7 +153,7 @@ The table below shows this endpoint's support for
], ],
"Address": "127.0.0.1", "Address": "127.0.0.1",
"Port": 8000, "Port": 8000,
"ServiceMeta": { "Meta": {
"redis_version": "4.0" "redis_version": "4.0"
}, },
"EnableTagOverride": false, "EnableTagOverride": false,

View File

@ -105,7 +105,7 @@ and vice versa. A catalog entry can have either, neither, or both.
"v1" "v1"
], ],
"Address": "127.0.0.1", "Address": "127.0.0.1",
"ServiceMeta": { "Meta": {
"redis_version": "4.0" "redis_version": "4.0"
}, },
"Port": 8000 "Port": 8000
@ -537,7 +537,7 @@ $ curl \
"ID": "consul", "ID": "consul",
"Service": "consul", "Service": "consul",
"Tags": null, "Tags": null,
"ServiceMeta": {}, "Meta": {},
"Port": 8300 "Port": 8300
}, },
"redis": { "redis": {
@ -546,7 +546,7 @@ $ curl \
"Tags": [ "Tags": [
"v1" "v1"
], ],
"ServiceMeta": { "Meta": {
"redis_version": "4.0" "redis_version": "4.0"
}, },
"Port": 8000 "Port": 8000

View File

@ -216,7 +216,7 @@ $ curl \
"Service": "redis", "Service": "redis",
"Tags": ["primary"], "Tags": ["primary"],
"Address": "10.1.10.12", "Address": "10.1.10.12",
"ServiceMeta": { "Meta": {
"redis_version": "4.0" "redis_version": "4.0"
}, },
"Port": 8000 "Port": 8000

View File

@ -241,7 +241,6 @@ The table below shows this endpoint's support for
"Near": "node1", "Near": "node1",
"OnlyPassing": false, "OnlyPassing": false,
"Tags": ["primary", "!experimental"], "Tags": ["primary", "!experimental"],
"ServiceMeta": {"redis_version": "4.0"},
"NodeMeta": {"instance_type": "m3.large"} "NodeMeta": {"instance_type": "m3.large"}
}, },
"DNS": { "DNS": {
@ -314,7 +313,6 @@ $ curl \
}, },
"OnlyPassing": false, "OnlyPassing": false,
"Tags": ["primary", "!experimental"], "Tags": ["primary", "!experimental"],
"ServiceMeta": {"redis_version": "4.0"},
"NodeMeta": {"instance_type": "m3.large"} "NodeMeta": {"instance_type": "m3.large"}
}, },
"DNS": { "DNS": {
@ -512,7 +510,7 @@ $ curl \
"ID": "redis", "ID": "redis",
"Service": "redis", "Service": "redis",
"Tags": null, "Tags": null,
"ServiceMeta": {"redis_version": "4.0"}, "Meta": {"redis_version": "4.0"},
"Port": 8000 "Port": 8000
}, },
"Checks": [ "Checks": [
@ -619,7 +617,7 @@ $ curl \
}, },
"OnlyPassing": true, "OnlyPassing": true,
"Tags": ["primary"], "Tags": ["primary"],
"ServiceMeta": { "mysql_version": "5.7.20" }, "Meta": { "mysql_version": "5.7.20" },
"NodeMeta": {"instance_type": "m3.large"} "NodeMeta": {"instance_type": "m3.large"}
} }
} }