Abacn commented on code in PR #31253:
URL: https://github.com/apache/beam/pull/31253#discussion_r1605656952
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java:
##########
@@ -1081,4 +1084,52 @@ private static Object convertAvroNumeric(Object value) {
public static ServiceCallMetric writeCallMetric(TableReference
tableReference) {
return callMetricForMethod(tableReference, "BigQueryBatchWrite");
}
+
+ /**
+ * A counter holding a list of counters. Increment the counter will
increment every sub-counter it
+ * holds.
+ */
+ static class NestedCounter implements Counter, Serializable {
+
+ private final MetricName name;
+ private final ImmutableList<Counter> counters;
+
+ public NestedCounter(MetricName name, Counter... counters) {
+ this.name = name;
+ this.counters = ImmutableList.copyOf(counters);
+ }
+
+ @Override
+ public void inc() {
+ for (Counter counter : counters) {
+ counter.inc();
+ }
+ }
+
+ @Override
+ public void inc(long n) {
+ for (Counter counter : counters) {
+ counter.inc(n);
+ }
+ }
+
+ @Override
+ public void dec() {
+ for (Counter counter : counters) {
+ counter.dec();
+ }
+ }
+
+ @Override
+ public void dec(long n) {
+ for (Counter counter : counters) {
+ counter.dec(n);
+ }
+ }
+
+ @Override
+ public MetricName getName() {
+ return name;
+ }
Review Comment:
it makes sense. name is a MetricsName object contains a namespace + name. It
is not obvious how to concatenate sub-counter names into here so I left it as is
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java:
##########
@@ -1081,4 +1084,52 @@ private static Object convertAvroNumeric(Object value) {
public static ServiceCallMetric writeCallMetric(TableReference
tableReference) {
return callMetricForMethod(tableReference, "BigQueryBatchWrite");
}
+
+ /**
+ * A counter holding a list of counters. Increment the counter will
increment every sub-counter it
+ * holds.
+ */
+ static class NestedCounter implements Counter, Serializable {
+
+ private final MetricName name;
+ private final ImmutableList<Counter> counters;
+
+ public NestedCounter(MetricName name, Counter... counters) {
+ this.name = name;
+ this.counters = ImmutableList.copyOf(counters);
+ }
+
+ @Override
+ public void inc() {
+ for (Counter counter : counters) {
+ counter.inc();
+ }
+ }
+
+ @Override
+ public void inc(long n) {
+ for (Counter counter : counters) {
+ counter.inc(n);
+ }
+ }
+
+ @Override
+ public void dec() {
+ for (Counter counter : counters) {
+ counter.dec();
+ }
+ }
+
+ @Override
+ public void dec(long n) {
+ for (Counter counter : counters) {
+ counter.dec(n);
+ }
+ }
+
+ @Override
+ public MetricName getName() {
+ return name;
+ }
Review Comment:
it makes sense. However name is a MetricsName object contains a namespace +
name. It is not obvious how to concatenate sub-counter names into here so I
left it as is
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]