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

ZOOKEEPER-3376: Extract metrics-api module. #2054

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zookeeper-metrics-providers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<modules>
<module>zookeeper-prometheus-metrics</module>
<module>zookeeper-metrics-api</module>
</modules>

</project>
41 changes: 41 additions & 0 deletions zookeeper-metrics-providers/zookeeper-metrics-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!--
/**
* 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.
*/
-->
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper-metrics-providers</artifactId>
<version>3.10.0-SNAPSHOT</version>
</parent>

<artifactId>zookeeper-metrics-api</artifactId>
<packaging>jar</packaging>
<name>Apache ZooKeeper - Metrics API</name>
<description>ZooKeeper Metrics API</description>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
/**
* A counter refers to a value which can only increase.
* Usually the value is reset when the process starts.
*
* A CounterSet is a set of {@link Counter} grouped by keys.
* A CounterSet is a set of {@link Counter} grouped by keys.
*/

public interface CounterSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

/**
* A Gauge is an application provided object which will be called by the metrics framework to sample a numeric value.
*
* A GaugeSet is a set of {@link Gauge} grouped by keys.
*/
public interface GaugeSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface MetricsContext {

/**
* Returns the CounterSet identified by the given name
* Null name is not allowed
* Null name is not allowed.
*
* @param name
* @return CounterSet identified by the name in this context.
Expand Down Expand Up @@ -94,7 +94,6 @@ public interface MetricsContext {

/**
* Unregisters the user provided {@link GaugeSet} bound to the given name.
*
* Unregistering with a null name is not allowed.
* @param name unique name of the GaugeSet in this context
*
Expand All @@ -104,7 +103,7 @@ public interface MetricsContext {
enum DetailLevel {
/**
* The returned Summary is expected to track only simple aggregated
* values, like min/max/avg
* values, like min/max/avg.
*/
BASIC,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@

/**
* A MetricsProvider is a system which collects Metrics and publishes current values to external facilities.
*
* The system will create an instance of the configured class using the default constructor, which must be public.<br>
* After the instantiation of the provider, the system will call {@link #configure(java.util.Properties) } in order to provide configuration,
* and then when the system is ready to work it will call {@link #start() }.
* After the instantiation of the provider, the system will call {@link #configure(java.util.Properties) } in order
* to provide configuration, and then when the system is ready to work it will call {@link #start() }.
* <br>
* Providers can be used both on ZooKeeper servers and on ZooKeeper clients.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
*/
public class RateLogger {

private final long LOG_INTERVAL; // Duration is in ms
private final long interval; // Duration is in ms

public RateLogger(Logger log) {
this(log, 100);
}

public RateLogger(Logger log, long interval) {
LOG = log;
LOG_INTERVAL = interval;
this.log = log;
this.interval = interval;
}

private final Logger LOG;
private final Logger log;
private String msg = null;
private long timestamp;
private int count = 0;
Expand All @@ -54,7 +54,7 @@ public void flush() {
if (value != null) {
log += " Last value:" + value;
}
LOG.warn(log);
this.log.warn(log);
}
msg = null;
value = null;
Expand All @@ -73,7 +73,7 @@ public void rateLimitLog(String newMsg, String newValue) {
if (Objects.equals(newMsg, msg)) {
++count;
value = newValue;
if (now - timestamp >= LOG_INTERVAL) {
if (now - timestamp >= interval) {
flush();
msg = newMsg;
timestamp = now;
Expand All @@ -84,7 +84,7 @@ public void rateLimitLog(String newMsg, String newValue) {
msg = newMsg;
value = newValue;
timestamp = now;
LOG.warn("Message:{} Value:{}", msg, value);
log.warn("Message:{} Value:{}", msg, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@
<dependencies>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<!-- we can create a metrics-providers-api package
once we get rid of ant based build
https://issues.apache.org/jira/browse/ZOOKEEPER-3376
-->
<artifactId>zookeeper</artifactId>
<artifactId>zookeeper-metrics-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.apache.zookeeper.metrics.MetricsContext;
import org.apache.zookeeper.metrics.Summary;
import org.apache.zookeeper.metrics.SummarySet;
import org.apache.zookeeper.server.util.QuotaMetricsUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.hamcrest.CoreMatchers;
Expand Down Expand Up @@ -127,7 +126,7 @@ public void testCounters() throws Exception {
@Test
public void testCounterSet_single() throws Exception {
// create and register a CounterSet
final String name = QuotaMetricsUtils.QUOTA_EXCEEDED_ERROR_PER_NAMESPACE;
final String name = "quota_exceeded_error_per_namespace";
final CounterSet counterSet = provider.getRootContext().getCounterSet(name);
final String[] keys = {"ns1", "ns2"};
final int count = 3;
Expand Down Expand Up @@ -159,7 +158,7 @@ public void testCounterSet_single() throws Exception {

@Test
public void testCounterSet_multiple() throws Exception {
final String name = QuotaMetricsUtils.QUOTA_EXCEEDED_ERROR_PER_NAMESPACE;
final String name = "quota_exceeded_error_per_namespace";

final String[] names = new String[]{name + "_1", name + "_2"};
final String[] keys = new String[]{"ns21", "ns22"};
Expand Down Expand Up @@ -206,7 +205,7 @@ public void testCounterSet_registerWithNullName() {
@Test
public void testCounterSet_negativeValue() {
// create and register a CounterSet
final String name = QuotaMetricsUtils.QUOTA_EXCEEDED_ERROR_PER_NAMESPACE;
final String name = "quota_exceeded_error_per_namespace";
final CounterSet counterSet = provider.getRootContext().getCounterSet(name);

// add negative value and make sure no exception is thrown
Expand All @@ -216,7 +215,7 @@ public void testCounterSet_negativeValue() {
@Test
public void testCounterSet_nullKey() {
// create and register a CounterSet
final String name = QuotaMetricsUtils.QUOTA_EXCEEDED_ERROR_PER_NAMESPACE;
final String name = "quota_exceeded_error_per_namespace";
final CounterSet counterSet = provider.getRootContext().getCounterSet(name);

// increment the count with null key and make sure no exception is thrown
Expand Down Expand Up @@ -508,7 +507,7 @@ private String callServlet() throws ServletException, IOException {

@Test
public void testGaugeSet_singleGaugeSet() throws Exception {
final String name = QuotaMetricsUtils.QUOTA_BYTES_LIMIT_PER_NAMESPACE;
final String name = "quota_bytes_limit_per_namespace";
final Number[] values = {10.0, 100.0};
final String[] keys = {"ns11", "ns12"};
final Map<String, Number> metricsMap = new HashMap<>();
Expand Down Expand Up @@ -553,8 +552,8 @@ public void testGaugeSet_singleGaugeSet() throws Exception {
@Test
public void testGaugeSet_multipleGaugeSets() throws Exception {
final String[] names = new String[] {
QuotaMetricsUtils.QUOTA_COUNT_LIMIT_PER_NAMESPACE,
QuotaMetricsUtils.QUOTA_COUNT_USAGE_PER_NAMESPACE
"quota_count_limit_per_namespace",
"quota_count_usage_per_namespace"
};

final Number[] values = new Number[] {20.0, 200.0};
Expand Down Expand Up @@ -614,8 +613,8 @@ public void testGaugeSet_multipleGaugeSets() throws Exception {
@Test
public void testGaugeSet_overwriteRegister() {
final String[] names = new String[] {
QuotaMetricsUtils.QUOTA_COUNT_LIMIT_PER_NAMESPACE,
QuotaMetricsUtils.QUOTA_COUNT_USAGE_PER_NAMESPACE
"quota_count_limit_per_namespace",
"quota_count_usage_per_namespace"
};

final int count = names.length;
Expand All @@ -642,7 +641,7 @@ public void testGaugeSet_overwriteRegister() {

@Test
public void testGaugeSet_nullKey() {
final String name = QuotaMetricsUtils.QUOTA_COUNT_LIMIT_PER_NAMESPACE;
final String name = "quota_count_limit_per_namespace";
final Map<String, Number> metricsMap = new HashMap<>();
metricsMap.put(null, 10.0);

Expand Down
5 changes: 5 additions & 0 deletions zookeeper-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<description>ZooKeeper server</description>

<dependencies>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper-metrics-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
Expand Down
Loading