Repository navigation
[BEAM-6165] send metrics to Flink in portable Flink runner - #7183
Conversation
ryan-williams
left a comment
There was a problem hiding this comment.
flagging a couple things for people to chime in on…
|
|
||
| String masterUrl = options.getFlinkMaster(); | ||
| Configuration flinkConfig = getFlinkConfiguration(confDir); | ||
| Configuration flinkConfiguration = getFlinkConfiguration(confDir); |
There was a problem hiding this comment.
this change is for consistency with the batch environment creation function (also in this file)
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
org.apache.beam.sdk.metrics.Counter only supports longs…
| intDistributionData.getMin(), | ||
| intDistributionData.getMax()); | ||
| } else { | ||
| throw new IllegalArgumentException( |
There was a problem hiding this comment.
likewise, Distribution only supports longs
| return [ | ||
| 'java', | ||
| '-jar', flink_job_server_jar, | ||
| '--flink-master-url', '[local]', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
hm I think you pasted the wrong link @mxm? afaict you just linked to this PR.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
I don't think this change is necessary for the scope of this PR.
| } | ||
| } | ||
|
|
||
| def flinkCompatibilityMatrixStreamingDOCKER = flinkCompatibilityMatrix(streaming: true) |
|
@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? |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
I believe that should be changed in BeamFnApi.MonitoringInfo. Ok for now as a workaround.
There was a problem hiding this comment.
not sure I follow; how could I put this String ⇒ MetricName logic into BeamFnApi.MonitoringInfo? The latter is codegen'd from proto definitions…
|
makes sense @tweise, and thanks for the quick look. I went ahead and removed all but the essential changes. previously there was a |
| * 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 { |
There was a problem hiding this comment.
Rename this to TestFileReporter?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
That sounds reasonable. But shouldn't we use a more distinct name to avoid confusion, like BeamFlinkFileMetricReporter?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
(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.
There was a problem hiding this comment.
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]', |
| * | ||
| * <p>Should be consistent with {@code parse_namespace_and_name} in monitoring_infos.py | ||
| * | ||
| * <p>TODO: not flink-specific; where should it live? |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
|
Run Java_Examples_Dataflow PreCommit |
|
Run Python Flink ValidatesRunner |
|
@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())) { |
There was a problem hiding this comment.
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
You could reference this file which pulls it in. SimpleMonitoringInfoBuilder
There was a problem hiding this comment.
good catch, thanks! I just filed #7408 to fix
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
Counterin aDoFnand 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)