Skip to content

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

Merged
nitin-sachdev-29 merged 2 commits into
release/1.21.xfrom
backport/nitin/txn-api-missing-fields/really-novel-primate
Mar 14, 2025
Merged

Backport of Add the missing Service TaggedAddresses and Check Type fields to Txn API into release/1.21.x#22221
nitin-sachdev-29 merged 2 commits into
release/1.21.xfrom
backport/nitin/txn-api-missing-fields/really-novel-primate

Conversation

@hc-github-team-consul-core
Copy link
Copy Markdown
Collaborator

Backport

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

The below text is copied from the body of the original PR.


Description

Update: looks like there is an issue with API package unable to unmarshall TxnResult when the service has TaggedAddresses set. This issue should be resolved first before this PR.

Consul Transaction API Service Operation does not register the TaggedAddresses field in the AgentService struct that is sent from the client. Same with the Type field in the HealthCheck struct.

Testing & Reproduction steps

  1. Create a Transaction API input file txn.json
[
{
    "Node": {
        "Verb": "set",
        "Node": {
            "Node": "n1",
            "Address": "192.168.0.10"
        }
    }
},
{
    "Service": {
        "Verb": "set",
        "Node": "n1",
        "Service": {
            "ID": "s1",
            "Service": "s1",
            "Address": "192.168.0.10",
            "TaggedAddresses": {
                "lan": {
                    "Address": "192.168.0.10",
                    "Port": 8080
                }
            },
            "Port": 8080
        }
        }
},
{
    "Check": {
        "Verb": "set",
        "Check": {
            "Node": "n1",
            "CheckID": "healthcheck",
            "Name": "healthcheck",
            "Status": "passing",
            "ServiceID": "s1",
            "ServiceName": "s1",
            "Definition": {
                "HTTP": "http://localhost:8080",
                "Interval": "10s"
            },
            "Type": "http"
        }
    }
}
]
  1. Start Consul in Agent mode.
docker run -p 8500:8500 hashicorp/consul:1.20
  1. Submit the transaction, returns success but Service TaggedAddresses and Check Type are not registered.
curl --request PUT --data @txn2.json http://127.0.0.1:8500/v1/txn

{
    "Results": [
        {
            "Node": {
                "ID": "",
                "Node": "n1",
                "Address": "192.168.0.10",
                "Datacenter": "dc1",
                "TaggedAddresses": null,
                "Meta": null,
                "CreateIndex": 18,
                "ModifyIndex": 18
            }
        },
        {
            "Service": {
                "ID": "s1",
                "Service": "s1",
                "Tags": null,
                "Address": "192.168.0.10",
                "Meta": null,
                "Port": 8080,
                "Weights": {
                    "Passing": 1,
                    "Warning": 1
                },
                "EnableTagOverride": false,
                "Proxy": {
                    "Mode": "",
                    "MeshGateway": {},
                    "Expose": {}
                },
                "Connect": {},
                "PeerName": "",
                "CreateIndex": 18,
                "ModifyIndex": 18
            }
        },
        {
            "Check": {
                "Node": "n1",
                "CheckID": "healthcheck",
                "Name": "healthcheck",
                "Status": "passing",
                "Notes": "",
                "Output": "",
                "ServiceID": "s1",
                "ServiceName": "s1",
                "ServiceTags": null,
                "Type": "",
                "Interval": "",
                "Timeout": "",
                "ExposedPort": 0,
                "Definition": {
                    "Interval": "10s",
                    "HTTP": "http://localhost:8080"
                },
                "CreateIndex": 18,
                "ModifyIndex": 18
            }
        }
    ],
    "Errors": null

Relevant Unit Test:
https://github.com/jzou-rbx/consul/blob/4d76a43dc6d0ad9dacd6079c7b34d128baad12c7/agent/txn_endpoint_test.go#L533
does not test for the Type field in a check.

https://github.com/jzou-rbx/consul/blob/4d76a43dc6d0ad9dacd6079c7b34d128baad12c7/agent/txn_endpoint_test.go#L703 does not test for the TaggedAddresses field in a regular service.

The test build after the PR now work properly to include these fields when submitting the same input above to the Transaction API.

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

Overview of commits

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved Consul Bot automated PR

Copy link
Copy Markdown
Contributor

@nitin-sachdev-29 nitin-sachdev-29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nitin-sachdev-29 nitin-sachdev-29 merged commit a9b583b into release/1.21.x Mar 14, 2025
@nitin-sachdev-29 nitin-sachdev-29 deleted the backport/nitin/txn-api-missing-fields/really-novel-primate branch March 14, 2025 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants