Skip to content

Commit

Permalink
Merge pull request #2768 from Polber/jkinard/2766
Browse files Browse the repository at this point in the history
Issue 2766 - hzn service log displays first instance of service name substring instead of exact string
  • Loading branch information
linggao committed Aug 19, 2021
2 parents 97db8ca + 7bea4a6 commit 40bb7c1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cli/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,28 @@ func Log(serviceName string, serviceVersion, containerName string, tailing bool)
// Search the list of services to find one that matches the input service name. The service's instance Id
// is what appears in the syslog, so we need to save that.
serviceFound := false
var serviceInstanceFound *api.MicroserviceInstanceOutput
var instanceId string
var msdefId string
org, name := cutil.SplitOrgSpecUrl(refUrl)
for _, serviceInstance := range runningServices.Instances["active"] {
if (serviceInstance.SpecRef == name && serviceInstance.Org == org) || strings.Contains(serviceInstance.SpecRef, refUrl) {
if serviceVersion == "" || serviceVersion == serviceInstance.Version {
instanceId = serviceInstance.InstanceId
msdefId = serviceInstance.MicroserviceDefId
if (serviceVersion == "" || serviceVersion == serviceInstance.Version) {
if serviceInstance.SpecRef == name && (serviceInstance.Org == org || org == "") {
serviceInstanceFound = serviceInstance
serviceFound = true
msgPrinter.Printf("Found service %v with service id %v.", serviceInstance.SpecRef, instanceId)
msgPrinter.Println()
break
} else if !serviceFound && strings.Contains(serviceInstance.SpecRef, name) && (serviceInstance.Org == org || org == "") {
serviceInstanceFound = serviceInstance
serviceFound = true
}
}
}
if !serviceFound {
if serviceFound {
instanceId = serviceInstanceFound.InstanceId
msdefId = serviceInstanceFound.MicroserviceDefId
msgPrinter.Printf("Found service %v with service id %v.", serviceInstanceFound.SpecRef, instanceId)
msgPrinter.Println()
} else {
if serviceVersion == "" {
cliutils.Fatal(cliutils.CLI_INPUT_ERROR, msgPrinter.Sprintf("Service %v is not running on the node.", refUrl))
} else {
Expand Down

0 comments on commit 40bb7c1

Please sign in to comment.