Skip to content

Backport of Refactor Txn API to use AgentService and add TaggedAddresses support into release/1.15.x#22308

Closed
srahul3 wants to merge 1 commit into
release/1.15.xfrom
srahul3/backport/txn-api-missing-fields/release/1.15.x
Closed

Backport of Refactor Txn API to use AgentService and add TaggedAddresses support into release/1.15.x#22308
srahul3 wants to merge 1 commit into
release/1.15.xfrom
srahul3/backport/txn-api-missing-fields/release/1.15.x

Conversation

@srahul3
Copy link
Copy Markdown
Collaborator

@srahul3 srahul3 commented May 2, 2025

Backport

This PR is auto-generated from #22248 to be assessed for backporting due to the inclusion of the label backport/1.51.

The person who merged in the original PR is:
@nitin-sachdev-29
This person should manually cherry-pick the original PR into a new backport PR,
and close this one when the manual backport PR is merged in.

Description

This PR fixes the Golang Consul API Client Library Unmarshalling error when using the Transaction API with Service that has TaggedAddresses, see #22180 (comment).

Below is a summary of the current Service Transaction Workflow when using the Golang Consul API Client Library:

  1. The Txn client specifies Service information to update as an api.AgentService in an api.ServiceTxnOp to submit to the Agent Txn endpoint.

  2. In the Agent Txn endpoint, it converts the api.AgentService to a structs.NodeService
    that is used internally for applying the transaction.

  3. After the transaction is applied, the structs.TxnResponse that is returned to the client contains the Service information as a structs.NodeService in the structs.TxnServiceResult.

  4. The Txn client tries to decode the returned response as an api.TxnResponse which uses api.CatalogService for the Service TxnResult.

  5. When a Service has TaggedAddresses, the decoding fails with json: cannot unmarshal object into Go struct field CatalogService.Results.Service.TaggedAddresses of type string. This is because structs.NodeService has TaggedAddresses as a map[string]structs.ServiceAddress, while api.CatalogService has TaggedAddresses as a map[string]string which is intended to be the node's TaggedAddresses and the Service's TaggedAddresses` is in ServiceTaggedAddresses field.

The proposed fix here is to change the Golang Consul Client Library to use api.AgentService for the Service TxnResult which has fields that are compatible for conversion from structs.NodeService
returned from the agent endpoint.

This change will require applications that use the Golang Consul Client Library for Service Transactions to do a small code change once they choose to upgrade the library to the new release (they will get notified with compile errors). Considering that any such clients are already in a broken state (if there are any such users besides us), it should be fine ok require such a change. api.AgentService appears to be the more appropriate Service TxnResult type, it matches the Txn input type and it is the return type for other endpoints such as health/service.

If we do still want to maintain api.CatalogService as the Service TxnResult type, then we could just add a best-effort conversion from api.AgentService to api.CatalogService before returning in the client library.

PR Checklist

  • updated test coverage
  • not a security concern

@srahul3 srahul3 requested a review from a team as a code owner May 2, 2025 07:52
@github-actions github-actions Bot added the theme/api Relating to the HTTP API interface label May 2, 2025
@srahul3 srahul3 added pr/no-changelog PR does not need a corresponding .changelog entry pr/no-backport labels May 2, 2025
@nitin-sachdev-29
Copy link
Copy Markdown
Contributor

Since 1.15 is an older version the changes are not merged in CE. The required changes are merged in enterprise repo.

@github-actions github-actions Bot deleted the srahul3/backport/txn-api-missing-fields/release/1.15.x branch October 30, 2025 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/no-backport pr/no-changelog PR does not need a corresponding .changelog entry theme/api Relating to the HTTP API interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants