From 07b82466d4ae59251bad59a20024d696c03d4376 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Fri, 11 Dec 2020 11:20:34 +0000 Subject: [PATCH] Adds external-source Metadata when register consul-esm as a service --- agent.go | 7 +++++++ agent_test.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/agent.go b/agent.go index 82c58a4..f0d3dcc 100644 --- a/agent.go +++ b/agent.go @@ -170,6 +170,12 @@ func (a *Agent) serviceID() string { return fmt.Sprintf("%s:%s", a.config.Service, a.id) } +func (a *Agent) serviceMeta() map[string]string { + return map[string]string{ + "external-source": "consul-esm", + } +} + type alreadyExistsError struct { serviceID string } @@ -188,6 +194,7 @@ func (a *Agent) register() error { service := &api.AgentServiceRegistration{ ID: a.serviceID(), Name: a.config.Service, + Meta: a.serviceMeta(), } if a.config.Tag != "" { service.Tags = []string{a.config.Tag} diff --git a/agent_test.go b/agent_test.go index 2399212..93bb2f8 100644 --- a/agent_test.go +++ b/agent_test.go @@ -79,6 +79,9 @@ func TestAgent_registerServiceAndCheck(t *testing.T) { if got, want := services[0].ServiceTags, []string{"test"}; !reflect.DeepEqual(got, want) { r.Fatalf("got %q, want %q", got, want) } + if got, want := services[0].ServiceMeta, map[string]string{"external-source": "consul-esm"}; !reflect.DeepEqual(got, want) { + r.Fatalf("got %q, want %q", got, want) + } checks, _, err := agent.client.Health().Checks(agent.config.Service, nil) if err != nil {