ISSUE #1262: Remove Deprecated CodahaleMetricsProvider, CodahaleOpStatsLogger and …
…CodahaleStatsLogger classes.
### Motivation
We have deprecated these classes since 2018 and moved them to the codahale package.
### Changes
Removed the deprecated files.
Master Issue: #1262, #762
Reviewers: Enrico Olivelli <eolivelli@gmail.com>, Nicolò Boschi <boschi1997@gmail.com>
This closes #2459 from Ghatage/BOOKKEEPER-1262/cleanupDeprecatedCode, closes #1262
diff --git a/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleMetricsProvider.java b/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleMetricsProvider.java
deleted file mode 100644
index bbf7bcd..0000000
--- a/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleMetricsProvider.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * 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.bookkeeper.stats;
-
-import com.codahale.metrics.CsvReporter;
-import com.codahale.metrics.JmxReporter;
-import com.codahale.metrics.MetricFilter;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.ScheduledReporter;
-import com.codahale.metrics.Slf4jReporter;
-import com.codahale.metrics.graphite.Graphite;
-import com.codahale.metrics.graphite.GraphiteReporter;
-import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
-import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
-import com.google.common.base.Strings;
-import com.google.common.net.HostAndPort;
-import java.io.File;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import org.apache.commons.configuration.Configuration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A {@link StatsProvider} implemented based on <i>Codahale</i> metrics library.
- */
-@Deprecated
-@SuppressWarnings("deprecation")
-public class CodahaleMetricsProvider implements StatsProvider {
-
- static final Logger LOG = LoggerFactory.getLogger(CodahaleMetricsProvider.class);
-
- MetricRegistry metrics = null;
- List<ScheduledReporter> reporters = new ArrayList<ScheduledReporter>();
- JmxReporter jmx = null;
-
- synchronized void initIfNecessary() {
- if (metrics == null) {
- metrics = new MetricRegistry();
- metrics.registerAll(new MemoryUsageGaugeSet());
- metrics.registerAll(new GarbageCollectorMetricSet());
- }
- }
-
- public synchronized MetricRegistry getMetrics() {
- return metrics;
- }
-
- @Override
- public void start(Configuration conf) {
- initIfNecessary();
-
- int metricsOutputFrequency = conf.getInt("codahaleStatsOutputFrequencySeconds", 60);
- String prefix = conf.getString("codahaleStatsPrefix", "");
- String graphiteHost = conf.getString("codahaleStatsGraphiteEndpoint");
- String csvDir = conf.getString("codahaleStatsCSVEndpoint");
- String slf4jCat = conf.getString("codahaleStatsSlf4jEndpoint");
- String jmxDomain = conf.getString("codahaleStatsJmxEndpoint");
-
- if (!Strings.isNullOrEmpty(graphiteHost)) {
- LOG.info("Configuring stats with graphite");
- HostAndPort addr = HostAndPort.fromString(graphiteHost);
- final Graphite graphite = new Graphite(
- new InetSocketAddress(addr.getHostText(), addr.getPort()));
- reporters.add(GraphiteReporter.forRegistry(getMetrics())
- .prefixedWith(prefix)
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .filter(MetricFilter.ALL)
- .build(graphite));
- }
- if (!Strings.isNullOrEmpty(csvDir)) {
- // NOTE: 1/ metrics output files are exclusive to a given process
- // 2/ the output directory must exist
- // 3/ if output files already exist they are not overwritten and there is no metrics output
- File outdir;
- if (!Strings.isNullOrEmpty(prefix)) {
- outdir = new File(csvDir, prefix);
- } else {
- outdir = new File(csvDir);
- }
- LOG.info("Configuring stats with csv output to directory [{}]", outdir.getAbsolutePath());
- reporters.add(CsvReporter.forRegistry(getMetrics())
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .build(outdir));
- }
- if (!Strings.isNullOrEmpty(slf4jCat)) {
- LOG.info("Configuring stats with slf4j");
- reporters.add(Slf4jReporter.forRegistry(getMetrics())
- .outputTo(LoggerFactory.getLogger(slf4jCat))
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .build());
- }
- if (!Strings.isNullOrEmpty(jmxDomain)) {
- LOG.info("Configuring stats with jmx");
- jmx = JmxReporter.forRegistry(getMetrics())
- .inDomain(jmxDomain)
- .convertRatesTo(TimeUnit.SECONDS)
- .convertDurationsTo(TimeUnit.MILLISECONDS)
- .build();
- jmx.start();
- }
-
- for (ScheduledReporter r : reporters) {
- r.start(metricsOutputFrequency, TimeUnit.SECONDS);
- }
- }
-
- @Override
- public void stop() {
- for (ScheduledReporter r : reporters) {
- r.report();
- r.stop();
- }
- if (jmx != null) {
- jmx.stop();
- }
- }
-
- @Override
- public StatsLogger getStatsLogger(String name) {
- initIfNecessary();
- return new CodahaleStatsLogger(getMetrics(), name);
- }
-
- @Override
- public String getStatsName(String... statsComponents) {
- if (statsComponents.length == 0) {
- return "";
- }
- String baseName = statsComponents[0];
- String[] names = new String[statsComponents.length - 1];
- System.arraycopy(statsComponents, 1, names, 0, names.length);
- return MetricRegistry.name(baseName, names);
- }
-}
diff --git a/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleOpStatsLogger.java b/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleOpStatsLogger.java
deleted file mode 100644
index f6ee602..0000000
--- a/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleOpStatsLogger.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * 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.bookkeeper.stats;
-
-import com.codahale.metrics.Snapshot;
-import com.codahale.metrics.Timer;
-import java.util.Arrays;
-import java.util.concurrent.TimeUnit;
-
-@Deprecated
-class CodahaleOpStatsLogger implements OpStatsLogger {
- final Timer success;
- final Timer fail;
-
- CodahaleOpStatsLogger(Timer success, Timer fail) {
- this.success = success;
- this.fail = fail;
- }
-
- // OpStatsLogger functions
- @Override
- public void registerFailedEvent(long eventLatency, TimeUnit unit) {
- fail.update(eventLatency, unit);
- }
-
- @Override
- public void registerSuccessfulEvent(long eventLatency, TimeUnit unit) {
- success.update(eventLatency, unit);
- }
-
- @Override
- public void registerSuccessfulValue(long value) {
- // Values are inserted as millis, which is the unit they will be presented, to maintain 1:1 scale
- success.update(value, TimeUnit.MILLISECONDS);
- }
-
- @Override
- public void registerFailedValue(long value) {
- // Values are inserted as millis, which is the unit they will be presented, to maintain 1:1 scale
- fail.update(value, TimeUnit.MILLISECONDS);
- }
-
- @Override
- public synchronized void clear() {
- // can't clear a timer
- }
-
- /**
- * This function should go away soon (hopefully).
- */
- @Override
- public synchronized OpStatsData toOpStatsData() {
- long numFailed = fail.getCount();
- long numSuccess = success.getCount();
- Snapshot s = success.getSnapshot();
- double avgLatencyMillis = s.getMean();
-
- double[] defaultPercentiles = {10, 50, 90, 99, 99.9, 99.99};
- long[] latenciesMillis = new long[defaultPercentiles.length];
- Arrays.fill(latenciesMillis, Long.MAX_VALUE);
- for (int i = 0; i < defaultPercentiles.length; i++) {
- latenciesMillis[i] = (long) s.getValue(defaultPercentiles[i] / 100);
- }
- return new OpStatsData(numSuccess, numFailed, avgLatencyMillis, latenciesMillis);
- }
-}
diff --git a/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleStatsLogger.java b/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleStatsLogger.java
deleted file mode 100644
index 7a75258..0000000
--- a/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleStatsLogger.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * 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.bookkeeper.stats;
-
-import static com.codahale.metrics.MetricRegistry.name;
-
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
-
-/**
- * A {@link StatsLogger} implemented based on <i>Codahale</i> metrics library.
- */
-@Deprecated
-public class CodahaleStatsLogger implements StatsLogger {
- protected final String basename;
- final MetricRegistry metrics;
-
- CodahaleStatsLogger(MetricRegistry metrics, String basename) {
- this.metrics = metrics;
- this.basename = basename;
- }
-
- @Override
- public OpStatsLogger getOpStatsLogger(String statName) {
- Timer success = metrics.timer(name(basename, statName));
- Timer failure = metrics.timer(name(basename, statName + "-fail"));
- return new CodahaleOpStatsLogger(success, failure);
- }
-
- @Override
- public Counter getCounter(String statName) {
- final com.codahale.metrics.Counter c = metrics.counter(name(basename, statName));
- return new Counter() {
- @Override
- public synchronized void clear() {
- long cur = c.getCount();
- c.dec(cur);
- }
-
- @Override
- public Long get() {
- return c.getCount();
- }
-
- @Override
- public void inc() {
- c.inc();
- }
-
- @Override
- public void dec() {
- c.dec();
- }
-
- @Override
- public void add(long delta) {
- c.inc(delta);
- }
- };
- }
-
- @Override
- public <T extends Number> void registerGauge(final String statName, final Gauge<T> gauge) {
- String metricName = name(basename, statName);
- metrics.remove(metricName);
-
- metrics.register(metricName, new com.codahale.metrics.Gauge<T>() {
- @Override
- public T getValue() {
- return gauge.getSample();
- }
- });
- }
-
- @Override
- public <T extends Number> void unregisterGauge(String statName, Gauge<T> gauge) {
- // do nothing right now as the Codahale doesn't support conditional removal
- }
-
- @Override
- public StatsLogger scope(String scope) {
- String scopeName;
- if (0 == basename.length()) {
- scopeName = scope;
- } else {
- scopeName = name(basename, scope);
- }
- return new CodahaleStatsLogger(metrics, scopeName);
- }
-
- @Override
- public void removeScope(String name, StatsLogger statsLogger) {
- // no-op. the codahale stats logger doesn't have the references for stats logger.
- }
-}