Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: make Sensor#add idempotent #4853

Merged
merged 3 commits into from
Apr 12, 2018
Merged

MINOR: make Sensor#add idempotent #4853

merged 3 commits into from
Apr 12, 2018

Conversation

vvcephei
Copy link
Contributor

This change makes adding a metric to a sensor idempotent.
That is, if the metric is already added to the sensor, the method
returns with success.

The current behavior is that any attempt to register a second metric
with the same name is an error.

Testing strategy: There is a new unit test covering this behavior

Committer Checklist (excluded from commit message)

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

@vvcephei
Copy link
Contributor Author

@guozhangwang @mjsax @bbejeck

I decided to pull this change into a separate PR. Who else should I ask for a review?

@vvcephei vvcephei mentioned this pull request Apr 11, 2018
3 tasks
@vvcephei
Copy link
Contributor Author

@wicknicks Can you also take a look at this proposal?

Copy link
Contributor

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

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

Overall lgtm. I don't have that much experience with metrics, but what if someone wants to update or change a metric with the same name? How would that be accomplished?

@bbejeck
Copy link
Contributor

bbejeck commented Apr 11, 2018

failures are related; unused import in ConnectMetricsTest

@vvcephei
Copy link
Contributor Author

@bbejeck Thanks for the review.

You can't update or change a metric, even today. You would have to remove the old metric and then add a new one. This should work the same before as after this PR.

Copy link
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

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

One nit comment, otherwise LGTM.

this.stats.add(stat);
return true;
} else if (metrics.containsKey(metricName)) {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we log here indicating an add function called for the same metric name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This behavior is similar to the idempotent sensor creation at https://github.com/vvcephei/kafka/blob/1578db793d54482adaa6a90d4ca1fce45afb929a/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java#L399

Interestingly, the choice there was to log only when the sensor got created, not when it was a no-op.

I'm open to whatever.

@vvcephei
Copy link
Contributor Author

the tests actually passed, but jenkins got rate-limited from Github.

Retest this, please.

@guozhangwang guozhangwang merged commit cc43e77 into apache:trunk Apr 12, 2018
koqizhao pushed a commit to koqizhao/kafka that referenced this pull request Apr 12, 2018
This change makes adding a metric to a sensor idempotent.
That is, if the metric is already added to the sensor, the method
returns with success.

The current behavior is that any attempt to register a second metric
with the same name is an error.

Testing strategy: There is a new unit test covering this behavior

Reviewers: Guozhang Wang <[email protected]>, Bill Bejeck <[email protected]>
koqizhao pushed a commit to koqizhao/kafka that referenced this pull request Apr 12, 2018
This change makes adding a metric to a sensor idempotent.
That is, if the metric is already added to the sensor, the method
returns with success.

The current behavior is that any attempt to register a second metric
with the same name is an error.

Testing strategy: There is a new unit test covering this behavior

Reviewers: Guozhang Wang <[email protected]>, Bill Bejeck <[email protected]>
koqizhao pushed a commit to koqizhao/kafka that referenced this pull request Apr 12, 2018
This change makes adding a metric to a sensor idempotent.
That is, if the metric is already added to the sensor, the method
returns with success.

The current behavior is that any attempt to register a second metric
with the same name is an error.

Testing strategy: There is a new unit test covering this behavior

Reviewers: Guozhang Wang <[email protected]>, Bill Bejeck <[email protected]>
@vvcephei vvcephei deleted the idempotent-sensor-add branch April 12, 2018 16:01
@mjsax mjsax added streams and removed streams labels May 7, 2018
ying-zheng pushed a commit to ying-zheng/kafka that referenced this pull request Jul 6, 2018
This change makes adding a metric to a sensor idempotent.
That is, if the metric is already added to the sensor, the method
returns with success.

The current behavior is that any attempt to register a second metric
with the same name is an error.

Testing strategy: There is a new unit test covering this behavior

Reviewers: Guozhang Wang <[email protected]>, Bill Bejeck <[email protected]>
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