From c7581d68c639e28ccd43304d1f609c4c4878bc0e Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Wed, 28 Mar 2018 09:04:50 -0500 Subject: [PATCH] Renames agent API layer for service metadata to "meta" for consistency --- agent/agent_endpoint.go | 2 +- agent/config/runtime_test.go | 2 +- agent/consul/state/catalog.go | 2 +- agent/consul/state/catalog_test.go | 16 ++++++++-------- agent/structs/service_definition.go | 4 ++-- agent/structs/structs.go | 8 ++++---- agent/structs/structs_test.go | 8 ++++---- api/agent.go | 2 +- website/source/api/agent/service.html.md | 6 +++--- website/source/api/catalog.html.md | 6 +++--- website/source/api/health.html.md | 2 +- website/source/api/query.html.md | 6 ++---- 12 files changed, 31 insertions(+), 33 deletions(-) diff --git a/agent/agent_endpoint.go b/agent/agent_endpoint.go index 2e7d2f0cab..8904f436d9 100644 --- a/agent/agent_endpoint.go +++ b/agent/agent_endpoint.go @@ -515,7 +515,7 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re // Get the node service. 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) fmt.Fprint(resp, fmt.Errorf("Invalid Service Meta: %v", err)) return nil, nil diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 4c4358c58a..d7ff1d2bd6 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -4096,9 +4096,9 @@ func TestSanitize(t *testing.T) { "Checks": [], "EnableTagOverride": false, "ID": "", + "Meta": {}, "Name": "foo", "Port": 0, - "ServiceMeta": {}, "Tags": [], "Token": "hidden" } diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 91489f57ad..36fa42a54e 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -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) } - 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) } // Create the service node entry and populate the indexes. Note that diff --git a/agent/consul/state/catalog_test.go b/agent/consul/state/catalog_test.go index 9ffed8fba7..3fbb8124fd 100644 --- a/agent/consul/state/catalog_test.go +++ b/agent/consul/state/catalog_test.go @@ -69,17 +69,17 @@ func TestStateStore_EnsureRegistration(t *testing.T) { } 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{ - ID: "redis1", - Service: "redis", - Address: "1.1.1.1", - Port: 8080, - ServiceMeta: map[string]string{strings.Repeat("a", 129): "somevalue"}, - Tags: []string{"master"}, + ID: "redis1", + Service: "redis", + Address: "1.1.1.1", + Port: 8080, + Meta: map[string]string{strings.Repeat("a", 129): "somevalue"}, + Tags: []string{"master"}, } 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. diff --git a/agent/structs/service_definition.go b/agent/structs/service_definition.go index aa1cda535e..4dc8ccfca0 100644 --- a/agent/structs/service_definition.go +++ b/agent/structs/service_definition.go @@ -6,7 +6,7 @@ type ServiceDefinition struct { Name string Tags []string Address string - ServiceMeta map[string]string + Meta map[string]string Port int Check CheckType Checks CheckTypes @@ -20,7 +20,7 @@ func (s *ServiceDefinition) NodeService() *NodeService { Service: s.Name, Tags: s.Tags, Address: s.Address, - ServiceMeta: s.ServiceMeta, + Meta: s.Meta, Port: s.Port, EnableTagOverride: s.EnableTagOverride, } diff --git a/agent/structs/structs.go b/agent/structs/structs.go index 0056af4877..92f942d0d5 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -412,7 +412,7 @@ func (s *ServiceNode) ToNodeService() *NodeService { Tags: s.ServiceTags, Address: s.ServiceAddress, Port: s.ServicePort, - ServiceMeta: s.ServiceMeta, + Meta: s.ServiceMeta, EnableTagOverride: s.ServiceEnableTagOverride, RaftIndex: RaftIndex{ CreateIndex: s.CreateIndex, @@ -429,7 +429,7 @@ type NodeService struct { Service string Tags []string Address string - ServiceMeta map[string]string + Meta map[string]string Port int EnableTagOverride bool @@ -446,7 +446,7 @@ func (s *NodeService) IsSame(other *NodeService) bool { !reflect.DeepEqual(s.Tags, other.Tags) || s.Address != other.Address || s.Port != other.Port || - !reflect.DeepEqual(s.ServiceMeta, other.ServiceMeta) || + !reflect.DeepEqual(s.Meta, other.Meta) || s.EnableTagOverride != other.EnableTagOverride { return false } @@ -466,7 +466,7 @@ func (s *NodeService) ToServiceNode(node string) *ServiceNode { ServiceTags: s.Tags, ServiceAddress: s.Address, ServicePort: s.Port, - ServiceMeta: s.ServiceMeta, + ServiceMeta: s.Meta, ServiceEnableTagOverride: s.EnableTagOverride, RaftIndex: RaftIndex{ CreateIndex: s.CreateIndex, diff --git a/agent/structs/structs_test.go b/agent/structs/structs_test.go index af7cc2b049..e1cb8ed8a9 100644 --- a/agent/structs/structs_test.go +++ b/agent/structs/structs_test.go @@ -187,7 +187,7 @@ func TestStructs_ServiceNode_PartialClone(t *testing.T) { } sn.ServiceMeta["new_meta"] = "new_value" 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", Tags: []string{"foo", "bar"}, Address: "127.0.0.1", - ServiceMeta: map[string]string{ + Meta: map[string]string{ "meta1": "value1", "meta2": "value2", }, @@ -232,7 +232,7 @@ func TestStructs_NodeService_IsSame(t *testing.T) { Address: "127.0.0.1", Port: 1234, EnableTagOverride: true, - ServiceMeta: map[string]string{ + Meta: map[string]string{ // We don't care about order "meta2": "value2", "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.Address = "XXX" }, func() { other.Address = "127.0.0.1" }) 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 }) } diff --git a/api/agent.go b/api/agent.go index bd414d6c6b..b42baed41d 100644 --- a/api/agent.go +++ b/api/agent.go @@ -66,7 +66,7 @@ type AgentServiceRegistration struct { Port int `json:",omitempty"` Address string `json:",omitempty"` EnableTagOverride bool `json:",omitempty"` - ServiceMeta map[string]string `json:",omitempty"` + Meta map[string]string `json:",omitempty"` Check *AgentServiceCheck Checks AgentServiceChecks } diff --git a/website/source/api/agent/service.html.md b/website/source/api/agent/service.html.md index 033a620114..c7b1001114 100644 --- a/website/source/api/agent/service.html.md +++ b/website/source/api/agent/service.html.md @@ -53,7 +53,7 @@ $ curl \ "Service": "redis", "Tags": [], "Address": "", - "ServiceMeta": { + "Meta": { "redis_version": "4.0" }, "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 DNS queries. -- `ServiceMeta` `(map: nil)` - Specifies arbitrary KV metadata +- `Meta` `(map: nil)` - Specifies arbitrary KV metadata linked to the service instance. - `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", "Port": 8000, - "ServiceMeta": { + "Meta": { "redis_version": "4.0" }, "EnableTagOverride": false, diff --git a/website/source/api/catalog.html.md b/website/source/api/catalog.html.md index b63837e02e..4bbb612c6d 100644 --- a/website/source/api/catalog.html.md +++ b/website/source/api/catalog.html.md @@ -105,7 +105,7 @@ and vice versa. A catalog entry can have either, neither, or both. "v1" ], "Address": "127.0.0.1", - "ServiceMeta": { + "Meta": { "redis_version": "4.0" }, "Port": 8000 @@ -537,7 +537,7 @@ $ curl \ "ID": "consul", "Service": "consul", "Tags": null, - "ServiceMeta": {}, + "Meta": {}, "Port": 8300 }, "redis": { @@ -546,7 +546,7 @@ $ curl \ "Tags": [ "v1" ], - "ServiceMeta": { + "Meta": { "redis_version": "4.0" }, "Port": 8000 diff --git a/website/source/api/health.html.md b/website/source/api/health.html.md index ef22d8648c..a404bda2e2 100644 --- a/website/source/api/health.html.md +++ b/website/source/api/health.html.md @@ -216,7 +216,7 @@ $ curl \ "Service": "redis", "Tags": ["primary"], "Address": "10.1.10.12", - "ServiceMeta": { + "Meta": { "redis_version": "4.0" }, "Port": 8000 diff --git a/website/source/api/query.html.md b/website/source/api/query.html.md index e12c0d7545..586244fcf7 100644 --- a/website/source/api/query.html.md +++ b/website/source/api/query.html.md @@ -241,7 +241,6 @@ The table below shows this endpoint's support for "Near": "node1", "OnlyPassing": false, "Tags": ["primary", "!experimental"], - "ServiceMeta": {"redis_version": "4.0"}, "NodeMeta": {"instance_type": "m3.large"} }, "DNS": { @@ -314,7 +313,6 @@ $ curl \ }, "OnlyPassing": false, "Tags": ["primary", "!experimental"], - "ServiceMeta": {"redis_version": "4.0"}, "NodeMeta": {"instance_type": "m3.large"} }, "DNS": { @@ -512,7 +510,7 @@ $ curl \ "ID": "redis", "Service": "redis", "Tags": null, - "ServiceMeta": {"redis_version": "4.0"}, + "Meta": {"redis_version": "4.0"}, "Port": 8000 }, "Checks": [ @@ -619,7 +617,7 @@ $ curl \ }, "OnlyPassing": true, "Tags": ["primary"], - "ServiceMeta": { "mysql_version": "5.7.20" }, + "Meta": { "mysql_version": "5.7.20" }, "NodeMeta": {"instance_type": "m3.large"} } }