Class TestSinkWriterMetricGroup
- All Implemented Interfaces:
org.apache.flink.metrics.groups.OperatorMetricGroup,org.apache.flink.metrics.groups.SinkWriterMetricGroup,org.apache.flink.metrics.MetricGroup
SinkWriterMetricGroup whose metrics can be read back by the names they registered
under, so a sink writer's metrics are asserted the way a reporter would see them.
Everything a writer registers — including the FLIP-33 standard counters, which are registered
here under their documented names rather than merely held — goes through one MetricListener, so counterValue(String...) and gaugeValue(String...) reach all
of them and a renamed or unregistered metric fails its test. That is what the alternatives cannot
do: UnregisteredMetricsGroup.createSinkWriterMetricGroup() hands out a fresh
SimpleCounter on every call, so the counter the writer captured is unreachable afterwards, and
InternalSinkWriterMetricGroup has no mock(...) factory in either supported Flink
line (1.20 and 2.x offer a package-private constructor and wrap(OperatorMetricGroup),
which a listener group cannot satisfy).
ProxyMetricGroup, through the package-private ListenerReadableMetricGroup base
holding the listener and the inherited counterValue(String...), gaugeValue(String...) and hasMetric(String...) accessors, supplies the delegation to
the listener's group, which is why the registration methods are not overridden here.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringFLIP-33 name of the bytes counter.static final StringFLIP-33 name of the records counter, as a reporter sees it.static final StringFLIP-33 name of the send-error counter.Fields inherited from class org.apache.flink.runtime.metrics.groups.ProxyMetricGroup
parentMetricGroup -
Method Summary
Modifier and TypeMethodDescriptionfinal longcounterValue(String... identifier) Returns the counter registered underidentifier, relative to the group.static TestSinkWriterMetricGroupcreate()Creates a group over a fresh listener.final <T> TgaugeValue(String... identifier) Returns the value of the gauge registered underidentifier.org.apache.flink.metrics.Gauge<Long>The gauge a writer passed tosetCurrentSendTimeGauge(org.apache.flink.metrics.Gauge<java.lang.Long>), ornull.org.apache.flink.metrics.groups.OperatorIOMetricGrouporg.apache.flink.metrics.Counterorg.apache.flink.metrics.Counterorg.apache.flink.metrics.Counterorg.apache.flink.metrics.Counterfinal booleanWhether any metric is registered underidentifier— the assertion a metric that may legitimately be absent needs, since "not registered" is not "registered at zero".final org.apache.flink.metrics.CounterregisteredCounter(String... identifier) Returns the counter registered underidentifieritself — for the assertion that cares which implementation a runtime registered, such as a thread-safe one on a surface whose counts arrive from client threads.voidsetCurrentSendTimeGauge(org.apache.flink.metrics.Gauge<Long> currentSendTimeGauge) Methods inherited from class org.apache.flink.runtime.metrics.groups.ProxyMetricGroup
addEvent, addGroup, addGroup, addSpan, counter, counter, gauge, getAllVariables, getMetricIdentifier, getMetricIdentifier, getScopeComponents, histogram, meterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.metrics.MetricGroup
addEvent, addGroup, addGroup, addGroup, addSpan, counter, counter, counter, counter, gauge, gauge, getAllVariables, getMetricIdentifier, getMetricIdentifier, getScopeComponents, histogram, histogram, meter, meter
-
Field Details
-
NUM_RECORDS_SEND
FLIP-33 name of the records counter, as a reporter sees it.- See Also:
-
NUM_BYTES_SEND
FLIP-33 name of the bytes counter.- See Also:
-
NUM_RECORDS_SEND_ERRORS
FLIP-33 name of the send-error counter.- See Also:
-
-
Method Details
-
create
Creates a group over a fresh listener. -
getCurrentSendTimeGauge
The gauge a writer passed tosetCurrentSendTimeGauge(org.apache.flink.metrics.Gauge<java.lang.Long>), ornull. -
getNumRecordsSendCounter
public org.apache.flink.metrics.Counter getNumRecordsSendCounter()- Specified by:
getNumRecordsSendCounterin interfaceorg.apache.flink.metrics.groups.SinkWriterMetricGroup
-
getNumBytesSendCounter
public org.apache.flink.metrics.Counter getNumBytesSendCounter()- Specified by:
getNumBytesSendCounterin interfaceorg.apache.flink.metrics.groups.SinkWriterMetricGroup
-
getNumRecordsSendErrorsCounter
public org.apache.flink.metrics.Counter getNumRecordsSendErrorsCounter()- Specified by:
getNumRecordsSendErrorsCounterin interfaceorg.apache.flink.metrics.groups.SinkWriterMetricGroup
-
getNumRecordsOutErrorsCounter
public org.apache.flink.metrics.Counter getNumRecordsOutErrorsCounter()- Specified by:
getNumRecordsOutErrorsCounterin interfaceorg.apache.flink.metrics.groups.SinkWriterMetricGroup
-
setCurrentSendTimeGauge
- Specified by:
setCurrentSendTimeGaugein interfaceorg.apache.flink.metrics.groups.SinkWriterMetricGroup
-
getIOMetricGroup
public org.apache.flink.metrics.groups.OperatorIOMetricGroup getIOMetricGroup()- Specified by:
getIOMetricGroupin interfaceorg.apache.flink.metrics.groups.OperatorMetricGroup
-
counterValue
Returns the counter registered underidentifier, relative to the group.- Parameters:
identifier- the name path, one element per group level (for example"errorClass", "UNAVAILABLE", "errors")- Returns:
- the counter's value
- Throws:
AssertionError- if nothing was registered under that name
-
registeredCounter
Returns the counter registered underidentifieritself — for the assertion that cares which implementation a runtime registered, such as a thread-safe one on a surface whose counts arrive from client threads.- Parameters:
identifier- the name path, one element per group level- Returns:
- the registered counter
- Throws:
AssertionError- if nothing was registered under that name
-
hasMetric
Whether any metric is registered underidentifier— the assertion a metric that may legitimately be absent needs, since "not registered" is not "registered at zero". -
gaugeValue
Returns the value of the gauge registered underidentifier.- Type Parameters:
T- the gauge's value type- Parameters:
identifier- the name path, one element per group level- Returns:
- the gauge's current value
- Throws:
AssertionError- if nothing was registered under that name
-