Skip to content

Commit a9b583b

Browse files
Backport of Add the missing Service TaggedAddresses and Check Type fields to Txn API into release/1.21.x (#22221)
* backport of commit c981401 * backport of commit f20658e --------- Co-authored-by: nitin.sachdev <[email protected]>
1 parent 67d0ed0 commit a9b583b

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

.changelog/22220.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
agent: Add the missing Service TaggedAddresses and Check Type fields to Txn API.
3+
```

agent/txn_endpoint.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ func (s *HTTPHandlers) convertOps(resp http.ResponseWriter, req *http.Request) (
231231
},
232232
},
233233
}
234+
if len(in.Service.Service.TaggedAddresses) > 0 {
235+
taggedAddresses := make(map[string]structs.ServiceAddress)
236+
for name, addr := range in.Service.Service.TaggedAddresses {
237+
taggedAddresses[name] = structs.ServiceAddress{
238+
Address: addr.Address,
239+
Port: addr.Port,
240+
}
241+
}
242+
out.Service.Service.TaggedAddresses = taggedAddresses
243+
}
234244

235245
if svc.Proxy != nil {
236246
out.Service.Service.Proxy = structs.ConnectProxyConfig{}
@@ -300,6 +310,7 @@ func (s *HTTPHandlers) convertOps(resp http.ResponseWriter, req *http.Request) (
300310
Status: check.Status,
301311
Notes: check.Notes,
302312
Output: check.Output,
313+
Type: check.Type,
303314
ServiceID: check.ServiceID,
304315
ServiceName: check.ServiceName,
305316
ServiceTags: check.ServiceTags,

agent/txn_endpoint_test.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
542542
"Status": "critical",
543543
"Notes": "Http based health check",
544544
"Output": "",
545+
"Type": "http",
545546
"ServiceID": "",
546547
"ServiceName": "",
547548
"Definition": {
@@ -564,6 +565,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
564565
"Status": "passing",
565566
"Notes": "Http based health check",
566567
"Output": "success",
568+
"Type": "http",
567569
"ServiceID": "",
568570
"ServiceName": "",
569571
"Definition": {
@@ -586,6 +588,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
586588
"Status": "passing",
587589
"Notes": "Http based health check",
588590
"Output": "success",
591+
"Type": "http",
589592
"ServiceID": "",
590593
"ServiceName": "",
591594
"ExposedPort": 5678,
@@ -624,6 +627,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
624627
Name: "Node http check",
625628
Status: api.HealthCritical,
626629
Notes: "Http based health check",
630+
Type: "http",
627631
Definition: structs.HealthCheckDefinition{
628632
Interval: 6 * time.Second,
629633
Timeout: 6 * time.Second,
@@ -646,6 +650,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
646650
Status: api.HealthPassing,
647651
Notes: "Http based health check",
648652
Output: "success",
653+
Type: "http",
649654
Definition: structs.HealthCheckDefinition{
650655
Interval: 10 * time.Second,
651656
Timeout: 10 * time.Second,
@@ -668,6 +673,7 @@ func TestTxnEndpoint_UpdateCheck(t *testing.T) {
668673
Status: api.HealthPassing,
669674
Notes: "Http based health check",
670675
Output: "success",
676+
Type: "http",
671677
ExposedPort: 5678,
672678
Definition: structs.HealthCheckDefinition{
673679
Interval: 15 * time.Second,
@@ -712,6 +718,23 @@ func TestTxnEndpoint_NodeService(t *testing.T) {
712718
}
713719
}
714720
},
721+
{
722+
"Service": {
723+
"Verb": "set",
724+
"Node": "%s",
725+
"Service": {
726+
"Service": "test2",
727+
"Address": "192.168.0.10",
728+
"Port" : 8080,
729+
"TaggedAddresses": {
730+
"lan": {
731+
"Address": "192.168.0.10",
732+
"Port": 8080
733+
}
734+
}
735+
}
736+
}
737+
},
715738
{
716739
"Service": {
717740
"Verb": "set",
@@ -736,7 +759,7 @@ func TestTxnEndpoint_NodeService(t *testing.T) {
736759
}
737760
}
738761
]
739-
`, a.config.NodeName, a.config.NodeName)))
762+
`, a.config.NodeName, a.config.NodeName, a.config.NodeName)))
740763
req, _ := http.NewRequest("PUT", "/v1/txn", buf)
741764
resp := httptest.NewRecorder()
742765
obj, err := a.srv.Txn(resp, req)
@@ -747,7 +770,7 @@ func TestTxnEndpoint_NodeService(t *testing.T) {
747770
if !ok {
748771
t.Fatalf("bad type: %T", obj)
749772
}
750-
require.Equal(t, 2, len(txnResp.Results))
773+
require.Equal(t, 3, len(txnResp.Results))
751774

752775
index := txnResp.Results[0].Service.ModifyIndex
753776
expected := structs.TxnResponse{
@@ -768,6 +791,29 @@ func TestTxnEndpoint_NodeService(t *testing.T) {
768791
EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(),
769792
},
770793
},
794+
&structs.TxnResult{
795+
Service: &structs.NodeService{
796+
Service: "test2",
797+
ID: "test2",
798+
Address: "192.168.0.10",
799+
Port: 8080,
800+
TaggedAddresses: map[string]structs.ServiceAddress{
801+
"lan": {
802+
Address: "192.168.0.10",
803+
Port: 8080,
804+
},
805+
},
806+
Weights: &structs.Weights{
807+
Passing: 1,
808+
Warning: 1,
809+
},
810+
RaftIndex: structs.RaftIndex{
811+
CreateIndex: index,
812+
ModifyIndex: index,
813+
},
814+
EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(),
815+
},
816+
},
771817
&structs.TxnResult{
772818
Service: &structs.NodeService{
773819
Service: "test-sidecar-proxy",

0 commit comments

Comments
 (0)