lukecwik commented on a change in pull request #11184: [BEAM-4374] Update 
protos related to MonitoringInfo.
URL: https://github.com/apache/beam/pull/11184#discussion_r398852450
 
 

 ##########
 File path: 
runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/SimpleMonitoringInfoBuilder.java
 ##########
 @@ -86,46 +89,97 @@ public SimpleMonitoringInfoBuilder setUrn(String urn) {
     return this;
   }
 
-  /** Sets the timestamp of the MonitoringInfo to the current time. */
-  public SimpleMonitoringInfoBuilder setTimestampToNow() {
-    Instant time = Instant.now();
-    
this.builder.getTimestampBuilder().setSeconds(time.getEpochSecond()).setNanos(time.getNano());
+  /**
+   * Sets the type of the MonitoringInfo.
+   *
+   * @param type The type of the MonitoringInfo
+   */
+  public SimpleMonitoringInfoBuilder setType(String type) {
+    this.builder.setType(type);
+    return this;
+  }
+
+  /**
+   * Encodes the value and sets the type to {@link 
MonitoringInfoConstants.TypeUrns#SUM_INT64_TYPE}.
+   */
+  public SimpleMonitoringInfoBuilder setInt64SumValue(long value) {
+    ByteString.Output output = ByteString.newOutput();
+    try {
+      VARINT_CODER.encode(value, output);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    this.builder.setPayload(output.toByteString());
+    this.builder.setType(MonitoringInfoConstants.TypeUrns.SUM_INT64_TYPE);
     return this;
   }
 
-  /** Sets the int64Value of the CounterData in the MonitoringInfo, and the 
appropriate type URN. */
-  public SimpleMonitoringInfoBuilder setInt64Value(long value) {
-    
this.builder.getMetricBuilder().getCounterDataBuilder().setInt64Value(value);
-    this.setInt64TypeUrn();
+  public SimpleMonitoringInfoBuilder setDoubleSumValue(double value) {
+    ByteString.Output output = ByteString.newOutput();
+    try {
+      DOUBLE_CODER.encode(value, output);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    this.builder.setPayload(output.toByteString());
+    this.builder.setType(MonitoringInfoConstants.TypeUrns.SUM_DOUBLE_TYPE);
     return this;
   }
 
   /**
-   * Sets the IntDistributionData of the DistributionData in the 
MonitoringInfo, and the appropriate
-   * type URN.
+   * Encodes the value and sets the type to {@link
+   * MonitoringInfoConstants.TypeUrns#LATEST_INT64_TYPE}.
    */
-  public SimpleMonitoringInfoBuilder 
setInt64DistributionValue(DistributionData data) {
-    this.builder
-        .getMetricBuilder()
-        .getDistributionDataBuilder()
-        .getIntDistributionDataBuilder()
-        .setCount(data.count())
-        .setSum(data.sum())
-        .setMin(data.min())
-        .setMax(data.max());
-    this.setInt64DistributionTypeUrn();
+  public SimpleMonitoringInfoBuilder setInt64LatestValue(GaugeData data) {
+    checkArgument(GaugeData.empty() != data, "Cannot encode empty gauge data");
+    ByteString.Output output = ByteString.newOutput();
+    try {
+      VARINT_CODER.encode(data.timestamp().getMillis(), output);
+      VARINT_CODER.encode(data.value(), output);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    this.builder.setPayload(output.toByteString());
+    this.builder.setType(MonitoringInfoConstants.TypeUrns.LATEST_INT64_TYPE);
     return this;
   }
 
-  /** Sets the the appropriate type URN for int64 distribution tuples. */
-  public SimpleMonitoringInfoBuilder setInt64DistributionTypeUrn() {
-    this.builder.setType(MonitoringInfoConstants.TypeUrns.DISTRIBUTION_INT64);
+  /**
+   * Encodes the value and sets the type to {@link
+   * MonitoringInfoConstants.TypeUrns#DISTRIBUTION_INT64_TYPE}.
+   */
+  public SimpleMonitoringInfoBuilder 
setInt64DistributionValue(DistributionData data) {
+    ByteString.Output output = ByteString.newOutput();
+    try {
+      VARINT_CODER.encode(data.count(), output);
+      VARINT_CODER.encode(data.sum(), output);
+      VARINT_CODER.encode(data.min(), output);
+      VARINT_CODER.encode(data.max(), output);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    this.builder.setPayload(output.toByteString());
+    
this.builder.setType(MonitoringInfoConstants.TypeUrns.DISTRIBUTION_INT64_TYPE);
     return this;
   }
 
-  /** Sets the the appropriate type URN for sum int64 counters. */
-  public SimpleMonitoringInfoBuilder setInt64TypeUrn() {
-    this.builder.setType(MonitoringInfoConstants.TypeUrns.SUM_INT64);
+  /**
+   * Encodes the value and sets the type to {@link
+   * MonitoringInfoConstants.TypeUrns#DISTRIBUTION_INT64_TYPE}.
+   */
+  public SimpleMonitoringInfoBuilder setDoubleDistributionValue(
 
 Review comment:
   Yup

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to