static Collection getConfig()

in src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/BlockedThreadsConfigurator.java [72:110]


  static Collection<Threshold> getConfig(String[] thresholds) {
    // Threshold can be defined as a sole value e.g
    //  threshold = 80
    // and would become a default one for all blocked threads check or as a set of specific thread
    // groups checks defined like
    //  threshold = foo=30
    //  threshold = bar=40
    //  ...
    // they are mutually exclusive which means that one either checks all threads or groups
    Map<Boolean, List<Threshold>> specsClassified =
        Arrays.stream(thresholds)
            .filter(spec -> !spec.isEmpty())
            .map(BlockedThreadsConfigurator::getSpec)
            .filter(Optional::isPresent)
            .map(Optional::get)
            .collect(groupingBy(Threshold::hasPrefix));

    // check configuration consistency
    if (specsClassified.size() > 1) {
      Collection<Threshold> specs = deduplicatePrefixes(specsClassified.get(true));
      log.warn(
          "Global and specific thresholds were configured for blocked threads check. Specific"
              + " configuration is used {}.",
          specs);
      return specs;
    }

    if (specsClassified.size() == 1) {
      Map.Entry<Boolean, List<Threshold>> entry = specsClassified.entrySet().iterator().next();
      return Boolean.TRUE == entry.getKey()
          ? deduplicatePrefixes(entry.getValue())
          : deduplicateGlobal(entry.getValue());
    }

    log.info(
        "Default blocked threads check is configured with {}% threshold",
        DEFAULT_BLOCKED_THREADS_THRESHOLD);
    return ImmutableSet.of(new Threshold(DEFAULT_BLOCKED_THREADS_THRESHOLD));
  }