public static @Nullable MetricsContainer getCurrentContainer() {
    MetricsContainer container = CONTAINER_FOR_THREAD.get().container;
    if (container == null && REPORTED_MISSING_CONTAINER.compareAndSet(false, true)) {
      if (isMetricsSupported()) {
        LOG.error(
            "Unable to update metrics on the current thread. Most likely caused by using metrics "
                + "outside the managed work-execution thread:\n  {}",
            StringUtils.arrayToNewlines(Thread.currentThread().getStackTrace(), 10));
      } else {
        // rate limiting this log as it can be emitted each time metrics incremented
        LOG.warn(
            "Reporting metrics are not supported in the current execution environment:\n  {}",
            StringUtils.arrayToNewlines(Thread.currentThread().getStackTrace(), 10));
      }
    }
    return container;
  }
@Test
  public void testBehavesWithoutMetricsContainer() {
    assertNull(MetricsEnvironment.getCurrentContainer());
  }