Skip to content

Commit

Permalink
[FLINK-30409] Return a new metric group when creating closed metric g…
Browse files Browse the repository at this point in the history
…roup

This closes apache#21539
  • Loading branch information
mas-chen authored and xintongsong committed Dec 21, 2022
1 parent 79e6a7e commit 535f02c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ private AbstractMetricGroup<?> addGroup(String name, ChildType childType) {

AbstractMetricGroup newGroup = createChildGroup(name, childType);
AbstractMetricGroup prior = groups.put(name, newGroup);
if (prior == null) {
// no prior group with that name
if (prior == null || prior.isClosed()) {
// no prior group or closed group with that name
return newGroup;
} else {
// had a prior group with that name, add the prior group back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,29 @@ public void closedGroupCreatesClosedGroups() {
assertTrue(subgroup.isClosed());
}

@Test
public void addClosedGroupReturnsNewGroupInstance() {
GenericMetricGroup mainGroup =
new GenericMetricGroup(
exceptionOnRegister,
new DummyAbstractMetricGroup(exceptionOnRegister),
"mainGroup");

AbstractMetricGroup<?> subGroup = (AbstractMetricGroup<?>) mainGroup.addGroup("subGroup");

assertFalse(subGroup.isClosed());

subGroup.close();
assertTrue(subGroup.isClosed());

AbstractMetricGroup<?> newSubGroupWithSameNameAsClosedGroup =
(AbstractMetricGroup<?>) mainGroup.addGroup("subGroup");
assertFalse(
"The new subgroup should not be closed",
newSubGroupWithSameNameAsClosedGroup.isClosed());
assertTrue("The old sub group is not modified", subGroup.isClosed());
}

@Test
public void tolerateMetricNameCollisions() {
final String name = "abctestname";
Expand Down

0 comments on commit 535f02c

Please sign in to comment.