Class DestinationMetrics
destination.NAME.recordsSend and
destination.NAME.sendErrors on the writer's metric group, where NAME is the destination
as the connector's docs page spells it.
Opt-in, and off by default, because Flink cannot unregister a metric. A sink writing to
per-record destinations has an unbounded destination set — a topic per tenant, a table per day —
so registering a subgroup per destination would grow the metric registry for the lifetime of the
task and undo the eviction hygiene the writers themselves practise. Each connector that registers
these counters exposes the switch as perDestinationMetrics on its own options object.
Entries are never removed, which is the deliberate consequence: a destination whose writer state was evicted and later rebuilt reuses the counters it had, so its totals stay continuous instead of restarting at zero. Nothing else could be true — an unregistered metric cannot be re-registered under the same name.
Call sites hold a DestinationMetrics.Counters handle rather than passing a destination name per record:
the name is then composed once per destination instead of once per record, and a disabled
instance costs the writer nothing beyond two null checks. DestinationMetrics.Counters is safe to cache
alongside the writer's own per-destination state.
The counter type is the caller's choice, for the reason ErrorClassCounters
records: of(MetricGroup, boolean) registers task-thread-only SimpleCounters, and
of(MetricGroup, boolean, Supplier) takes the counter a connector counting from SDK
callback threads needs. Registration itself is safe from any thread either way.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne destination's counters; a no-op instance when per-destination metrics are off. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringGroup name carrying the destination, so the destination is a metric variable, not a name.static final StringCounter name for records handed to the client for a destination.static final StringCounter name for records routed to the failure handler for a destination. -
Method Summary
Modifier and TypeMethodDescriptionforDestination(String destination) Returns the counters for a destination, registering them on first use.static DestinationMetricsof(org.apache.flink.metrics.MetricGroup metricGroup, boolean enabled) Creates the per-destination counters.static DestinationMetricsof(org.apache.flink.metrics.MetricGroup metricGroup, boolean enabled, Supplier<? extends org.apache.flink.metrics.Counter> counterSupplier) Creates the per-destination counters with the counter type the caller needs for the threads it counts from.
-
Field Details
-
DESTINATION_GROUP
Group name carrying the destination, so the destination is a metric variable, not a name.- See Also:
-
RECORDS_SEND
Counter name for records handed to the client for a destination.- See Also:
-
SEND_ERRORS
Counter name for records routed to the failure handler for a destination.- See Also:
-
-
Method Details
-
of
public static DestinationMetrics of(org.apache.flink.metrics.MetricGroup metricGroup, boolean enabled) Creates the per-destination counters.- Parameters:
metricGroup- the sink writer's metric groupenabled- whether the connector'sperDestinationMetricsoption is set; when false, nothing is ever registered andforDestination(java.lang.String)always returns a no-op- Returns:
- the counters
-
of
public static DestinationMetrics of(org.apache.flink.metrics.MetricGroup metricGroup, boolean enabled, Supplier<? extends org.apache.flink.metrics.Counter> counterSupplier) Creates the per-destination counters with the counter type the caller needs for the threads it counts from.- Parameters:
metricGroup- the metric group the per-destination subgroups register onenabled- whether the connector'sperDestinationMetricsoption is set; when false, nothing is ever registered andforDestination(java.lang.String)always returns a no-opcounterSupplier- creates each counter before it is registered under its name; pass a thread-safe counter when increments arrive from more than one thread- Returns:
- the counters
-
forDestination
Returns the counters for a destination, registering them on first use. The result is stable per destination name and is meant to be cached by the caller.- Parameters:
destination- the destination name, as the connector's docs page spells it- Returns:
- the destination's counters, or a no-op when the option is off
-