apache_beam.metrics.metric module¶
User-facing classes for Metrics API.
The classes in this file allow users to define and use metrics to be collected and displayed as part of their pipeline execution.
- Metrics - This class lets pipeline and transform writers create and access
metric objects such as counters, distributions, etc.
- class apache_beam.metrics.metric.Metrics[source]¶
Bases:
object
Lets users create/access metric objects during pipeline execution.
- static counter(namespace: Type | str, name: str) DelegatingCounter [source]¶
Obtains or creates a Counter metric.
- Parameters:
namespace – A class or string that gives the namespace to a metric
name – A string that gives a unique name to a metric
- Returns:
A Counter object.
- static distribution(namespace: Type | str, name: str) DelegatingDistribution [source]¶
Obtains or creates a Distribution metric.
Distribution metrics are restricted to integer-only distributions.
- Parameters:
namespace – A class or string that gives the namespace to a metric
name – A string that gives a unique name to a metric
- Returns:
A Distribution object.
- static gauge(namespace: Type | str, name: str) DelegatingGauge [source]¶
Obtains or creates a Gauge metric.
Gauge metrics are restricted to integer-only values.
- Parameters:
namespace – A class or string that gives the namespace to a metric
name – A string that gives a unique name to a metric
- Returns:
A Distribution object.
- static string_set(namespace: Type | str, name: str) DelegatingStringSet [source]¶
Obtains or creates a String set metric.
String set metrics are restricted to string values.
- Parameters:
namespace – A class or string that gives the namespace to a metric
name – A string that gives a unique name to a metric
- Returns:
A StringSet object.
- class DelegatingCounter(metric_name: MetricName, process_wide: bool = False)[source]¶
Bases:
Counter
Metrics Counter that Delegates functionality to MetricsEnvironment.
- class DelegatingDistribution(metric_name: MetricName)[source]¶
Bases:
Distribution
Metrics Distribution Delegates functionality to MetricsEnvironment.
- class DelegatingGauge(metric_name: MetricName)[source]¶
Bases:
Gauge
Metrics Gauge that Delegates functionality to MetricsEnvironment.
- class DelegatingStringSet(metric_name: MetricName)[source]¶
Bases:
StringSet
Metrics StringSet that Delegates functionality to MetricsEnvironment.
- class apache_beam.metrics.metric.MetricsFilter[source]¶
Bases:
object
Simple object to filter metrics results.
If filters by matching a result’s step-namespace-name with three internal sets. No execution/matching logic is added to this object, so that it may be used to construct arguments as an RPC request. It is left for runners to implement matching logic by themselves.
Note: This class only supports user defined metrics.
- with_metric(metric: Metric) MetricsFilter [source]¶
- with_name(name: str) MetricsFilter [source]¶
- with_names(names: Iterable[str]) MetricsFilter [source]¶
- with_namespace(namespace: Type | str) MetricsFilter [source]¶
- with_step(step: str) MetricsFilter [source]¶
- with_steps(steps: Iterable[str]) MetricsFilter [source]¶
- class apache_beam.metrics.metric.Lineage(label: str)[source]¶
Bases:
object
Standard collection of metrics used to record source and sinks information for lineage tracking.
Create a Lineage with valid label (
SOURCE
orSINK
)- LINEAGE_NAMESPACE = 'lineage'¶
- SOURCE = 'sources'¶
- SINK = 'sinks'¶
- static wrap_segment(segment: str) str [source]¶
Wrap segment to valid segment name.
Specifically, If there are reserved chars (colon, whitespace, dot), escape with backtick. If the segment is already wrapped, return the original.
- static get_fq_name(system: str, *segments: str, subtype: str | None = None) str [source]¶
Assemble fully qualified name (FQN). Format:
system:segment1.segment2
system:subtype:segment1.segment2
system:`segment1.with.dots:colons.segment2`
This helper method is for internal and testing usage only.
- add(system: str, *segments: str, subtype: str | None = None) None [source]¶
Adds the given details as Lineage.
For asset level lineage the resource location should be specified as Dataplex FQN, see https://cloud.google.com/data-catalog/docs/fully-qualified-names
Example of adding FQN components:
add(“system”, “segment1”, “segment2”)
add(“system”, “segment1”, “segment2”, subtype=”subtype”)
Example of adding a FQN:
add(“system:segment1.segment2”)
add(“system:subtype:segment1.segment2”)
The first positional argument serves as system, if full segments are provided, or the full FQN if it is provided as a single argument.