@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.
Modifier and Type | Class and Description |
---|---|
static class |
MetricsEnvironment.MetricsContainerHolder |
static interface |
MetricsEnvironment.MetricsEnvironmentState
Set the
MetricsContainer for the associated MetricsEnvironment . |
Constructor and Description |
---|
MetricsEnvironment() |
Modifier and Type | Method and Description |
---|---|
static @Nullable MetricsContainer |
getCurrentContainer()
Return the
MetricsContainer for the current thread. |
static MetricsEnvironment.MetricsEnvironmentState |
getMetricsEnvironmentStateForCurrentThread()
Returns the container holder for the current thread.
|
static @Nullable MetricsContainer |
getProcessWideContainer()
Return the
MetricsContainer for the current process. |
static boolean |
isMetricsSupported()
Indicates whether metrics reporting is supported.
|
static java.io.Closeable |
scopedMetricsContainer(MetricsContainer container)
Set the
MetricsContainer for the current thread. |
static @Nullable MetricsContainer |
setCurrentContainer(@Nullable 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.
|
static @Nullable MetricsContainer |
setProcessWideContainer(@Nullable MetricsContainer container)
Set the
MetricsContainer for the current process. |
public static MetricsEnvironment.MetricsEnvironmentState getMetricsEnvironmentStateForCurrentThread()
public static @Nullable MetricsContainer setCurrentContainer(@Nullable MetricsContainer container)
MetricsContainer
for the current thread.public static @Nullable MetricsContainer setProcessWideContainer(@Nullable MetricsContainer container)
MetricsContainer
for the current process.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.public static @Nullable 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.
public static @Nullable MetricsContainer getProcessWideContainer()
MetricsContainer
for the current process.