ea93c7b29c
## Backport This PR is auto-generated from #17754 to be assessed for backporting due to the inclusion of the label backport/1.16. 🚨 >**Warning** automatic cherry-pick of commits failed. If the first commit failed, you will see a blank no-op commit below. If at least one commit succeeded, you will see the cherry-picked commits up to, _not including_, the commit where the merge conflict occurred. The person who merged in the original PR is: @WenInCode 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. > merge conflict error: unable to process merge commit: "1c757b8a2c1160ad53421b7b8bd7f74b205c4b89", automatic backport requires rebase workflow The below text is copied from the body of the original PR. --- fixes #17097 Consul version of each nodes in UI nodes section @jkirschner-hashicorp @huikang @team @Maintainers Updated consul version in the request to register consul. Added this as Node MetaData. Fetching this new metadata in UI <img width="1512" alt="Screenshot 2023-06-15 at 4 21 33 PM" src="https://github.com/hashicorp/consul/assets/3139634/94f7cf6b-701f-4230-b9f7-d8c4342d0737"> Also made this backward compatible and tested. Backward compatible in this context means - If consul binary with above PR changes is deployed to one of node, and if UI is run from this node, then the version of not only current (upgraded) node is displayed in UI , but also of older nodes given that they are consul servers only. For older (non-server or client) nodes the version is not added in NodeMeta Data and hence the version will not be displayed for them. If a old node is consul server, the version will be displayed. As the endpoint - "v1/internal/ui/nodes?dc=dc1" was already returning version in service meta. This is made use of in current UI changes. <img width="1480" alt="Screenshot 2023-06-16 at 6 58 32 PM" src="https://github.com/hashicorp/consul/assets/3139634/257942f4-fbed-437d-a492-37849d2bec4c"> --- <details> <summary> Overview of commits </summary> - 931fdfc7ecdc26bb7cc20b698c5e14c1b65fcc6e - b3e2ec1ccaca3832a088ffcac54257fa6653c6c1 - 8d0e9a54907039c09330c6cd7b9e761566af6856 - 04e5d88cca37821f6667be381c16aaa5958b5c92 - 28286a2e98f8cd66ef8593c2e2893b4db6080417 - 43e50ad38207952a9c4d04d45d08b6b8f71b31fe - 0cf1b7077cdf255596254d9dc1624a269c42b94d - 27f34ce1c2973591f75b1e38a81ccbe7cee6cee3 - 2ac76d62b8cbae76b1a903021aebb9b865e29d6e - 3d618df9ef1d10dd5056c8b1ed865839c553a0e0 - 1c757b8a2c1160ad53421b7b8bd7f74b205c4b89 - 23ce82b4cee8f74dd634dbe145313e9a56c0077d - 4dc1c9b4c5aafdb8883ef977dfa9b39da138b6cb - 85a12a92528bfa267a039a9bb258170be914abf7 - 25d30a3fa980d130a30d445d26d47ef2356cb553 - 7f1d6192dce3352e92307175848b89f91e728c24 - 5174cbff84b0795d4cb36eb8980d0d5336091ac9 </details> --------- Co-authored-by: Vijay Srinivas <vijayraghav22@gmail.com> Co-authored-by: John Murret <john.murret@hashicorp.com> Co-authored-by: Jared Kirschner <85913323+jkirschner-hashicorp@users.noreply.github.com> |
||
---|---|---|
.. | ||
watch | ||
.golangci.yml | ||
README.md | ||
acl.go | ||
acl_test.go | ||
agent.go | ||
agent_test.go | ||
api.go | ||
api_test.go | ||
catalog.go | ||
catalog_test.go | ||
config_entry.go | ||
config_entry_discoverychain.go | ||
config_entry_discoverychain_test.go | ||
config_entry_exports.go | ||
config_entry_exports_test.go | ||
config_entry_gateways.go | ||
config_entry_gateways_test.go | ||
config_entry_inline_certificate.go | ||
config_entry_inline_certificate_test.go | ||
config_entry_intentions.go | ||
config_entry_intentions_test.go | ||
config_entry_jwt_provider.go | ||
config_entry_jwt_provider_test.go | ||
config_entry_mesh.go | ||
config_entry_rate_limit_ip.go | ||
config_entry_routes.go | ||
config_entry_sameness_group.go | ||
config_entry_status.go | ||
config_entry_status_test.go | ||
config_entry_test.go | ||
connect.go | ||
connect_ca.go | ||
connect_ca_test.go | ||
connect_intention.go | ||
connect_intention_test.go | ||
coordinate.go | ||
coordinate_test.go | ||
debug.go | ||
debug_test.go | ||
discovery_chain.go | ||
discovery_chain_test.go | ||
event.go | ||
event_test.go | ||
go.mod | ||
go.sum | ||
health.go | ||
health_test.go | ||
internal.go | ||
internal_test.go | ||
kv.go | ||
kv_test.go | ||
lock.go | ||
lock_test.go | ||
mock_api_test.go | ||
namespace.go | ||
namespace_test.go | ||
operator.go | ||
operator_area.go | ||
operator_autopilot.go | ||
operator_autopilot_test.go | ||
operator_keyring.go | ||
operator_keyring_test.go | ||
operator_license.go | ||
operator_raft.go | ||
operator_raft_test.go | ||
operator_segment.go | ||
operator_usage.go | ||
operator_usage_test.go | ||
oss_test.go | ||
partition.go | ||
peering.go | ||
peering_test.go | ||
prepared_query.go | ||
prepared_query_test.go | ||
raw.go | ||
semaphore.go | ||
semaphore_test.go | ||
session.go | ||
session_test.go | ||
snapshot.go | ||
snapshot_test.go | ||
status.go | ||
status_test.go | ||
txn.go | ||
txn_test.go |
README.md
Consul API Client
This package provides the api
package which provides programmatic access to the full Consul API.
The full documentation is available on Godoc.
Usage
Below is an example of using the Consul client. To run the example, you must first install Consul and Go.
To run the client API, create a new Go module.
go mod init consul-demo
Copy the example code into a file called main.go
in the directory where the module is defined.
As seen in the example, the Consul API is often imported with the alias capi
.
package main
import (
"fmt"
capi "github.com/hashicorp/consul/api"
)
func main() {
// Get a new client
client, err := capi.NewClient(capi.DefaultConfig())
if err != nil {
panic(err)
}
// Get a handle to the KV API
kv := client.KV()
// PUT a new KV pair
p := &capi.KVPair{Key: "REDIS_MAXCLIENTS", Value: []byte("1000")}
_, err = kv.Put(p, nil)
if err != nil {
panic(err)
}
// Lookup the pair
pair, _, err := kv.Get("REDIS_MAXCLIENTS", nil)
if err != nil {
panic(err)
}
fmt.Printf("KV: %v %s\n", pair.Key, pair.Value)
}
Install the Consul API dependency with go mod tidy
.
In a separate terminal window, start a local Consul server.
consul agent -dev -node machine
Run the example.
go run .
You should get the following result printed to the terminal.
KV: REDIS_MAXCLIENTS 1000
After running the code, you can also view the values in the Consul UI on your local machine at http://localhost:8500/ui/dc1/kv