private Predicate<ServiceInstance> relatedInstanceFilter(ServiceInstance instance, Optional<Attribute> hostAttr) {
        return candidate -> {
            // both names equals
            if (candidate.getName().equals(instance.getName())) {
                return true;
            }
            if (hostAttr.isPresent()) {
                // both hosts equals
                if (candidate.getAttributes().contains(hostAttr.get())) {
                    return true;
                }
                // name equals host
                if (candidate.getName().equals(hostAttr.get().getValue())) {
                    return true;
                }
                // host equals name
                return candidate.getAttributes()
                                .stream()
                                .filter(hostAttrFilter())
                                .anyMatch(attr -> attr.getValue().equals(instance.getName()));
            }
            return false;
        };
    }
@return return the related service hierarchy recursively, e.g. A-B-C, query A will return A-B, B-C
If the relation could be conjectured will be removed, e.g. A-B-C-D and A-D, query A will return A-B, B-C, C-D because A-D could be conjectured.
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/HierarchyQueryService.java