Skip to content

KAFKA-8696: clean up Sum/Count/Total metrics#7057

Merged
guozhangwang merged 2 commits into
apache:trunkfrom
vvcephei:MINOR-fix-total-count-sum-metrics
Jul 23, 2019
Merged

KAFKA-8696: clean up Sum/Count/Total metrics#7057
guozhangwang merged 2 commits into
apache:trunkfrom
vvcephei:MINOR-fix-total-count-sum-metrics

Conversation

@vvcephei

@vvcephei vvcephei commented Jul 9, 2019

Copy link
Copy Markdown
Contributor
  • Clean up one redundant and one misplaced metric
  • Clarify the relationship among these metrics to avoid future confusion

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@vvcephei

vvcephei commented Jul 9, 2019

Copy link
Copy Markdown
Contributor Author

@guozhangwang @cadonna ,

I noticed this while looking at the comments on #6979

I remembered these metrics being super confusing in the past, and it didn't seem too hard to just clean it up. What do you think?

-John

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'm not generally a fan of building tall class hierarchies, but in this case, it seemed like the cleanest way to delegate to Sum, which has the advantage of code de-duplication, but more importantly makes the code more self-documenting... I.e., this metric is exactly the same as Sum, except that it always increments by 1.

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 metric was redundant with Sum (their implementations are exactly the same). I decided in favor of Sum because it's a top-level class.

Since this class is public and not internal, though, I figure we'd better just mark it as deprecated for now, although it's unused in our code base as of this PR.

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 metric had been added as an internal class in Streams, since it was only needed by Streams, but this actually seems like a liability...

Putting it here reduces the chance that someone would accidentally use Count, not realizing it is sampled, whereas this metric's presence would force you to consider which of the two options you want.

Also, if someone did want a non-sampled count in the future, they might just re-implement it here, if they didn't happen to find the one in Streams, leading us back into the situation I'm trying to fix here, where we have redundant metrics.

These two points seem to outweigh the advantage of keeping a class defined in the smallest scope in which it's needed.

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.

Since we're relocating packages, it's a good opportunity to try an pick a more semantic and consistent name... Not sure if I succeeded.

@vvcephei

vvcephei commented Jul 9, 2019

Copy link
Copy Markdown
Contributor Author

None of those test timeouts seem related...

Retest this, please.

@bbejeck

bbejeck commented Jul 10, 2019

Copy link
Copy Markdown
Member

Retest this, please.

@mjsax

mjsax commented Jul 11, 2019

Copy link
Copy Markdown
Member

Would this need a KIP?

@bbejeck

bbejeck commented Jul 11, 2019

Copy link
Copy Markdown
Member

retest this please

@vvcephei

Copy link
Copy Markdown
Contributor Author

@mjsax , yeah, I guess it would, since we've moving a metric from internal to a public place.

@vvcephei

Copy link
Copy Markdown
Contributor Author

Created KIP-488: https://cwiki.apache.org/confluence/x/kkAyBw

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.

nit: align indention

Comment thread clients/src/main/java/org/apache/kafka/common/metrics/stats/CumulativeSum.java Outdated
Comment thread clients/src/main/java/org/apache/kafka/common/metrics/stats/CumulativeCount.java Outdated

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

Just one question about naming compared with KIP itself, otherwise lgtm.

Comment thread clients/src/main/java/org/apache/kafka/common/metrics/stats/CumulativeSum.java Outdated

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

Overall this LGTM, just waiting for updates from KIP changes

@vvcephei vvcephei changed the title MINOR: clean up Sum/Count/Total metrics KAFKA-8696: clean up Sum/Count/Total metrics Jul 22, 2019
* Clean up one redundant and one misplaced metric
* Clarify the relationship among these metrics to avoid future confusion

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

Hi @bbejeck @mjsax @guozhangwang ,

I believe this is ready for reviews, as the KIP has just been accepted.

Still waiting on the build, so the jury is out on style/compilation/tests.

Thanks,
-John

public Meter(TimeUnit unit, SampledStat rateStat, MetricName rateMetricName, MetricName totalMetricName) {
if (!(rateStat instanceof SampledTotal) && !(rateStat instanceof Count)) {
throw new IllegalArgumentException("Meter is supported only for SampledTotal and Count");
if (!(rateStat instanceof WindowedSum)) {

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.

note that WindowedCount is a subclass of WindowedSum, so we just need one condition to check both (and also to permit any of the deprecated classes, as they all also subclass WindowedSum).

@guozhangwang

Copy link
Copy Markdown
Contributor

All test failures seem transient. retest this please

@guozhangwang guozhangwang 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 except a few minor things. Wait for one green build.

}

/**
* @deprecated since 2.4 Use {@link SampledTotal} instead.

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.

The javadoc seems incorrect.

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.

Oops! I wonder how that happened... Thanks for catching it.

for (Sensor sensor : Arrays.asList(parent, child)) {
sensor.add(metrics.metricName(sensor.name() + ".avg", "grp1"), new Avg());
sensor.add(metrics.metricName(sensor.name() + ".count", "grp1"), new Count());
sensor.add(metrics.metricName(sensor.name() + ".count", "grp1"), new WindowedCount());

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.

nit: also change the metric name?

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 don't know... I'm reluctant to expand the scope of this change to change registered metric names. I know these are just in tests, but still, it seems not necessary.

Do you think changing these metric names increases clarity, or were you just asking if we should consider changing them?

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 do not feel strong about it, just asking whether it's worth doing. Seems it's not worth doing after all.

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.

Ok. Thanks for bringing it up, but let's just leave it alone... It will be an opportunity for someone to use git blame later and curse my name.

break;
case TOTAL:
sensor.add(metrics.metricName("test.metric.total", "total", tags), new Total());
sensor.add(metrics.metricName("test.metric.total", "total", tags), new CumulativeSum());

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.

nit: ditto here about metric name.

@guozhangwang

Copy link
Copy Markdown
Contributor

retest this please

@guozhangwang

Copy link
Copy Markdown
Contributor

Test failures are transient, merging to trunk now.

@guozhangwang
guozhangwang merged commit a8aedc8 into apache:trunk Jul 23, 2019
@guozhangwang

Copy link
Copy Markdown
Contributor

cc @cadonna : the other PR can be rebased.

@vvcephei
vvcephei deleted the MINOR-fix-total-count-sum-metrics branch July 24, 2019 22:35
@vvcephei

Copy link
Copy Markdown
Contributor Author

Yay! Thanks, @guozhangwang .

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants