open-consul/api
hc-github-team-consul-core ea93c7b29c
Backport of Displays Consul version of each nodes in UI nodes section into release/1.16.x (#18113)
## 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>
2023-07-17 17:27:50 +00:00
..
watch Backport of watch: support -filter for consul watch: checks, services, nodes, service into release/1.16.x (#17965) 2023-06-30 12:59:28 -07:00
.golangci.yml ci: Use golangci-lint for linting 2020-03-17 13:43:40 -04:00
README.md Update the README for the Consul API (#15936) 2023-01-06 21:10:56 +00:00
acl.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
acl_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
agent.go Add version endpoint (#17506) 2023-05-30 17:25:48 -05:00
agent_test.go api: enable query options on agent force-leave endpoint (#15987) 2023-04-18 11:31:48 -05:00
api.go Accept ap, datacenter, and namespace query params (#17525) 2023-05-31 11:50:24 -04:00
api_test.go Backport of backport ent changes to oss into release/1.16.x (#17617) 2023-06-08 16:45:28 +00:00
catalog.go api: ensure empty locality field is not transmitted to Consul (#17137) 2023-04-26 10:01:17 -05:00
catalog_test.go Backport of Displays Consul version of each nodes in UI nodes section into release/1.16.x (#18113) 2023-07-17 17:27:50 +00:00
config_entry.go backport of commit c0afba3a0c2ae093fee756a9019d49db25367d69 (#17975) 2023-06-30 14:20:50 +00:00
config_entry_discoverychain.go fixed aliases for sameness group (sameness_group) (#17161) 2023-04-26 14:53:23 -07:00
config_entry_discoverychain_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
config_entry_exports.go add sameness to exported services structs in the api package (#16984) 2023-04-12 16:49:28 -04:00
config_entry_exports_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
config_entry_gateways.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
config_entry_gateways_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
config_entry_inline_certificate.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
config_entry_inline_certificate_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
config_entry_intentions.go add sameness intentions in api package (#17096) 2023-04-26 10:00:18 -04:00
config_entry_intentions_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
config_entry_jwt_provider.go Expose JWKS cluster config through JWTProviderConfigEntry (#17978) (#18002) 2023-07-04 09:53:12 -04:00
config_entry_jwt_provider_test.go Expose JWKS cluster config through JWTProviderConfigEntry (#17978) (#18002) 2023-07-04 09:53:12 -04:00
config_entry_mesh.go Permissive mTLS (#17035) 2023-04-19 14:45:00 -05:00
config_entry_rate_limit_ip.go fix rate limiting mapping to be the same between api and struct packages (#17599) 2023-06-07 14:50:22 -04:00
config_entry_routes.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
config_entry_sameness_group.go Fix a bug with disco chain config entry fetching (#17078) 2023-04-21 09:18:32 -04:00
config_entry_status.go APIGW: Update how status conditions for certificates are handled (#17115) 2023-04-27 15:54:44 +00:00
config_entry_status_test.go APIGW Normalize Status Conditions (#16994) 2023-04-24 16:22:55 -04:00
config_entry_test.go Support Envoy's MaxEjectionPercent and BaseEjectionTime config entries for passive health checks (#15979) 2023-04-26 15:59:48 -07:00
connect.go Rename hcp-metrics-collector to consul-telemetry-collector (#17327) 2023-05-16 14:36:05 -04:00
connect_ca.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
connect_ca_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
connect_intention.go Add sameness groups to service intentions. (#17064) 2023-04-20 12:16:04 -04:00
connect_intention_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
coordinate.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
coordinate_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
debug.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
debug_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
discovery_chain.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
discovery_chain_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
event.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
event_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
go.mod Update api submodule sdk dependency 2023-06-08 16:03:08 -04:00
go.sum Update api submodule sdk dependency 2023-06-08 16:03:08 -04:00
health.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
health_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
internal.go Add /v1/internal/service-virtual-ip for manually setting service VIPs (#17294) 2023-05-12 00:38:52 +00:00
internal_test.go Add /v1/internal/service-virtual-ip for manually setting service VIPs (#17294) 2023-05-12 00:38:52 +00:00
kv.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
kv_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
lock.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
lock_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
mock_api_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
namespace.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
namespace_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_area.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_autopilot.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_autopilot_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_keyring.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_keyring_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_license.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_raft.go Backport of [NET-3865] [Supportability] Additional Information in the output of 'consul operator raft list-peers' into release/1.16.x (#17738) 2023-06-21 11:26:48 +05:30
operator_raft_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_segment.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
operator_usage.go Backport of feat: include nodes count in operator usage endpoint and cli command into release/1.16.x (#18012) 2023-07-05 15:37:51 +00:00
operator_usage_test.go Backport of [API Gateway] Fix rate limiting for API gateways into release/1.16.x (#17635) 2023-06-09 12:40:03 +00:00
oss_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
partition.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
peering.go api: ensure empty locality field is not transmitted to Consul (#17137) 2023-04-26 10:01:17 -05:00
peering_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
prepared_query.go Add sameness group field to prepared queries (#17089) 2023-04-24 13:21:28 -07:00
prepared_query_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
raw.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
semaphore.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
semaphore_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
session.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
session_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
snapshot.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
snapshot_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
status.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
status_test.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
txn.go Add copyright headers for acl, api and bench folders (#16706) 2023-03-28 16:12:41 -04:00
txn_test.go Backport of Displays Consul version of each nodes in UI nodes section into release/1.16.x (#18113) 2023-07-17 17:27:50 +00:00

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