github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/serviceregistration/id.go (about)

     1  package serviceregistration
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/nomad/nomad/structs"
     7  )
     8  
     9  const (
    10  	// nomadServicePrefix is the prefix that scopes all Nomad registered
    11  	// services (both agent and task entries).
    12  	nomadServicePrefix = "_nomad"
    13  
    14  	// nomadTaskPrefix is the prefix that scopes Nomad registered services
    15  	// for tasks.
    16  	nomadTaskPrefix = nomadServicePrefix + "-task-"
    17  )
    18  
    19  // MakeAllocServiceID creates a unique ID for identifying an alloc service in
    20  // a service registration provider. Both Nomad and Consul solutions use the
    21  // same ID format to provide consistency.
    22  //
    23  // Example Service ID: _nomad-task-b4e61df9-b095-d64e-f241-23860da1375f-redis-http-http
    24  func MakeAllocServiceID(allocID, taskName string, service *structs.Service) string {
    25  	return fmt.Sprintf("%s%s-%s-%s-%s",
    26  		nomadTaskPrefix, allocID, taskName, service.Name, service.PortLabel)
    27  }