Class MetricsEnvironment
- java.lang.Object
-
- org.apache.beam.sdk.metrics.MetricsEnvironment
-
@Experimental(METRICS) @Internal public class MetricsEnvironment extends java.lang.Object
Manages and provides the metrics container associated with each thread.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 callsetCurrentContainer(org.apache.beam.sdk.metrics.MetricsContainer)
before invoking any code that may update metrics within that step. It should callsetCurrentContainer(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 aCloseable
that will restore the previous container when closed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MetricsEnvironment.MetricsContainerHolder
static interface
MetricsEnvironment.MetricsEnvironmentState
Set theMetricsContainer
for the associatedMetricsEnvironment
.
-
Constructor Summary
Constructors Constructor Description MetricsEnvironment()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @Nullable MetricsContainer
getCurrentContainer()
Return theMetricsContainer
for the current thread.static MetricsEnvironment.MetricsEnvironmentState
getMetricsEnvironmentStateForCurrentThread()
Returns the container holder for the current thread.static @Nullable MetricsContainer
getProcessWideContainer()
Return theMetricsContainer
for the current process.static boolean
isMetricsSupported()
Indicates whether metrics reporting is supported.static java.io.Closeable
scopedMetricsContainer(MetricsContainer container)
Set theMetricsContainer
for the current thread.static @Nullable MetricsContainer
setCurrentContainer(@Nullable MetricsContainer container)
Set theMetricsContainer
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 theMetricsContainer
for the current process.
-
-
-
Method Detail
-
getMetricsEnvironmentStateForCurrentThread
public static MetricsEnvironment.MetricsEnvironmentState getMetricsEnvironmentStateForCurrentThread()
Returns the container holder for the current thread.
-
setCurrentContainer
public static @Nullable MetricsContainer setCurrentContainer(@Nullable MetricsContainer container)
Set theMetricsContainer
for the current thread.- Returns:
- The previous container for the current thread.
-
setProcessWideContainer
public static @Nullable MetricsContainer setProcessWideContainer(@Nullable MetricsContainer container)
Set theMetricsContainer
for the current process.- Returns:
- The previous container for the current process.
-
setMetricsSupported
public static void setMetricsSupported(boolean supported)
Called by the run to indicate whether metrics reporting is supported.
-
isMetricsSupported
public static boolean isMetricsSupported()
Indicates whether metrics reporting is supported.
-
scopedMetricsContainer
public static java.io.Closeable scopedMetricsContainer(MetricsContainer container)
Set theMetricsContainer
for the current thread.- Returns:
- A
Closeable
that will reset the current container to the previousMetricsContainer
when closed.
-
getCurrentContainer
public static @Nullable MetricsContainer getCurrentContainer()
Return theMetricsContainer
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.
-
getProcessWideContainer
public static @Nullable MetricsContainer getProcessWideContainer()
Return theMetricsContainer
for the current process.
-
-