Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of Add the missing Service TaggedAddresses and Check Type fields to Txn API into release/1.20.x #22222

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/22220.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
agent: Add the missing Service TaggedAddresses and Check Type fields to Txn API.
```
11 changes: 11 additions & 0 deletions agent/txn_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ func (s *HTTPHandlers) convertOps(resp http.ResponseWriter, req *http.Request) (
},
},
}
if len(in.Service.Service.TaggedAddresses) > 0 {
taggedAddresses := make(map[string]structs.ServiceAddress)
for name, addr := range in.Service.Service.TaggedAddresses {
taggedAddresses[name] = structs.ServiceAddress{
Address: addr.Address,
Port: addr.Port,
}
}
out.Service.Service.TaggedAddresses = taggedAddresses
}

if svc.Proxy != nil {
out.Service.Service.Proxy = structs.ConnectProxyConfig{}
Expand Down Expand Up @@ -300,6 +310,7 @@ func (s *HTTPHandlers) convertOps(resp http.ResponseWriter, req *http.Request) (
Status: check.Status,
Notes: check.Notes,
Output: check.Output,
Type: check.Type,
ServiceID: check.ServiceID,
ServiceName: check.ServiceName,
ServiceTags: check.ServiceTags,
Expand Down
50 changes: 48 additions & 2 deletions agent/txn_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
"Status": "critical",
"Notes": "Http based health check",
"Output": "",
"Type": "http",
"ServiceID": "",
"ServiceName": "",
"Definition": {
Expand All @@ -564,6 +565,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
"Status": "passing",
"Notes": "Http based health check",
"Output": "success",
"Type": "http",
"ServiceID": "",
"ServiceName": "",
"Definition": {
Expand All @@ -586,6 +588,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
"Status": "passing",
"Notes": "Http based health check",
"Output": "success",
"Type": "http",
"ServiceID": "",
"ServiceName": "",
"ExposedPort": 5678,
Expand Down Expand Up @@ -624,6 +627,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
Name: "Node http check",
Status: api.HealthCritical,
Notes: "Http based health check",
Type: "http",
Definition: structs.HealthCheckDefinition{
Interval: 6 * time.Second,
Timeout: 6 * time.Second,
Expand All @@ -646,6 +650,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
Status: api.HealthPassing,
Notes: "Http based health check",
Output: "success",
Type: "http",
Definition: structs.HealthCheckDefinition{
Interval: 10 * time.Second,
Timeout: 10 * time.Second,
Expand All @@ -668,6 +673,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
Status: api.HealthPassing,
Notes: "Http based health check",
Output: "success",
Type: "http",
ExposedPort: 5678,
Definition: structs.HealthCheckDefinition{
Interval: 15 * time.Second,
Expand Down Expand Up @@ -712,6 +718,23 @@ func TestTxnEndpoint_NodeService(t *testing.T) {
}
}
},
{
"Service": {
"Verb": "set",
"Node": "%s",
"Service": {
"Service": "test2",
"Address": "192.168.0.10",
"Port" : 8080,
"TaggedAddresses": {
"lan": {
"Address": "192.168.0.10",
"Port": 8080
}
}
}
}
},
{
"Service": {
"Verb": "set",
Expand All @@ -736,7 +759,7 @@ func TestTxnEndpoint_NodeService(t *testing.T) {
}
}
]
`, a.config.NodeName, a.config.NodeName)))
`, a.config.NodeName, a.config.NodeName, a.config.NodeName)))
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
resp := httptest.NewRecorder()
obj, err := a.srv.Txn(resp, req)
Expand All @@ -747,7 +770,7 @@ func TestTxnEndpoint_NodeService(t *testing.T) {
if !ok {
t.Fatalf("bad type: %T", obj)
}
require.Equal(t, 2, len(txnResp.Results))
require.Equal(t, 3, len(txnResp.Results))

index := txnResp.Results[0].Service.ModifyIndex
expected := structs.TxnResponse{
Expand All @@ -768,6 +791,29 @@ func TestTxnEndpoint_NodeService(t *testing.T) {
EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(),
},
},
&structs.TxnResult{
Service: &structs.NodeService{
Service: "test2",
ID: "test2",
Address: "192.168.0.10",
Port: 8080,
TaggedAddresses: map[string]structs.ServiceAddress{
"lan": {
Address: "192.168.0.10",
Port: 8080,
},
},
Weights: &structs.Weights{
Passing: 1,
Warning: 1,
},
RaftIndex: structs.RaftIndex{
CreateIndex: index,
ModifyIndex: index,
},
EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(),
},
},
&structs.TxnResult{
Service: &structs.NodeService{
Service: "test-sidecar-proxy",
Expand Down
Loading