Update the v1/agent/service/:service endpoint to output tagged… (#6304)

This commit is contained in:
Matt Keeler 2019-08-10 09:15:19 -04:00 committed by GitHub
parent 6f42bd6920
commit 0e1b7038cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 39 deletions

View File

@ -10,8 +10,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/mitchellh/mapstructure"
"github.com/hashicorp/go-memdb" "github.com/hashicorp/go-memdb"
"github.com/mitchellh/hashstructure" "github.com/mitchellh/hashstructure"
@ -288,43 +286,9 @@ func (s *HTTPServer) AgentService(resp http.ResponseWriter, req *http.Request) (
return "", nil, acl.ErrPermissionDenied return "", nil, acl.ErrPermissionDenied
} }
var connect *api.AgentServiceConnect
var proxy *api.AgentServiceConnectProxyConfig
if svc.Connect.Native {
connect = &api.AgentServiceConnect{
Native: svc.Connect.Native,
}
}
if svc.Kind == structs.ServiceKindConnectProxy ||
svc.Kind == structs.ServiceKindMeshGateway {
proxy = svc.Proxy.ToAPI()
}
var weights api.AgentWeights
if svc.Weights != nil {
err := mapstructure.Decode(svc.Weights, &weights)
if err != nil {
return "", nil, err
}
}
// Calculate the content hash over the response, minus the hash field // Calculate the content hash over the response, minus the hash field
reply := &api.AgentService{ aSvc := buildAgentService(svc)
Kind: api.ServiceKind(svc.Kind), reply := &aSvc
ID: svc.ID,
Service: svc.Service,
Tags: svc.Tags,
Meta: svc.Meta,
Port: svc.Port,
Address: svc.Address,
EnableTagOverride: svc.EnableTagOverride,
Weights: weights,
Proxy: proxy,
Connect: connect,
}
rawHash, err := hashstructure.Hash(reply, nil) rawHash, err := hashstructure.Hash(reply, nil)
if err != nil { if err != nil {

View File

@ -278,6 +278,12 @@ func TestAgent_Service(t *testing.T) {
services { services {
name = "web" name = "web"
port = 8181 port = 8181
tagged_addresses {
wan {
address = "198.18.0.1"
port = 1818
}
}
} }
`) `)
defer a.Shutdown() defer a.Shutdown()
@ -323,6 +329,8 @@ func TestAgent_Service(t *testing.T) {
Passing: 1, Passing: 1,
Warning: 1, Warning: 1,
}, },
Meta: map[string]string{},
Tags: []string{},
} }
// Copy and modify // Copy and modify
@ -335,11 +343,19 @@ func TestAgent_Service(t *testing.T) {
ID: "web", ID: "web",
Service: "web", Service: "web",
Port: 8181, Port: 8181,
ContentHash: "afaa0e76b202ffbb", ContentHash: "6c247f8ffa5d1fb2",
Weights: api.AgentWeights{ Weights: api.AgentWeights{
Passing: 1, Passing: 1,
Warning: 1, Warning: 1,
}, },
TaggedAddresses: map[string]api.ServiceAddress{
"wan": api.ServiceAddress{
Address: "198.18.0.1",
Port: 1818,
},
},
Meta: map[string]string{},
Tags: []string{},
} }
tests := []struct { tests := []struct {

View File

@ -647,6 +647,7 @@ func TestAPI_AgentService(t *testing.T) {
Passing: 1, Passing: 1,
Warning: 1, Warning: 1,
}, },
Meta: map[string]string{},
} }
require.Equal(expect, got) require.Equal(expect, got)
require.Equal(expect.ContentHash, qm.LastContentHash) require.Equal(expect.ContentHash, qm.LastContentHash)