Skip to content

Commit

Permalink
Add marathon-task tag to registered service
Browse files Browse the repository at this point in the history
  • Loading branch information
Oskar Jagodzinski authored and tomez committed Aug 6, 2019
1 parent ff8224d commit 2c38f27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions hook/consul/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ func (h *Hook) RegisterIntoConsul(taskInfo mesosutils.TaskInfo) error {
// it registers the service
// See: https://github.com/allegro/marathon-consul/blob/v1.1.0/consul/consul.go#L299-L301
consulServiceID := fmt.Sprintf("%s_%s_%d", taskID, portServiceName, port.GetNumber())
marathonTaskTag := fmt.Sprintf("marathon-task:%s", taskID)
portTags := mesosutils.GetLabelKeysByValue(port.GetLabels().GetLabels(), consulTagValue)
portTags = append(portTags, globalTags...)
portTags = append(portTags, marathonTaskTag)
log.Infof("Adding service ID %q to deregister before termination", consulServiceID)
instancesToRegister = append(instancesToRegister, instance{
consulServiceName: portServiceName,
Expand Down
8 changes: 4 additions & 4 deletions hook/consul/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ func TestIfUsesPortLabelsForRegistration(t *testing.T) {
consulServiceName: "consulName",
consulServiceID: createServiceID(taskID, consulName, 666),
port: 666,
tags: []string{"hystrix", "metrics", "extras", "marathon"},
tags: []string{"hystrix", "metrics", "extras", "marathon", "marathon-task:taskID"},
}
expectedService2 := instance{
consulServiceName: "consulName-secured",
consulServiceID: createServiceID(taskID, consulNameSecond, 997),
port: 997,
tags: []string{"metrics", "extras", "marathon"},
tags: []string{"metrics", "extras", "marathon", "marathon-task:taskID"},
}

// Create a test Consul server
Expand Down Expand Up @@ -375,8 +375,8 @@ func TestIfPlaceholdersAreResolved(t *testing.T) {
{Number: 877, Name: &servicePortName},
})

expectedServiceTags := []string{"marathon", "service-port:877", "admin-port:655", "{port:unknown} is not replaced"}
expectedAdminTags := []string{"marathon", "admin", "service-port:877"}
expectedServiceTags := []string{"marathon", "service-port:877", "admin-port:655", "{port:unknown} is not replaced", "marathon-task:taskId"}
expectedAdminTags := []string{"marathon", "admin", "service-port:877", "marathon-task:taskId"}

h := &Hook{config: Config{ConsulGlobalTag: "marathon"}, client: client}

Expand Down

0 comments on commit 2c38f27

Please sign in to comment.