Class AbstractMetricGroup<A extends AbstractMetricGroup<?>>
- java.lang.Object
-
- org.apache.flink.runtime.metrics.groups.AbstractMetricGroup<A>
-
- Type Parameters:
A
- The type of the parent MetricGroup
- All Implemented Interfaces:
MetricGroup
- Direct Known Subclasses:
ComponentMetricGroup
,GenericMetricGroup
,ProcessMetricGroup
,ResourceManagerMetricGroup
,SlotManagerMetricGroup
@Internal public abstract class AbstractMetricGroup<A extends AbstractMetricGroup<?>> extends Object implements MetricGroup
AbstractMetricGroup
that contains key functionality for adding metrics and groups.IMPORTANT IMPLEMENTATION NOTE
This class uses locks for adding and removing metrics objects. This is done to prevent resource leaks in the presence of concurrently closing a group and adding metrics and subgroups. Since closing groups recursively closes the subgroups, the lock acquisition order must be strictly from parent group to subgroup. If at any point, a subgroup holds its group lock and calls a parent method that also acquires the lock, it will create a deadlock condition.
An AbstractMetricGroup can be
closed
. Upon closing, the group de-register all metrics from any metrics reporter and any internal maps. Note that even closed metrics groups return Counters, Gauges, etc to the code, to prevent exceptions in the monitored code. These metrics simply do not get reported any more, when created on a closed group.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractMetricGroup.ChildType
Enum for indicating which child group should be created.
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
LOG
protected A
parent
The parent group containing this group.protected QueryScopeInfo
queryServiceScopeInfo
The metrics query service scope represented by this group, lazily computed.protected MetricRegistry
registry
The registry that this metrics group belongs to.protected Map<String,String>[]
variables
The map containing all variables and their associated values, lazily computed.
-
Constructor Summary
Constructors Constructor Description AbstractMetricGroup(MetricRegistry registry, String[] scope, A parent)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description MetricGroup
addGroup(String name)
Creates a new MetricGroup and adds it to this groups sub-groups.MetricGroup
addGroup(String key, String value)
Creates a new key-value MetricGroup pair.protected void
addMetric(String name, Metric metric)
Adds the given metric to the group and registers it at the registry, if the group is not yet closed, and if no metric with the same name has been registered before.void
addSpan(SpanBuilder spanBuilder)
void
close()
Counter
counter(String name)
Creates and registers a newCounter
with Flink.<C extends Counter>
Ccounter(String name, C counter)
Registers aCounter
with Flink.protected GenericMetricGroup
createChildGroup(String name, AbstractMetricGroup.ChildType childType)
protected String
createLogicalScope(CharacterFilter filter, char delimiter)
protected abstract QueryScopeInfo
createQueryServiceMetricInfo(CharacterFilter filter)
Creates the metric query service scope for this group.<T,G extends Gauge<T>>
Ggauge(String name, G gauge)
Registers a newGauge
with Flink.Map<String,String>
getAllVariables()
Returns a map of all variables and their associated value, for example{"<host>"="host-7", "<tm_id>"="taskmanager-2"}
.Map<String,String>
getAllVariables(int reporterIndex, Set<String> excludedVariables)
protected abstract String
getGroupName(CharacterFilter filter)
Returns the name for this group, meaning what kind of entity it represents, for example "taskmanager".String
getLogicalScope(CharacterFilter filter)
Returns the logical scope of this group, for example"taskmanager.job.task"
.String
getLogicalScope(CharacterFilter filter, char delimiter)
Returns the logical scope of this group, for example"taskmanager.job.task"
.String
getMetricIdentifier(String metricName)
Returns the fully qualified metric name, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName"
.String
getMetricIdentifier(String metricName, CharacterFilter filter)
Returns the fully qualified metric name, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName"
.String
getMetricIdentifier(String metricName, CharacterFilter filter, int reporterIndex, char delimiter)
Returns the fully qualified metric name using the configured delimiter for the reporter with the given index, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName"
.QueryScopeInfo
getQueryServiceMetricInfo(CharacterFilter filter)
Returns the metric query service scope for this group.String[]
getScopeComponents()
Gets the scope as an array of the scope components, for example["host-7", "taskmanager-2", "window_word_count", "my-mapper"]
.<H extends Histogram>
Hhistogram(String name, H histogram)
Registers a newHistogram
with Flink.boolean
isClosed()
<M extends Meter>
Mmeter(String name, M meter)
Registers a newMeter
with Flink.protected void
putVariables(Map<String,String> variables)
Enters all variables specific to thisAbstractMetricGroup
and their associated values into the map.
-
-
-
Field Detail
-
LOG
protected static final org.slf4j.Logger LOG
-
parent
protected final A extends AbstractMetricGroup<?> parent
The parent group containing this group.
-
variables
protected volatile Map<String,String>[] variables
The map containing all variables and their associated values, lazily computed.
-
registry
protected final MetricRegistry registry
The registry that this metrics group belongs to.
-
queryServiceScopeInfo
protected QueryScopeInfo queryServiceScopeInfo
The metrics query service scope represented by this group, lazily computed.
-
-
Constructor Detail
-
AbstractMetricGroup
public AbstractMetricGroup(MetricRegistry registry, String[] scope, A parent)
-
-
Method Detail
-
getAllVariables
public Map<String,String> getAllVariables()
Description copied from interface:MetricGroup
Returns a map of all variables and their associated value, for example{"<host>"="host-7", "<tm_id>"="taskmanager-2"}
.- Specified by:
getAllVariables
in interfaceMetricGroup
- Returns:
- map of all variables and their associated value
-
getAllVariables
public Map<String,String> getAllVariables(int reporterIndex, Set<String> excludedVariables)
-
putVariables
protected void putVariables(Map<String,String> variables)
Enters all variables specific to thisAbstractMetricGroup
and their associated values into the map.- Parameters:
variables
- map to enter variables and their values into
-
getLogicalScope
public String getLogicalScope(CharacterFilter filter)
Returns the logical scope of this group, for example"taskmanager.job.task"
.- Parameters:
filter
- character filter which is applied to the scope components- Returns:
- logical scope
-
getLogicalScope
public String getLogicalScope(CharacterFilter filter, char delimiter)
Returns the logical scope of this group, for example"taskmanager.job.task"
.- Parameters:
filter
- character filter which is applied to the scope components- Returns:
- logical scope
-
createLogicalScope
protected String createLogicalScope(CharacterFilter filter, char delimiter)
-
getGroupName
protected abstract String getGroupName(CharacterFilter filter)
Returns the name for this group, meaning what kind of entity it represents, for example "taskmanager".- Parameters:
filter
- character filter which is applied to the name- Returns:
- logical name for this group
-
getScopeComponents
public String[] getScopeComponents()
Gets the scope as an array of the scope components, for example["host-7", "taskmanager-2", "window_word_count", "my-mapper"]
.- Specified by:
getScopeComponents
in interfaceMetricGroup
- See Also:
getMetricIdentifier(String)
-
getQueryServiceMetricInfo
public QueryScopeInfo getQueryServiceMetricInfo(CharacterFilter filter)
Returns the metric query service scope for this group.- Parameters:
filter
- character filter- Returns:
- query service scope
-
createQueryServiceMetricInfo
protected abstract QueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter)
Creates the metric query service scope for this group.- Parameters:
filter
- character filter- Returns:
- query service scope
-
getMetricIdentifier
public String getMetricIdentifier(String metricName)
Returns the fully qualified metric name, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName"
.- Specified by:
getMetricIdentifier
in interfaceMetricGroup
- Parameters:
metricName
- metric name- Returns:
- fully qualified metric name
-
getMetricIdentifier
public String getMetricIdentifier(String metricName, CharacterFilter filter)
Returns the fully qualified metric name, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName"
.- Specified by:
getMetricIdentifier
in interfaceMetricGroup
- Parameters:
metricName
- metric namefilter
- character filter which is applied to the scope components if not null.- Returns:
- fully qualified metric name
-
getMetricIdentifier
public String getMetricIdentifier(String metricName, CharacterFilter filter, int reporterIndex, char delimiter)
Returns the fully qualified metric name using the configured delimiter for the reporter with the given index, for example"host-7.taskmanager-2.window_word_count.my-mapper.metricName"
.- Parameters:
metricName
- metric namefilter
- character filter which is applied to the scope components if not null.reporterIndex
- index of the reporter whose delimiter should be useddelimiter
- delimiter to use- Returns:
- fully qualified metric name
-
close
public void close()
-
isClosed
public final boolean isClosed()
-
addSpan
public void addSpan(SpanBuilder spanBuilder)
- Specified by:
addSpan
in interfaceMetricGroup
-
counter
public Counter counter(String name)
Description copied from interface:MetricGroup
Creates and registers a newCounter
with Flink.- Specified by:
counter
in interfaceMetricGroup
- Parameters:
name
- name of the counter- Returns:
- the created counter
-
counter
public <C extends Counter> C counter(String name, C counter)
Description copied from interface:MetricGroup
Registers aCounter
with Flink.- Specified by:
counter
in interfaceMetricGroup
- Type Parameters:
C
- counter type- Parameters:
name
- name of the countercounter
- counter to register- Returns:
- the given counter
-
gauge
public <T,G extends Gauge<T>> G gauge(String name, G gauge)
Description copied from interface:MetricGroup
Registers a newGauge
with Flink.- Specified by:
gauge
in interfaceMetricGroup
- Type Parameters:
T
- return type of the gauge- Parameters:
name
- name of the gaugegauge
- gauge to register- Returns:
- the given gauge
-
histogram
public <H extends Histogram> H histogram(String name, H histogram)
Description copied from interface:MetricGroup
Registers a newHistogram
with Flink.- Specified by:
histogram
in interfaceMetricGroup
- Type Parameters:
H
- histogram type- Parameters:
name
- name of the histogramhistogram
- histogram to register- Returns:
- the registered histogram
-
meter
public <M extends Meter> M meter(String name, M meter)
Description copied from interface:MetricGroup
Registers a newMeter
with Flink.- Specified by:
meter
in interfaceMetricGroup
- Type Parameters:
M
- meter type- Parameters:
name
- name of the metermeter
- meter to register- Returns:
- the registered meter
-
addMetric
protected void addMetric(String name, Metric metric)
Adds the given metric to the group and registers it at the registry, if the group is not yet closed, and if no metric with the same name has been registered before.- Parameters:
name
- the name to register the metric undermetric
- the metric to register
-
addGroup
public MetricGroup addGroup(String name)
Description copied from interface:MetricGroup
Creates a new MetricGroup and adds it to this groups sub-groups.- Specified by:
addGroup
in interfaceMetricGroup
- Parameters:
name
- name of the group- Returns:
- the created group
-
addGroup
public MetricGroup addGroup(String key, String value)
Description copied from interface:MetricGroup
Creates a new key-value MetricGroup pair. The key group is added to this groups sub-groups, while the value group is added to the key group's sub-groups. This method returns the value group.The only difference between calling this method and
group.addGroup(key).addGroup(value)
is thatMetricGroup.getAllVariables()
of the value group return an additional"<key>"="value"
pair.- Specified by:
addGroup
in interfaceMetricGroup
- Parameters:
key
- name of the first groupvalue
- name of the second group- Returns:
- the second created group
-
createChildGroup
protected GenericMetricGroup createChildGroup(String name, AbstractMetricGroup.ChildType childType)
-
-