Skip to content

Use MonitoringInfo data model in Java SDK metrics - #7915

Closed
ryan-williams wants to merge 4 commits into
apache:masterfrom
ryan-williams:mi-mk
Closed

ryan-williams wants to merge 4 commits into
apache:masterfrom
ryan-williams:mi-mk

Conversation

@ryan-williams

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

Copy link
Copy Markdown
Contributor
  • fold MonitoringInfoMetricName into MetricKey ({URN, labels})
    • MetricKey.stepName is expanded to a MetricLabels map
    • MetricContainerStepMap is now keyed off MetricLabels
    • (existing use-cases just get a PTRANSFORM entry with the stepName)
  • MetricName is basically a MonitoringInfo URN
    • previously only modeled user metrics ({namespace,name})
    • can now model system-metric URNs as well
  • MetricResult is like a full MonitoringInfo ({key, metric value})
    • it also contains both "attempted" and "committed", which MonitoringInfo does not, but I'm addressing that elsewhere

R: @ajamato, @Ardagan, @robertwb

java/core → model-fn-execution dependency

I waffled on #7867 due to making java/core depend on the model-fn-execution proto module. However, talking with @ajamato, it seems like we're ok with that.

It may be possible to pull more java/core metrics classes (Metric{Key,Name,Labels,Container*}, {Counter,Distribution,Gauge}Cell, and maybe more) into runners-core/java, which already depends on the model-fn-execution protos module, and save adding the dep to java/core. Let me know if I should look into that.

If not, someone should sign off on in particular on needing to add org.apache.beam.model and vendored gRPC to this GCP module API surface test.

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.

MetricsContainer metricsContainer = getMetricsContainer(stepName);
monitoringInfos.forEach(
monitoringInfo -> {
if (monitoringInfo.hasMetric()) {

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.

A lot of the Flink-related changes here have since been factored out to #7971, I'll try to get that merged, and in the meantime set up a view of this PR rebased on top of that.

@Ardagan Ardagan 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.

Ryan says that he'll split this PR into smaller ones. I'll get back to it once split happens.

}
// If it is not a user counter, just use the first part of the URN, i.e. 'beam'
List<String> pieces = Splitter.on(':').splitToList(urn);
if (pieces.size() != 2) {

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes this might be possible. Use the last part of the split as the name, then combine everything else.

Ryan is going to move this to the labels later on, getting rid of all this parsing code anyways though

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.

Cool, I changed my handling to match DF, as I mentioned above, thanks.

return false;
}
// If it is not a user counter, just use the first part of the URN, i.e. 'beam'
List<String> pieces = Splitter.on(':').splitToList(urn);

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.

We got duplication of this logic:
in this PR: MetricUrns.java L66
and in DF runner

can be more.

@ryan-williams ryan-williams Mar 7, 2019 •

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 for flagging this!

I've changed this code (and MetricUrns.parseUrn) to match the semantics there ("namespace is everything up to the last :, with internal : deleted"), and changed that site to call MetricUrns.parseUrn.

Combining this with MetricUrns.parseUrn would also be nice, but they're pretty different contexts and I don't see an easy way to atm.

That change is just the last commit, adc7872.

@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.

Thanks for the comments, I believe I addressed everything.

"Ryan says that he'll split this PR into smaller ones" is probably overstating it, unfortunately.

I'll if I can take the Flink stuff (from #7971) out of this one in the meantime though.

It's a small part of this PR, though, and I don't have plans to factor anything else out atm.

return false;
}
// If it is not a user counter, just use the first part of the URN, i.e. 'beam'
List<String> pieces = Splitter.on(':').splitToList(urn);

@ryan-williams ryan-williams Mar 7, 2019 •

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 for flagging this!

I've changed this code (and MetricUrns.parseUrn) to match the semantics there ("namespace is everything up to the last :, with internal : deleted"), and changed that site to call MetricUrns.parseUrn.

Combining this with MetricUrns.parseUrn would also be nice, but they're pretty different contexts and I don't see an easy way to atm.

That change is just the last commit, adc7872.

}
// If it is not a user counter, just use the first part of the URN, i.e. 'beam'
List<String> pieces = Splitter.on(':').splitToList(urn);
if (pieces.size() != 2) {

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.

Cool, I changed my handling to match DF, as I mentioned above, thanks.

@ryan-williams

Copy link
Copy Markdown
Contributor Author

Run Java PreCommit

@ajamato

ajamato commented Mar 13, 2019

Copy link
Copy Markdown

R: @pabloem

@pabloem pabloem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My only serious comment is that we may have a bug because MetricLabels doesn't seem to implement hashcode or equals, so we probably cant retrieve containers properly? I may be wrong.

Other than that, it looks fine. thanks!

import org.apache.beam.model.pipeline.v1.RunnerApi.ReadPayload;
import org.apache.beam.model.pipeline.v1.RunnerApi.StandardEnvironments;
import org.apache.beam.model.pipeline.v1.RunnerApi.WindowIntoPayload;
import org.apache.beam.sdk.metrics.BeamUrns;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How come this file was fine before without importing this? : s

if (!metricsContainers.containsKey(stepName)) {
metricsContainers.put(stepName, new MetricsContainerImpl(stepName));
public MetricsContainerImpl getContainer(MetricLabels labels) {
if (!metricsContainers.containsKey(labels)) {

@pabloem pabloem Mar 16, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It doesnt seem like MetricLabels implements a hashCode or an equals function. I may be missing something, but perhaps we need a test that checks that getContainer(MetricLabels.ptransform("A")) will work (creating a new metriclabels), and that MetricLabels.ptransform("A").equals(MetricLabels.ptransform("A"))?

MetricKey key = MetricKey.create(monitoringInfo.getUrn(), monitoringInfo.getLabelsMap());
MetricName metricName = key.metricName();

MetricsContainer container = getMetricsContainer(key.labels());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For my clarification: Does this mean that a user metric can only have as label its PTransform?

@ryan-williams

Copy link
Copy Markdown
Contributor Author

I don't think this is the approach we're intending to go with. I'm putting more details in a ML post shortly.

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