@Experimental(value=METRICS) @Internal public class MetricsEnvironment extends java.lang.Object
Users should not interact directly with this class. Instead, use Metrics
and the
returned objects to create and modify metrics.
The runner should create a MetricsContainer
for each context in which metrics are
reported (by step and name) and call setCurrentContainer(org.apache.beam.sdk.metrics.MetricsContainer)
before invoking any code that
may update metrics within that step. It should call setCurrentContainer(org.apache.beam.sdk.metrics.MetricsContainer)
again to restore
the previous container.
Alternatively, the runner can use scopedMetricsContainer(MetricsContainer)
to set the
container for the current thread and get a Closeable
that will restore the previous
container when closed.
Constructor and Description |
---|
MetricsEnvironment() |
Modifier and Type | Method and Description |
---|---|
static MetricsContainer |
getCurrentContainer()
Return the
MetricsContainer for the current thread. |
static boolean |
isMetricsSupported()
Indicates whether metrics reporting is supported.
|
static java.io.Closeable |
scopedMetricsContainer(MetricsContainer container)
Set the
MetricsContainer for the current thread. |
static MetricsContainer |
setCurrentContainer(MetricsContainer container)
Set the
MetricsContainer for the current thread. |
static void |
setMetricsSupported(boolean supported)
Called by the run to indicate whether metrics reporting is supported.
|
@Nullable public static MetricsContainer setCurrentContainer(@Nullable MetricsContainer container)
MetricsContainer
for the current thread.public static void setMetricsSupported(boolean supported)
public static boolean isMetricsSupported()
public static java.io.Closeable scopedMetricsContainer(MetricsContainer container)
MetricsContainer
for the current thread.Closeable
that will reset the current container to the previous
MetricsContainer
when closed.@Nullable public static MetricsContainer getCurrentContainer()
MetricsContainer
for the current thread.
May return null if metrics are not supported by the current runner or if the current thread is not a work-execution thread. The first time this happens in a given thread it will log a diagnostic message.