Skip to content

[BEAM-6138] Set the PTransform name on Java SDK User counters - #7624

Merged
swegner merged 7 commits into
apache:masterfrom
ajamato:user_counter_ptransform_name
Feb 4, 2019
Merged

swegner merged 7 commits into
apache:masterfrom
ajamato:user_counter_ptransform_name

Conversation

@ajamato

@ajamato ajamato commented Jan 25, 2019

Copy link
Copy Markdown

Please add a meaningful description for your change here

Set the PTransform name on Java SDK User counters


Follow this checklist to help us incorporate your contribution quickly and easily:

  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)

Lang SDK Apex Dataflow Flink Gearpump Samza Spark
Go Build Status --- --- --- --- --- ---
Java Build Status Build Status Build Status Build Status
Build Status
Build Status
Build Status Build Status Build Status
Python Build Status --- Build Status
Build Status
--- --- --- ---

@ajamato

ajamato commented Jan 26, 2019

Copy link
Copy Markdown
Author

@ryan-williams @Ardagan
Please take a look at this PR. I think there might be a few extra unit tests worth adding to PCollectionConsumerRegistry and PTransformFunctionRegistry

I'll add those soon, but wanted to share it in advance. PTAL and let me know if there are specific unit tests you think that I should try to add as well.

@ryan-williams ryan-williams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one quick nit from rebasing my work onto this branch


/**
* Key class to lookup the metric container for a step or unbound to any step. This is preferable
* to using null(which can't be used as a key). Additonally, this class could be extended to allow

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github doesn't seem to support a single "suggestion" block spanning multiple lines, but this causes a line-wrap so it's two "suggestion"s:

Suggested change
* to using null(which can't be used as a key). Additonally, this class could be extended to allow
* to using null (which can't be used as a key). Additionally, this class could be extended to

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/**
* Key class to lookup the metric container for a step or unbound to any step. This is preferable
* to using null(which can't be used as a key). Additonally, this class could be extended to allow
* containers for other non pTransform contexts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* containers for other non pTransform contexts.
* allow containers for other non pTransform contexts.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ryan-williams

Copy link
Copy Markdown
Contributor

I think ajamato#1 fixes the Java PreCommit failures, fwiw

@ajamato
ajamato force-pushed the user_counter_ptransform_name branch from 1caad4b to f5bc350 Compare January 30, 2019 00:37
@ajamato ajamato changed the title [Do not Submit yet] Set the PTransform name on Java SDK User counters Set the PTransform name on Java SDK User counters Jan 30, 2019
@ajamato

ajamato commented Jan 30, 2019

Copy link
Copy Markdown
Author

Applied the suggestions here, added some unit tests. Please see the style of ElementCountFnDataReceiverTest, PTransformFunctionRegistryTest, PCollectionConsumerRegistry test

Basically there are two ways to test the side effects in these tests:
(1) Mock the static to make sure that the metrics environment sets the correct metric container.
(2) Pull out the MonitoringInfos the counters create

I went with #1 which, though #2 might be more resistant to implemetnation internal changes. I was curious what others thoughts were on this.

@ajamato

ajamato commented Jan 30, 2019

Copy link
Copy Markdown
Author

I also removed the MetricContainerKey because I realized that for every element we were allocating the key, which I think would be problematic for performance and wanted to avoid

@ajamato

ajamato commented Jan 30, 2019

Copy link
Copy Markdown
Author

Run Python PreCommit

@Ardagan

Ardagan commented Jan 30, 2019

Copy link
Copy Markdown
Contributor

I also removed the MetricContainerKey because I realized that for every element we were allocating the key, which I think would be problematic for performance and wanted to avoid

Do we have a standard way to test this kind of performance regression?

@ajamato

ajamato commented Jan 30, 2019

Copy link
Copy Markdown
Author

I also removed the MetricContainerKey because I realized that for every element we were allocating the key, which I think would be problematic for performance and wanted to avoid

Do we have a standard way to test this kind of performance regression?

Not yet, Beam needs more microbenchmark tests, java too. We should probably start writing some in Q2.

@ajamato ajamato changed the title Set the PTransform name on Java SDK User counters [BEAM-6138] Set the PTransform name on Java SDK User counters Jan 31, 2019
@ajamato
ajamato force-pushed the user_counter_ptransform_name branch from 8d37535 to 73f6cb1 Compare January 31, 2019 22:15
@ajamato

ajamato commented Jan 31, 2019

Copy link
Copy Markdown
Author

Success, precommit is passing now. Let's finish up this review

@ryan-williams ryan-williams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm modulo a couple questions

if (metricUpdate.getKey().stepName() != null) {
stepName = metricUpdate.getKey().stepName();
}
builder.setPTransformLabel(stepName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't a step-name of null a sentinel that indicates omitting the PTransformLabel altogether?

Seems like you are going out of your way to set it to "" here, but I was thinking the contract was null ⟺ [PCollection-scoped metric]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't actually set the proto value to null, it will crash the program. This is an invalid input case though, since all user counters must be scoped to their step. I removed the test case which caused me to add this in the first place. If this occurs, we should drop the metric. I'll add a test for that too


builder = new SimpleMonitoringInfoBuilder();
builder.setUrnForUserMetric("ns", "name2");
builder.setPTransformLabel("");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as above about null vs "" here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked this test to use a non user counter on the unbounded container


@DoFn.FinishBundle
public void finishBundle() throws InterruptedException {
// Thread.sleep(2000); // TODO smarter test without sleeps???

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this still be here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

MonitoringInfoMetricName metricName =
MonitoringInfoMetricName.named(SimpleMonitoringInfoBuilder.ELEMENT_COUNT_URN, labels);
this.counter = LabeledMetrics.counter(metricName);
// Place it in a metric container which is not bound to the step name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble parsing this comment. What is "it"? "not likely" below is a bit cryptic… can it ever happen?

If you are moved to elaborate, that would be great, but not essential 😀

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment

c1.inc(5);

List<MonitoringInfo> expected = new ArrayList<MonitoringInfo>();
// ArrayList<MonitoringInfo> actual = testObject.getMonitoringInfos();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/** @return a MetricName for a specific urn and labels map. */
/** @return a MonitoringInfoMetricName for a specific urn and labels map. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless it is forced by linter, this comment is obsolete, since it repeats method signature without adding extra information.

Method can be renamed to generateMetricName for readability.

Suggested change
/** @return a MonitoringInfoMetricName for a specific urn and labels map. */

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants