Skip to content

[BEAM-4775] key MetricResult by a MetricKey - #7867

Merged
mxm merged 4 commits into
apache:masterfrom
ryan-williams:mr-mk
Feb 28, 2019
Merged

mxm merged 4 commits into
apache:masterfrom
ryan-williams:mr-mk

Conversation

@ryan-williams

@ryan-williams ryan-williams commented Feb 17, 2019 •

Copy link
Copy Markdown
Contributor

(factored out of #7823)

MetricResult previously had MetricKey's fields inlined, possibly due to living in java/core while MetricKey is in runners/core.

Having callers use a MetricKey simplifies call-sites and prepares for expanding Java SDK metrics to support (ptransform- and pcollection-scoped) system metrics in addition to (ptransform-scoped) user metrics, which #7823 implements.

This change also moves MetricKey and MetricFiltering into java/core, which is basically necessary / logical based on the intra-metrics-class dependencies.

R: @robertwb, @ajamato

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

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

@ryan-williams

Copy link
Copy Markdown
Contributor Author

Run Java PreCommit

@ryan-williams

Copy link
Copy Markdown
Contributor Author

Run Java PreCommit

@ajamato

ajamato commented Feb 19, 2019

Copy link
Copy Markdown

One thing I don't like about MetricKey, is that its only applicable to user metrics. Which are identified with the following fields:

  • Step Name
  • Namespace
  • User provided Metric Name

MonitoringInfos are defined by

  • URN
  • Arbitrary set of Key value pair labels.
  • (Doesn't necessarily have a step name at all).

MetricKey is insufficient today to describe any metric which isn't defined by (step, namespace, metric name).

Take a look at MonitoringInfoMetricName (extends MetricName), which I added.
https://github.com/apache/beam/blob/5b1700db834cf949547a20a30f3ee1270710585a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MonitoringInfoMetricName.java

This can contain a URN and an arbitrary set of key value pair labels. I think this is the more generalized way to key a Metric and I would like to land on this in the future. I think we don't really need two separte classed MetricName and MetricKey either.

We could just have one class in the end similar to which represents the MetricKey.

The challenge I see with this though, is that querying the metrics and storing the metrics internally use the same classes today (MetricKey). It would be better to keep the user facing API more similar to how the user defines a metric (explicitly being able to access the name and namespace fields). In the end we might have an internal MonitoringInfoMetricKey separate from a (User)MetricKey the user can us in the querying API.

If this change unblocks your work now, then I think its fine to proceed. But I wanted to give a bit more context here on how I think this could be simplified in the end. I think we have too many classes right now, for identifying metrics.

.appendText("inNamespace: ")
.appendValue(namespace)
.appendText("inKey: ")
.appendValue(key)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please check if tostring is implemented in MonitoringInfoMetricKey and MetricKey

/**
* An adapter between the {@link MetricsContainerStepMap} and Codahale's {@link Metric} interface.
*/
class SparkBeamMetric implements Metric {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I also notice the Metric class will only handle User Metrics (Name, Namespace). If spark only cares about UserMetrics that's okay I suppose. but won't handle more generlized MonitoringInfos

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.

Agreed. Most of what I've done so far (in #7823) is [expanding the Java SDK metrics classes to support the wider MonitoringInfo data model] while [preserving semantics of existing code that assumes / requires user-metrics].

In this case, I end up adapting this to use a MetricLabels.value() API that assumes there is exactly one label set on the MonitoringInfo (PTRANSFORM xor PCOLLECTION) and uses that, so it should be reasonably "future-proofed"

import org.apache.beam.sdk.metrics.MetricResult;
import org.apache.beam.sdk.metrics.MetricsOptions;
import org.apache.beam.sdk.metrics.MetricsSink;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you have any more details for this class? Link to doc? Explaination of how to use it. Example code of handling the Post request, etc.? What is the wire format used? Can it be included in this header?

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.

Yea, those would be nice to have 😀 I don't really know anything about it, and just made these changes to preserve the existing format.

I'll do some digging and try to formalize / document it better, though I assume that [not rocking the wire-format boat with whatever is going on here] is going to be what we want to do, in the short term at least.

@ryan-williams

Copy link
Copy Markdown
Contributor Author

Thanks Alex. The good news is I think we agree about everything you've said.

In #7823 I basically turn the existing Java SDK metrics classes into wrappers for corresponding MonitoringInfo structures:

  • MetricKey: {URN, labels}
  • MetricName: URN
    • I basically folded MonitoringInfoMetricName into MetricName, which becomes the only implementation of that concept
  • MetricLabels: labels map
    • thin wrapper over the raw map, that also exposes some APIs that encode the fact that today we expect MonitoringInfos to have exactly one of {PTRANSFORM,PCOLLECTION}.

So that is the larger vision, which this PR is a small step toward. LMK if that sounds off to you. I'm in a constant process of pulling stuff out of #7823 so that the real work will be in clearer relief there.

A different question that came up with @mxm on #7866 is around what packages things should live in. I don't think it's too bad if MetricKey goes into java/core here, but where it gets complicated is that inevitably, MetricResult → MetricKey → {fn-api protos}, which adds [java/core → model-fn-execution], which gives me some pause.

Hopefully we can push on other parts of this (and related PRs) while I think more about that question. Ofc any thoughts are welcome.

@ryan-williams

Copy link
Copy Markdown
Contributor Author

hm, I see a bunch of

BeamIOError: src and dst files do not exist. src: /tmp/beam-temp-py-wordcount-direct-42fabb3a34cb11e984ac42010a80000d/1c504dc3-20b6-4f8c-88ef-15912e953404.py-wordcount-direct, dst: /tmp/py-wordcount-direct-00000-of-00002 with exceptions None [while running 'write/Write/WriteImpl/FinalizeWrite
--
'] with exceptions None

in the scan for Portable_Python (batch; streaming seems to have passed).

@ryan-williams

Copy link
Copy Markdown
Contributor Author

Run Portable_Python PreCommit

@mxm
mxm merged commit 9afacc4 into apache:master Feb 28, 2019
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.

3 participants