[ 
https://issues.apache.org/jira/browse/BEAM-4374?focusedWorklogId=410561&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-410561
 ]

ASF GitHub Bot logged work on BEAM-4374:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 26/Mar/20 19:56
            Start Date: 26/Mar/20 19:56
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on 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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 410561)
    Time Spent: 30h 40m  (was: 30.5h)

> Update existing metrics in the FN API to use new Metric Schema
> --------------------------------------------------------------
>
>                 Key: BEAM-4374
>                 URL: https://issues.apache.org/jira/browse/BEAM-4374
>             Project: Beam
>          Issue Type: New Feature
>          Components: beam-model
>            Reporter: Alex Amato
>            Priority: Major
>          Time Spent: 30h 40m
>  Remaining Estimate: 0h
>
> Update existing metrics to use the new proto and cataloging schema defined in:
> [_https://s.apache.org/beam-fn-api-metrics_]
>  * Check in new protos
>  * Define catalog file for metrics
>  * Port existing metrics to use this new format, based on catalog 
> names+metadata



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to