[BEAM-6138] Add User Counter Metric Support to Java SDK#6799
[BEAM-6138] Add User Counter Metric Support to Java SDK#6799swegner merged 4 commits intoapache:masterfrom
Conversation
b0b40eb to
3c7da5e
Compare
63e2de1 to
c9d1dec
Compare
50050a1 to
4806ac9
Compare
ee0eb8a to
de6304a
Compare
|
This is ready for review now. There are two commits because this depends on a separate PR to be submitted first (#6786). PTAL appreciate the review :). |
4f9fcde to
c5ef127
Compare
| } | ||
|
|
||
| // Extract user metrics and store as MonitoringInfos. | ||
| MetricUpdates mus = metricsContainer.getUpdates(); |
There was a problem hiding this comment.
extract response building to separate method.
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/control/ProcessBundleHandler.java
Show resolved
Hide resolved
|
|
||
| // Enum extension to store the MonitoringInfoSpecs. | ||
| extend google.protobuf.EnumValueOptions { | ||
| MonitoringInfoSpec monitoring_info_spec = 207174266; |
There was a problem hiding this comment.
Do we have any guidelines on how to generate this number to avoid collisions? I failed to find good docs on this.
There was a problem hiding this comment.
I believe that we should use the commit number, and converted it from hex to dec.
| * | ||
| * <p>Example Usage (ElementCount counter): | ||
| * | ||
| * <p>SimpleMonitoringInfoBuilder builder = new SimpleMonitoringInfoBuilder(); |
There was a problem hiding this comment.
If there is a way to preserve formatting on autoformat, it would be great to keep setters on new lines.
I didn't find a way to properly invoke relevant formatter, so can't suggest a solution here atm.
There was a problem hiding this comment.
I think that we would need to reconfigure spotless. @swegner any ideas here?
There was a problem hiding this comment.
Our spotless config is here, which currently just used googleJavaFormat(). My preference would be to generally limit our customization and deviate only where it's important. GitHub isn't showing me the original diff so I can't tell exactly what's going wrong here.
There was a problem hiding this comment.
There are also various javadoc constructs which could help; this article has some guidance: A Guide to Formatting Code Snippets in Javadoc
| } | ||
|
|
||
| /** | ||
| * Builds the provided MonitoringInfo, if validateAndDropInvalid is set then it drops any |
There was a problem hiding this comment.
Builds the provided MonitoringInfo.
Returns null if validateAndDropInvalid set and fields do not match respecting MonitoringInfoSpec based on urn.
| } | ||
|
|
||
| /** | ||
| * @param namespace The namespace of the metric. |
There was a problem hiding this comment.
[Ignore if adding @param tags is required by linter]
Remove these param specs, since you do not provide any extra information here.
You can rename name and namespace to metricName and metricNamespace respectively, if you think this clarification is required.
Same for other cases.
| public class SimpleMonitoringInfoBuilderTest { | ||
|
|
||
| @Test | ||
| public void testSpecNotFullyMet() { |
There was a problem hiding this comment.
Please rename to "testReturnsNullIfSpecRequirementsNotMet"
same for other test methods.
| } | ||
|
|
||
| SimpleMonitoringInfoBuilder builder = new SimpleMonitoringInfoBuilder(); | ||
| builder.setUrnForUserMetric(RemoteExecutionTest.class.getName(), "counterMetric"); |
There was a problem hiding this comment.
Extract counter name to constant.
| Iterables.getOnlyElement(startFunctions).run(); | ||
| mainOutputValues.clear(); | ||
|
|
||
| assertThat(consumers.keySet(), containsInAnyOrder(inputPCollectionId, outputPCollectionId)); |
There was a problem hiding this comment.
We are testing metrics here, so we can skip other check.
c5ef127 to
891a795
Compare
ajamato
left a comment
There was a problem hiding this comment.
Couldn't seem to comment inline about moving the declaration in ProcessBundleHandler
ProcessBundleResponse.Builder response = ProcessBundleResponse.newBuilder();
This can't be moved because it is used outside of the try block at the end, so this is the closest place it can be defined
| * | ||
| * <p>Example Usage (ElementCount counter): | ||
| * | ||
| * <p>SimpleMonitoringInfoBuilder builder = new SimpleMonitoringInfoBuilder(); |
There was a problem hiding this comment.
I think that we would need to reconfigure spotless. @swegner any ideas here?
| } | ||
|
|
||
| /** | ||
| * @param namespace The namespace of the metric. |
| } | ||
|
|
||
| /** | ||
| * Builds the provided MonitoringInfo, if validateAndDropInvalid is set then it drops any |
| public class SimpleMonitoringInfoBuilderTest { | ||
|
|
||
| @Test | ||
| public void testSpecNotFullyMet() { |
| } | ||
|
|
||
| SimpleMonitoringInfoBuilder builder = new SimpleMonitoringInfoBuilder(); | ||
| builder.setUrnForUserMetric(RemoteExecutionTest.class.getName(), "counterMetric"); |
| Iterables.getOnlyElement(startFunctions).run(); | ||
| mainOutputValues.clear(); | ||
|
|
||
| assertThat(consumers.keySet(), containsInAnyOrder(inputPCollectionId, outputPCollectionId)); |
1779944 to
bf60e00
Compare
|
@swegner Would you like to review as well? |
|
Retest this please |
|
|
||
| static { | ||
| for (MonitoringInfoSpecs.Enum val : MonitoringInfoSpecs.Enum.values()) { | ||
| // Ignore the UNRECOGNIZED = -1 value; |
There was a problem hiding this comment.
This comment is redundant. It is better to remove it, or replace with explanation why we ignore "UNRECOGNIZED" values.
| return false; | ||
| } | ||
|
|
||
| Set<String> requiredLabels = new HashSet<String>(spec.getRequiredLabelsList()); |
There was a problem hiding this comment.
We can also add validation of different labels values. Such as PTransform should be a valid pTransform name, etc.
There was a problem hiding this comment.
I'll put a TODO in that, to enhance it. Let's consider that out of scope for now.
| * | ||
| * @param pTransform | ||
| */ | ||
| public void setPTransformLabel(String pTransform) { |
There was a problem hiding this comment.
It is better to define generalized method setLabel(String labelName, String labelValue) and provide a list of standard label names.
This is one of examples that might work
https://stackoverflow.com/questions/3978654/best-way-to-create-enum-of-strings
There was a problem hiding this comment.
Done, I think this is more or less what you mean
| assertNull(builder.build()); | ||
|
|
||
| builder.setPCollectionLabel("myPcollection"); | ||
| assertTrue(builder.build() != null); |
There was a problem hiding this comment.
Would be good idea to validate result values here as well.
| new UnknownPTransformRunnerFactory(urnToPTransformRunnerFactoryMap.keySet()); | ||
| } | ||
|
|
||
| private void extractMonitoringInfosToResponse( |
There was a problem hiding this comment.
This method should build a list of MonitoringInfos and caller should set MonitoringInfos to response.
Doing this will simplify reading code greatly and prevent further complexity growth.
There was a problem hiding this comment.
I'm using this style to prevent putting it on a temp list. We could return an iterator object instead?
There was a problem hiding this comment.
Returning an iterable now, moved it to MetricContainerImpl
This is subset of code from apache#6799 Extracting it for unblocking counter validation changes in Dataflow Java Runner.
bf60e00 to
c314dfe
Compare
|
Retest this please |
a0cf246 to
50dbf6d
Compare
| new UnknownPTransformRunnerFactory(urnToPTransformRunnerFactoryMap.keySet()); | ||
| } | ||
|
|
||
| private void extractMonitoringInfosToResponse( |
echauchot
left a comment
There was a problem hiding this comment.
Nice to see that there is portable user metrics now (at least counter) !
I only took a quick overlook. The only question I have is: If I understand correctly metrics updates are only sent at the end of the bundle processing. Is it planed to add metrics updates as part of the status updates during the bundle processing?
4fc030c to
f7ab80a
Compare
|
Yes @echauchot later on we will enhance this to also send metrics on the ProcessBundleProgressResponse, instead of just the ProcessBundleResponse. |
|
LGTM. I am going to merge this. but @echauchot if you have additional questions feel free to keep the conversation going. |
Please add a meaningful description for your change here
Adds Java User Metrics to the Java SDK.
Metrics set using Metrics.counter, inside the bundle processing thread (start, finish, process) will be collected and reported in the ProcesBundleResponse.
Follow this checklist to help us incorporate your contribution quickly and easily:
[BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replaceBEAM-XXXwith the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.It will help us expedite review of your Pull Request if you tag someone (e.g.
@username) to look at it.Post-Commit Tests Status (on master branch)