Skip to content

Commit

Permalink
Adds external-source Metadata when register consul-esm as a service
Browse files Browse the repository at this point in the history
  • Loading branch information
johncowen authored and eikenb committed Jun 1, 2022
1 parent c7b53f4 commit 07b8246
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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}
Expand Down
3 changes: 3 additions & 0 deletions agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 07b8246

Please sign in to comment.