Skip to content

[BEAM-6165] send metrics to Flink in portable Flink runner - #7183

Merged
tweise merged 4 commits into
apache:masterfrom
ryan-williams:fn
Dec 20, 2018
Merged

tweise merged 4 commits into
apache:masterfrom
ryan-williams:fn

Conversation

@ryan-williams

Copy link
Copy Markdown
Contributor

The Python SDK plumbs user metrics back in ProgressBundle{Progress,}Response, but the portable Flink runner doesn't send them on to Flink when executing stages.

This fixes that, and adds a test (in the python SDK) that increments a Counter in a DoFn and verifies that the result is written to a file by a Flink metrics reporter (FileReporter).

R: @angoenka
CC: @robertwb @tweise @mxm who I've discussed this with
CC: @ajamato who is doing related metrics work (cf. #6799)

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
Python Build Status --- Build Status
Build Status
Build Status --- --- ---

@ryan-williams ryan-williams left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

flagging a couple things for people to chime in on…


String masterUrl = options.getFlinkMaster();
Configuration flinkConfig = getFlinkConfiguration(confDir);
Configuration flinkConfiguration = getFlinkConfiguration(confDir);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this change is for consistency with the batch environment creation function (also in this file)

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 don't think this change is necessary for the scope of this PR.

LOG.info("Final accumulator values:");
for (Map.Entry<String, Object> entry : result.getAllAccumulatorResults().entrySet()) {
LOG.info("{} : {}", entry.getKey(), entry.getValue());
MetricsContainerStepMap stepMap = (MetricsContainerStepMap) entry.getValue();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe MetricsContainerStepMap was just being output as an object address here, so I expanded it to something more meaningful.

This could get factored out to a helper (overriding MetricsContainerStepMap.toString to do this feels like too much)

if (counterData.getValueCase() == BeamFnApi.CounterData.ValueCase.INT64_VALUE) {
counter.inc(counterData.getInt64Value());
} else {
throw new IllegalArgumentException("Unsupported CounterData type: " + counterData);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

org.apache.beam.sdk.metrics.Counter only supports longs…

intDistributionData.getMin(),
intDistributionData.getMax());
} else {
throw new IllegalArgumentException(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

likewise, Distribution only supports longs

return [
'java',
'-jar', flink_job_server_jar,
'--flink-master-url', '[local]',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

test_metrics below only works in [local] mode; the Flink Configuration isn't propagated through the [auto] mode, but maybe I should make that happen? or is it fine to only run this suite on local Flink clusters?

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.

This suite already assumes Flink embedded in the job server. If it would run on a remote Flink cluster, a metric reporter that writes to local file would also not work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we are agreeing that this change is OK: this suite is only run (or intended to run) on local Flink clusters.

I hadn't seen any extant part of it that would fail on a remote cluster, but you are saying such a part exists, IIUC.

I agree that my metric reporter would not work "as is" if this suite was run on a remote Flink cluster.

@mxm mxm Dec 3, 2018 •

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 think this could be avoided by adding/using this option for Python: #7183

edit: #7031

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hm I think you pasted the wrong link @mxm? afaict you just linked to this PR.

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.

Ah, this is the one I was referring to: #7031

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks, I am using the --flink-conf-dir added in #7031; I don't see a way to avoid specifying [local] here though. it also sounds like we are saying that this test is intended to only run in local mode, so we may as well make that explicit?

The previous ([auto]) code path goes through Flink code that doesn't seem to support injecting an existing Configuration (cf. streaming, batch; presumably this makes sense because it would be strange to do that if actually in remote/cluster mode?)

lmk if that doesn't make sense or there is something I should change here, thanks


String masterUrl = options.getFlinkMaster();
Configuration flinkConfig = getFlinkConfiguration(confDir);
Configuration flinkConfiguration = getFlinkConfiguration(confDir);

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 don't think this change is necessary for the scope of this PR.

Comment thread sdks/python/build.gradle Outdated
}
}

def flinkCompatibilityMatrixStreamingDOCKER = flinkCompatibilityMatrix(streaming: true)

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.

Why this change?

@tweise

tweise commented Dec 3, 2018

Copy link
Copy Markdown
Contributor

@ryan-williams thanks for working on this. I will take a look in the next few days. I appreciate the detailed attention to peripheral code but want to point out that PRs changes should be limited to the stated purpose. Stray, unrelated changes cause unnecessary noise/distraction and can even lead to merge conflicts. It would be nice to make such changes in a separate PR. IMO there is no need to back them out in this case unless specifically noted, but please keep it in mind for future work. Thanks!

*
* <p>Should be consistent with {@code parse_namespace_and_name} in monitoring_infos.py
*
* <p>TODO: not flink-specific; where should it live?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Flagging this as well, in case anyone has ideas.

I would normally view this as aMetricName constructor, but MetricName is in java-core, which doesn't depend on fn-api (and shouldn't be made to without good reason, I assume).

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 believe that should be changed in BeamFnApi.MonitoringInfo. Ok for now as a workaround.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure I follow; how could I put this String ⇒ MetricName logic into BeamFnApi.MonitoringInfo? The latter is codegen'd from proto definitions…

@ryan-williams

Copy link
Copy Markdown
Contributor Author

makes sense @tweise, and thanks for the quick look. I went ahead and removed all but the essential changes.

previously there was a beam_PreCommit_JavaPortabilityApi failure that I'm hoping was unrelated flakiness.

* Flink {@link org.apache.flink.metrics.reporter.MetricReporter metrics reporter} for writing
* metrics to a file (specified via the "metrics.reporter.test.file" config key).
*/
public class FileReporter extends AbstractReporter {

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.

Rename this to TestFileReporter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I originally gave it a name like that, however I talked myself in to that this is a potentially more general-purpose abstraction, and it is Flink specific, so that this (main, not test) package is an OK place for it.

If it was TestFileReporter then I'd feel obliged to put it in the test package, at which point the build plumbing to start a job-server in flink_runner_test.py that has the :beam-runners-flink -tests.jar` on the classpath would become more convoluted, so that was an added incentive to view this as not a "tests only" thing 😀

lmk what you think!

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 get why it's not practical to have it in the test scope. That's fine. Still, I think TestFileReporter reflects more accurately what it does. Also, it's configured via a test property, so I don't see how it is useful for non-testing.

@ryan-williams ryan-williams Dec 4, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's configured via a test property

ah, I left the reporter alias as test in flink_runner_test when I renamed this class to remove the Test prefix. I should change that alias to file, either way.

(update: I did this, and also left a placeholder in the FileReporter javadoc for whatever alias the user wants to use as the name of their FileReporter)

This is a reporter that writes the final state of all metrics to a file of the user's choosing. It can do this in test or production environments. It doesn't perform any assertions, or otherwise do things that only make sense in a testing context. It is fairly similar to Slf4jReporter, but its output is easier to parse (for machines or humans), and would normally be configured like:

metrics.reporters: file,
metrics.reporter.file.class: org.apache.beam.runners.flink.metrics.FileReporter
metrics.reporter.file.file: /some/path/on/job-mgr/node

To me, it feels weirder to name it Test* and leave it under main/, when it is not really that test-specific an abstraction.

However I understand if the possible non-test uses feel contrived, and perhaps having Test* names under main/ isn't too smelly.

I just want to make sure the vestigial metrics.reporter.test.* namespacing isn't driving the decision too heavily.

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.

That sounds reasonable. But shouldn't we use a more distinct name to avoid confusion, like BeamFlinkFileMetricReporter?

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 suppose it could come in handy when you just want to dump metrics locally.

Since package is org.apache.beam.runners.flink.metrics, FileReporter seems fine.

@ryan-williams ryan-williams Dec 5, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(woops, I'd not seen Max's comment above when I posted this, but seems like we're saying the same thing)

fwiw: "beam", "flink", "metrics", "file", and "reporter" are already in this class' name: org.apache.beam.runners.flink.metrics.FileReporter (and users would use this FQN in flink-conf.yaml, as in the example above).

I generally dislike the Java convention of repeating package-name segments in class' basenames, but recognize that it's common and people seem to like it, so happy to add here, just wanted to float the idea that org.apache.beam.runners.flink.metrics.BeamFlinkFileMetricReporter is redundant.

lmk if you still prefer it and I'll change it.

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.

Reason I brought it up is discoverability. Names like Node, Metric, Reporter all usually too generic, regardless in which package they reside. When you work in the IDE, you would probably not want to see dozens of matches when searching a class? I checked and in this case it is not the case however and not critical for this PR anyways. BTW it seems to be a convention in Beam code to prefix classes with the runner (like Flink when they are likely to appear in multiple runners).

return [
'java',
'-jar', flink_job_server_jar,
'--flink-master-url', '[local]',

@mxm mxm Dec 3, 2018 •

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 think this could be avoided by adding/using this option for Python: #7183

edit: #7031

*
* <p>Should be consistent with {@code parse_namespace_and_name} in monitoring_infos.py
*
* <p>TODO: not flink-specific; where should it live?

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 believe that should be changed in BeamFnApi.MonitoringInfo. Ok for now as a workaround.

* Parse a {@link MetricName} from a {@link
* org.apache.beam.model.fnexecution.v1.BeamFnApi.MonitoringInfoUrns.Enum}
*
* <p>Should be consistent with {@code parse_namespace_and_name} in monitoring_infos.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wanted to flag this for @ajamato in particular as the author of the python code I mimicked here.

How important is it that the python and java SDKs parse metric URNs into a {namespace, name} pairs in the same way?

From what I can tell, It may not be critical, though we should still probably agree on one semantic interpretation of what is "namespace" vs "name" of e.g. "beam:metric:element_count:v1".

With monitoring_infos.py as the reference implementation, the answer is {"beam", "metric:element_count:v1"}; shall I encode that in a comment in beam_fn_api.proto, and reference it here?

@ryan-williams

Copy link
Copy Markdown
Contributor Author

Run Java_Examples_Dataflow PreCommit

@tweise

tweise commented Dec 20, 2018

Copy link
Copy Markdown
Contributor

Run Python Flink ValidatesRunner

@tweise
tweise merged commit 1e41220 into apache:master Dec 20, 2018
@tweise

tweise commented Dec 20, 2018

Copy link
Copy Markdown
Contributor

@ryan-williams thanks for this contribution!

* <p>TODO: not flink-specific; where should it live?
*/
public static MetricName parseUrn(String urn) {
if (urn.startsWith(USER_COUNTER_URN_PREFIX.toString())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does calling toString on this work? The usage I have seen before involved extracting the attached object and pulling out a field from the enum.

See BeamUrns.getUrns

return value.getValueDescriptor().getOptions().getExtension(RunnerApi.beamUrn);

You could reference this file which pulls it in. SimpleMonitoringInfoBuilder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch, thanks! I just filed #7408 to fix

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