Skip to content

Conversation

@LakshmiNarayananDesikan
Copy link
Contributor

Description

The services can be imported across partitions with in a local data center. However there is no API to List the services imported by the downstream partition. The new API /v1/imported-services Lists the imported services across partitions with in a local datacenter.

Testing & Reproduction steps

Step 1: Create consul server agents
Step 2: Create partitions
consul partition create -name upstream -description "Upstream partition with services" -token=root
consul partition create -name downstream -description "Downstream partition consuming services" -token=root
Step 3: Run separate consul client agents for each partitions.
Step 4: Register the services in partitions

consul services register -token=root -http-addr=http://localhost:8510 payment-service.json

payment-service.json

{
  "service": {
    "id": "payments-1",
    "name": "payments",
    "tags": ["upstream", "api", "v1"],
    "port": 8080,
    "address": "127.0.0.1",
    "meta": {
      "version": "1.0.0",
      "environment": "test"
    },
    "check": {
      "name": "Always passing check",
      "ttl": "30s",
      "status": "passing"
    }
  }
}

consul services register -token=root -http-addr=http://localhost:8520 billing-service.json

billing-service.json

{
  "service": {
    "id": "billing-1",
    "name": "billing",
    "tags": ["downstream", "finance", "api", "v2"],
    "port": 8081,
    "address": "127.0.0.1",
    "meta": {
      "version": "2.1.0",
      "environment": "test",
      "team": "finance"
    },
    "check": {
      "name": "Always passing check",
      "ttl": "30s",
      "status": "passing"
    }
  }
}

consul config write -http-addr=http://localhost:8520 -token=root exported-services.hcl

exported-services.hcl

Kind = "exported-services"
Name = "upstream"
Partition = "upstream"

Services = [
  {
    Name = "payments"
    Namespace = "default"
    Consumers = [
      {
        Partition = "downstream"
      }
    ]
  }
]

Step 5: Below curl will help in fetching the imported services

curl -s -H "X-Consul-Token: root" \
  'http://localhost:8500/v1/imported-services?partition=downstream'

Links

PR Checklist

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

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@LakshmiNarayananDesikan LakshmiNarayananDesikan added the backport/1.22 Changes are backported to 1.22 label Jan 1, 2026
@github-actions github-actions bot added theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface labels Jan 1, 2026
return 0
}

if c.format == JSONFormat {
Copy link
Contributor

Choose a reason for hiding this comment

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

wont switch case be better? In case we add more formats in future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

return 0
}

c.UI.Output(formatImportedServices(filteredServices))
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be default case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return uniqueImportedServices[i].peer < uniqueImportedServices[j].peer
})

return uniqueImportedServices
Copy link
Contributor

Choose a reason for hiding this comment

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

we are looping over a lot services, intentions throughout this code piece, I feel it could be a performance issue, should we rather paginate the response? that way we wont have to process each of the intention and service, etc. for every call.

Since this does not hamper the core functionality, it is not a blocker, however worth discussing once and can be planned for phase 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will discuss and plan it for Phase 2

@LakshmiNarayananDesikan LakshmiNarayananDesikan merged commit 7ee7c79 into main Jan 12, 2026
104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/1.22 Changes are backported to 1.22 pr/no-metrics-test theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants