-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-16524; Metrics for KIP-853 (#18304)
This change implement some of the metrics enumerated in KIP-853. The KafkaRaftMetrics object now exposes number-of-voters, number-of-observers and uncommitted-voter-change. The number-of-observers and uncommitted-voter-change metrics are only present on the active controller or leader, since it does not make sense for other replicas to report these metrics. In order to make these two metrics thread-safe, KafkaRaftMetrics needs to be passed into LeaderState, and therefore QuorumState. This introduces a circularity since the KafkaRaftMetrics constructor takes in QuorumState. To break the circularity for now, the logic using QuorumState will be moved to the KafkaRaftMetrics#initialize method. The BrokerServerMetrics object now exposes ignored-static-voters. The ControllerServerMetrics object now exposes IgnoredStaticVoters. To implement both metrics for "ignored static voters", this PR introduces the ExternalKRaftMetrics interface, which allows for higher layer metrics objects to be accessible within the raft module. Reviewers: José Armando García Sancio <[email protected]>
- Loading branch information
1 parent
226532a
commit 98d238a
Showing
25 changed files
with
681 additions
and
87 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
core/src/main/scala/kafka/raft/DefaultExternalKRaftMetrics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package kafka.raft | ||
|
||
import org.apache.kafka.controller.metrics.ControllerMetadataMetrics | ||
import org.apache.kafka.raft.ExternalKRaftMetrics | ||
import org.apache.kafka.server.metrics.BrokerServerMetrics | ||
|
||
class DefaultExternalKRaftMetrics( | ||
val brokerServerMetrics: Option[BrokerServerMetrics], | ||
val controllerMetadataMetrics: Option[ControllerMetadataMetrics] | ||
) extends ExternalKRaftMetrics { | ||
|
||
override def setIgnoredStaticVoters(ignoredStaticVoters: Boolean): Unit = { | ||
brokerServerMetrics.foreach(metrics => metrics.setIgnoredStaticVoters(ignoredStaticVoters)) | ||
controllerMetadataMetrics.foreach(metrics => metrics.setIgnoredStaticVoters(ignoredStaticVoters)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
core/src/test/scala/kafka/raft/DefaultExternalKRaftMetricsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package kafka.raft | ||
|
||
import com.yammer.metrics.core.MetricsRegistry | ||
import org.apache.kafka.common.metrics.Metrics | ||
import org.apache.kafka.controller.metrics.ControllerMetadataMetrics | ||
import org.apache.kafka.server.metrics.BrokerServerMetrics | ||
import org.junit.jupiter.api.Assertions.{assertFalse, assertTrue} | ||
import org.junit.jupiter.api.Test | ||
|
||
import java.util.Optional | ||
|
||
final class DefaultExternalKRaftMetricsTest { | ||
@Test | ||
def testDefaultExternalKRaftMetrics(): Unit = { | ||
val brokerServerMetrics = new BrokerServerMetrics(new Metrics()) | ||
val controllerMetadataMetrics = new ControllerMetadataMetrics(Optional.of(new MetricsRegistry())) | ||
val metrics = new DefaultExternalKRaftMetrics( | ||
Option(brokerServerMetrics), | ||
Option(controllerMetadataMetrics) | ||
) | ||
|
||
assertFalse(brokerServerMetrics.ignoredStaticVoters()) | ||
assertFalse(controllerMetadataMetrics.ignoredStaticVoters()) | ||
|
||
metrics.setIgnoredStaticVoters(true) | ||
|
||
assertTrue(brokerServerMetrics.ignoredStaticVoters()) | ||
assertTrue(controllerMetadataMetrics.ignoredStaticVoters()) | ||
|
||
metrics.setIgnoredStaticVoters(false) | ||
|
||
assertFalse(brokerServerMetrics.ignoredStaticVoters()) | ||
assertFalse(controllerMetadataMetrics.ignoredStaticVoters()) | ||
} | ||
|
||
@Test | ||
def testEmptyDefaultExternalKRaftMetrics(): Unit = { | ||
val metrics = new DefaultExternalKRaftMetrics(None, None) | ||
metrics.setIgnoredStaticVoters(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
raft/src/main/java/org/apache/kafka/raft/ExternalKRaftMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.kafka.raft; | ||
|
||
/** | ||
* Implementations of this interface store external metrics objects whose | ||
* values are updated in the raft layer. They are not allowed to block. | ||
*/ | ||
public interface ExternalKRaftMetrics { | ||
void setIgnoredStaticVoters(boolean ignoredStaticVoters); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.