From a52fe969351fc7b603978a08c4d4b70130234611 Mon Sep 17 00:00:00 2001 From: srahul3 Date: Tue, 14 Jan 2025 11:22:47 +0530 Subject: [PATCH] Allowing esm to connect with server agents directly --- .vscode/launch.json | 8 ++++++++ agent.go | 9 +++++++++ config.hcl | 9 +++++++++ config2.hcl | 6 ++++++ config3.hcl | 12 ++++++++++++ config4.hcl | 10 ++++++++++ 6 files changed, 54 insertions(+) create mode 100644 config.hcl create mode 100644 config2.hcl create mode 100644 config3.hcl create mode 100644 config4.hcl diff --git a/.vscode/launch.json b/.vscode/launch.json index 4d1f1fd..dd0e851 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,6 +8,14 @@ "mode": "auto", "program": "${workspaceFolder}", "args": ["--config-file=${workspaceFolder}/config.hcl"] + }, + { + "name": "Launch Consul ESM with partition", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}", + "args": ["--config-file=${workspaceFolder}/config3.hcl"] } ] } \ No newline at end of file diff --git a/agent.go b/agent.go index 1a9daef..5827d27 100644 --- a/agent.go +++ b/agent.go @@ -85,6 +85,7 @@ func NewAgent(config *Config, logger hclog.Logger) (*Agent, error) { return nil, err } + client.AddHeader("X-Consul-Agent-Type", "esm") // Never used locally. I think we keep the reference to avoid GC. metricsConf, err := lib.InitTelemetry(config.Telemetry, logger) if err != nil { @@ -211,6 +212,14 @@ func (a *Agent) register() error { } a.HasPartition(func(partition string) { service.Partition = partition + + service.Check = &api.AgentServiceCheck{ + CheckID: "SerfHealth", + Name: "Serf Health Status", + Status: api.HealthPassing, + DeregisterCriticalServiceAfter: "120s", + TTL: "9999s", + } }) if a.config.Tag != "" { diff --git a/config.hcl b/config.hcl new file mode 100644 index 0000000..6092ce7 --- /dev/null +++ b/config.hcl @@ -0,0 +1,9 @@ +log_level = "DEBUG" +// instance_id = "agent-one" +http_addr = "consulserver-1805099012.us-west-2.elb.amazonaws.com:8500" +// main token +token = "a234daab-bfd1-cbd3-1f83-abf24e094b39" +// agent token +// token = "ab8c3616-3731-ed0f-77e4-45126e24ca74" +// instance_id = "a36ca779-ff11-dc3d-c610-31c017ab7156" +consul_service_tag = "vpc:vpc1" \ No newline at end of file diff --git a/config2.hcl b/config2.hcl new file mode 100644 index 0000000..d1159b8 --- /dev/null +++ b/config2.hcl @@ -0,0 +1,6 @@ +log_level = "DEBUG" +instance_id = "agent-two" +http_addr = "localhost:8500" +token = "a234daab-bfd1-cbd3-1f83-abf24e094b39" +// instance_id = "a36ca779-ff11-dc3d-c610-31c017ab7156" +consul_service_tag = "vpc:vpc2" \ No newline at end of file diff --git a/config3.hcl b/config3.hcl new file mode 100644 index 0000000..b7e036f --- /dev/null +++ b/config3.hcl @@ -0,0 +1,12 @@ +log_level = "DEBUG" +instance_id = "agent-three" +// http_addr = "localhost:8500" +//http_addr = "consulserver-1805099012.us-west-2.elb.amazonaws.com:8500" +http_addr = "52.36.169.149:8500" +//http_addr = "localhost:8500" +// token = "a234daab-bfd1-cbd3-1f83-abf24e094b39" +// scoped token +token = "52e7af34-4d54-43bf-8548-4861c39bdd5b" +// instance_id = "a36ca779-ff11-dc3d-c610-31c017ab7156" +consul_service_tag = "vpc:vpc2" +partition = "billing" \ No newline at end of file diff --git a/config4.hcl b/config4.hcl new file mode 100644 index 0000000..aa621f3 --- /dev/null +++ b/config4.hcl @@ -0,0 +1,10 @@ +log_level = "DEBUG" +// instance_id = "agent-two" +http_addr = "localhost:8500" +token = "a234daab-bfd1-cbd3-1f83-abf24e094b39" +// instance_id = "a36ca779-ff11-dc3d-c610-31c017ab7156" +consul_service_tag = "vpc:vpc2" +// The service name for this agent to use when registering itself with Consul. +consul_service = "billing:consul-esm" +// The directory in the Consul KV store to use for storing runtime data. +consul_kv_path = "billing:consul-esm/" \ No newline at end of file