summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-02-02 15:17:23 +0100
committerAlex Auvolat <alex@adnab.me>2023-02-02 15:17:23 +0100
commit552fc7e5a0d623114901d4d8e8e29bfffa47e09c (patch)
tree324903c281474e15aea8e9d86b600c6ecb3999f0 /examples
parent19220178311ca80374f6f5ff4069c0adcaab932d (diff)
downloaddf-consul-552fc7e5a0d623114901d4d8e8e29bfffa47e09c.tar.gz
df-consul-552fc7e5a0d623114901d4d8e8e29bfffa47e09c.zip
Split into several files and make more APIs
Diffstat (limited to 'examples')
-rw-r--r--examples/health-service-1.json206
-rw-r--r--examples/test.rs59
2 files changed, 250 insertions, 15 deletions
diff --git a/examples/health-service-1.json b/examples/health-service-1.json
new file mode 100644
index 0000000..915b3a9
--- /dev/null
+++ b/examples/health-service-1.json
@@ -0,0 +1,206 @@
+[
+ {
+ "Node": {
+ "ID": "9ccf821c-5e3e-cbe0-3727-0b0e5df35412",
+ "Node": "celeri",
+ "Address": "10.83.1.3",
+ "Datacenter": "prod",
+ "TaggedAddresses": {
+ "lan": "10.83.1.3",
+ "lan_ipv4": "10.83.1.3",
+ "wan": "10.83.1.3",
+ "wan_ipv4": "10.83.1.3"
+ },
+ "Meta": {
+ "cname_target": "neptune.site.deuxfleurs.fr.",
+ "consul-network-segment": "",
+ "public_ipv4": "77.207.15.215",
+ "public_ipv6": "2001:910:1204:1::33",
+ "site": "neptune"
+ },
+ "CreateIndex": 28797576,
+ "ModifyIndex": 28797584
+ },
+ "Service": {
+ "ID": "_nomad-task-c7132dd2-cc89-cbb4-5e53-6bd7c8c33677-front-https-jitsi-https_port",
+ "Service": "https-jitsi",
+ "Tags": [
+ "jitsi",
+ "tricot jitsi.deuxfleurs.fr",
+ "d53-cname jitsi.deuxfleurs.fr"
+ ],
+ "Address": "10.83.1.3",
+ "TaggedAddresses": {
+ "lan_ipv4": {
+ "Address": "10.83.1.3",
+ "Port": 30140
+ },
+ "wan_ipv4": {
+ "Address": "10.83.1.3",
+ "Port": 30140
+ }
+ },
+ "Meta": {
+ "external-source": "nomad"
+ },
+ "Port": 30140,
+ "Weights": {
+ "Passing": 1,
+ "Warning": 1
+ },
+ "EnableTagOverride": false,
+ "Proxy": {
+ "Mode": "",
+ "MeshGateway": {},
+ "Expose": {}
+ },
+ "Connect": {},
+ "CreateIndex": 29922481,
+ "ModifyIndex": 29922481
+ },
+ "Checks": [
+ {
+ "Node": "celeri",
+ "CheckID": "serfHealth",
+ "Name": "Serf Health Status",
+ "Status": "critical",
+ "Notes": "",
+ "Output": "Agent not live or unreachable",
+ "ServiceID": "",
+ "ServiceName": "",
+ "ServiceTags": [],
+ "Type": "",
+ "Interval": "",
+ "Timeout": "",
+ "ExposedPort": 0,
+ "Definition": {},
+ "CreateIndex": 28797576,
+ "ModifyIndex": 32831331
+ },
+ {
+ "Node": "celeri",
+ "CheckID": "_nomad-check-1e8b81aa1790b51ffdf12117760d851bf00cb96f",
+ "Name": "service: \"https-jitsi\" check",
+ "Status": "passing",
+ "Notes": "",
+ "Output": "TCP connect 10.83.1.3:30140: Success",
+ "ServiceID": "_nomad-task-c7132dd2-cc89-cbb4-5e53-6bd7c8c33677-front-https-jitsi-https_port",
+ "ServiceName": "https-jitsi",
+ "ServiceTags": [
+ "jitsi",
+ "tricot jitsi.deuxfleurs.fr",
+ "d53-cname jitsi.deuxfleurs.fr"
+ ],
+ "Type": "tcp",
+ "Interval": "1m0s",
+ "Timeout": "1m0s",
+ "ExposedPort": 0,
+ "Definition": {},
+ "CreateIndex": 29922481,
+ "ModifyIndex": 29922617
+ }
+ ]
+ },
+ {
+ "Node": {
+ "ID": "cee1c827-ff32-6f38-a815-69038a961a80",
+ "Node": "dahlia",
+ "Address": "10.83.2.1",
+ "Datacenter": "prod",
+ "TaggedAddresses": {
+ "lan": "10.83.2.1",
+ "lan_ipv4": "10.83.2.1",
+ "wan": "10.83.2.1",
+ "wan_ipv4": "10.83.2.1"
+ },
+ "Meta": {
+ "cname_target": "orion.site.deuxfleurs.fr.",
+ "consul-network-segment": "",
+ "public_ipv4": "82.66.80.201",
+ "public_ipv6": "2a01:e0a:28f:5e60::11",
+ "site": "orion"
+ },
+ "CreateIndex": 31880680,
+ "ModifyIndex": 31880870
+ },
+ "Service": {
+ "ID": "_nomad-task-8214d936-aab2-35b4-d24e-8941a2d3b5b0-front-https-jitsi-https_port",
+ "Service": "https-jitsi",
+ "Tags": [
+ "jitsi",
+ "tricot jitsi.deuxfleurs.fr",
+ "d53-cname jitsi.deuxfleurs.fr"
+ ],
+ "Address": "10.83.2.1",
+ "TaggedAddresses": {
+ "lan_ipv4": {
+ "Address": "10.83.2.1",
+ "Port": 25753
+ },
+ "wan_ipv4": {
+ "Address": "10.83.2.1",
+ "Port": 25753
+ }
+ },
+ "Meta": {
+ "external-source": "nomad"
+ },
+ "Port": 25753,
+ "Weights": {
+ "Passing": 1,
+ "Warning": 1
+ },
+ "EnableTagOverride": false,
+ "Proxy": {
+ "Mode": "",
+ "MeshGateway": {},
+ "Expose": {}
+ },
+ "Connect": {},
+ "CreateIndex": 33002874,
+ "ModifyIndex": 33002874
+ },
+ "Checks": [
+ {
+ "Node": "dahlia",
+ "CheckID": "serfHealth",
+ "Name": "Serf Health Status",
+ "Status": "passing",
+ "Notes": "",
+ "Output": "Agent alive and reachable",
+ "ServiceID": "",
+ "ServiceName": "",
+ "ServiceTags": [],
+ "Type": "",
+ "Interval": "",
+ "Timeout": "",
+ "ExposedPort": 0,
+ "Definition": {},
+ "CreateIndex": 31880680,
+ "ModifyIndex": 31880680
+ },
+ {
+ "Node": "dahlia",
+ "CheckID": "_nomad-check-75542d8bde0dd9887ff8af10a02bf6a1f605695d",
+ "Name": "service: \"https-jitsi\" check",
+ "Status": "passing",
+ "Notes": "",
+ "Output": "TCP connect 10.83.2.1:25753: Success",
+ "ServiceID": "_nomad-task-8214d936-aab2-35b4-d24e-8941a2d3b5b0-front-https-jitsi-https_port",
+ "ServiceName": "https-jitsi",
+ "ServiceTags": [
+ "jitsi",
+ "tricot jitsi.deuxfleurs.fr",
+ "d53-cname jitsi.deuxfleurs.fr"
+ ],
+ "Type": "tcp",
+ "Interval": "1m0s",
+ "Timeout": "1m0s",
+ "ExposedPort": 0,
+ "Definition": {},
+ "CreateIndex": 33002874,
+ "ModifyIndex": 33002958
+ }
+ ]
+ }
+]
diff --git a/examples/test.rs b/examples/test.rs
index e7c34c8..ba29583 100644
--- a/examples/test.rs
+++ b/examples/test.rs
@@ -2,23 +2,52 @@ use df_consul::*;
#[tokio::main]
async fn main() {
- let config = ConsulConfig {
- addr: "http://localhost:8500".into(),
- ca_cert: None,
- tls_skip_verify: false,
- client_cert: None,
- client_key: None,
- };
+ let config = ConsulConfig {
+ addr: "http://localhost:8500".into(),
+ ca_cert: None,
+ tls_skip_verify: false,
+ client_cert: None,
+ client_key: None,
+ };
- let consul = Consul::new(config, "").unwrap();
+ let consul = Consul::new(config, "").unwrap();
- println!("== LIST NODES ==");
- let list_nodes = consul.list_nodes().await.unwrap();
- println!("{:?}", list_nodes);
+ println!("== LIST NODES ==");
+ let nodes = consul.catalog_node_list(None).await.unwrap();
+ println!("{:?}", nodes);
- println!("== CATALOG 1 ==");
- println!("{:?}", consul.watch_node("caribou", None).await.unwrap());
+ if let Some(node) = nodes.first() {
+ println!("== NODE {} ==", node.node);
+ println!("{:?}", consul.catalog_node(&node.node, None).await.unwrap());
+ }
- println!("== CATALOG 2 ==");
- println!("{:?}", consul.watch_node("cariacou", None).await.unwrap());
+ println!("== LIST SERVICES ==");
+ let services = consul.catalog_service_list(None).await.unwrap();
+ println!("{:?}", services);
+
+ if let Some(service) = services.keys().next() {
+ println!("== SERVICE NODES {} ==", service);
+ println!(
+ "{:?}",
+ consul.catalog_service_nodes(service, None).await.unwrap()
+ );
+
+ println!("== SERVICE HEALTH {} ==", service);
+ println!(
+ "{:?}",
+ consul
+ .health_service_instances(service, None)
+ .await
+ .unwrap()
+ );
+ }
+
+ println!("== WATCHING EVERYTHING ==");
+ let mut watch = consul.watch_all_service_health();
+ loop {
+ if watch.changed().await.is_err() {
+ break;
+ }
+ println!("\n{:?}", watch.borrow_and_update());
+ }
}