Skip to content

Commit

Permalink
Allowing esm to connect with server agents directly
Browse files Browse the repository at this point in the history
  • Loading branch information
srahul3 committed Jan 14, 2025
1 parent 65c7897 commit a52fe96
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
]
}
9 changes: 9 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 != "" {
Expand Down
9 changes: 9 additions & 0 deletions config.hcl
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions config2.hcl
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 12 additions & 0 deletions config3.hcl
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions config4.hcl
Original file line number Diff line number Diff line change
@@ -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/"

0 comments on commit a52fe96

Please sign in to comment.