Remove io.ebean.meta.MetricType as it is unnecessary (#1923)

This commit is contained in:
Rob Bygrave
2020-02-22 09:17:14 +13:00
committed by GitHub
parent 444c868124
commit b24f093bbb
27 changed files with 56 additions and 170 deletions
@@ -5,11 +5,6 @@ package io.ebean.meta;
*/
public interface MetaMetric {
/**
* Return the metric type.
*/
MetricType getMetricType();
/**
* Return the metric name.
*/
+1 -11
View File
@@ -6,7 +6,6 @@ package io.ebean.meta;
public class MetricData {
private String name;
private String type;
private String hash;
private String loc;
private String sql;
@@ -16,9 +15,8 @@ public class MetricData {
private Long max;
private Long total;
public MetricData(String name, String type) {
public MetricData(String name) {
this.name = name;
this.type = type;
}
public MetricData() {
@@ -32,14 +30,6 @@ public class MetricData {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getHash() {
return hash;
}
@@ -1,40 +0,0 @@
package io.ebean.meta;
/**
* The type of Metric.
*/
public enum MetricType {
/**
* Transactions.
*/
TXN,
/**
* ORM Insert Update or Delete.
*/
IUD,
/**
* ORM queries.
*/
ORM,
/**
* DTO queries.
*/
DTO,
/**
* SQL queries with a label will have metrics collected.
* <p>
* SqlQuery and SqlUpdate without a label have no metrics collected.
*/
SQL,
/**
* L2 cache metrics.
*/
L2
}
@@ -1,7 +1,6 @@
package io.ebean.metric;
import io.ebean.ProfileLocation;
import io.ebean.meta.MetricType;
/**
* Factory to create timed metric counters.
@@ -18,21 +17,21 @@ public interface MetricFactory {
/**
* Create a timed metric group.
*/
TimedMetricMap createTimedMetricMap(MetricType metricType, String name);
TimedMetricMap createTimedMetricMap(String name);
/**
* Create a Timed metric.
*/
TimedMetric createTimedMetric(MetricType metricType, String name);
TimedMetric createTimedMetric(String name);
/**
* Create a counter metric.
*/
CountMetric createCountMetric(MetricType metricType, String name);
CountMetric createCountMetric(String name);
/**
* Create a Timed metric.
*/
QueryPlanMetric createQueryPlanMetric(MetricType metricType, Class<?> type, String label, ProfileLocation profileLocation, String sql);
QueryPlanMetric createQueryPlanMetric(Class<?> type, String label, ProfileLocation profileLocation, String sql);
}
@@ -1,6 +1,5 @@
package io.ebeaninternal.api;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.CountMetric;
import io.ebean.metric.MetricFactory;
@@ -22,11 +21,11 @@ public class ExtraMetrics {
*/
public ExtraMetrics() {
final MetricFactory factory = MetricFactory.get();
this.bindCapture = factory.createTimedMetric(MetricType.ORM, "ebean.queryplan.bindcapture");
this.planCollect = factory.createTimedMetric(MetricType.ORM, "ebean.queryplan.collect");
this.loadOneL2 = factory.createCountMetric(MetricType.ORM, "loadone.l2");
this.loadOneRef = factory.createCountMetric(MetricType.ORM, "loadone.ref");
this.loadOneNoLoader = factory.createCountMetric(MetricType.ORM, "loadone.noloader");
this.bindCapture = factory.createTimedMetric("ebean.queryplan.bindcapture");
this.planCollect = factory.createTimedMetric("ebean.queryplan.collect");
this.loadOneL2 = factory.createCountMetric("loadone.l2");
this.loadOneRef = factory.createCountMetric("loadone.ref");
this.loadOneNoLoader = factory.createCountMetric("loadone.noloader");
}
/**
@@ -18,8 +18,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static io.ebean.meta.MetricType.L2;
/**
* The default cache implementation.
* <p>
@@ -74,12 +72,12 @@ public class DefaultServerCache implements ServerCache {
MetricFactory factory = MetricFactory.get();
String prefix = "l2n.";
this.hitCount = factory.createCountMetric(L2, prefix + shortName + ".hit");
this.missCount = factory.createCountMetric(L2, prefix + shortName + ".miss");
this.putCount = factory.createCountMetric(L2, prefix + shortName + ".put");
this.removeCount = factory.createCountMetric(L2, prefix + shortName + ".remove");
this.clearCount = factory.createCountMetric(L2, prefix + shortName + ".clear");
this.evictCount = factory.createCountMetric(L2, prefix + shortName + ".evict");
this.hitCount = factory.createCountMetric(prefix + shortName + ".hit");
this.missCount = factory.createCountMetric(prefix + shortName + ".miss");
this.putCount = factory.createCountMetric(prefix + shortName + ".put");
this.removeCount = factory.createCountMetric(prefix + shortName + ".remove");
this.clearCount = factory.createCountMetric(prefix + shortName + ".clear");
this.evictCount = factory.createCountMetric(prefix + shortName + ".evict");
}
public void periodicTrim(BackgroundExecutor executor) {
@@ -47,7 +47,7 @@ class DumpMetricsData {
}
private MetricData create(MetaMetric metric) {
MetricData data = new MetricData(metric.getName(), metric.getMetricType().name());
MetricData data = new MetricData(metric.getName());
list.add(data);
return data;
}
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.deploy;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.TimedMetric;
@@ -25,12 +24,12 @@ class BeanIudMetrics {
MetricFactory metricFactory = MetricFactory.get();
String prefix = "iud." + beanShortName;
this.insert = metricFactory.createTimedMetric(MetricType.IUD, prefix + ".insert");
this.update = metricFactory.createTimedMetric(MetricType.IUD, prefix + ".update");
this.delete = metricFactory.createTimedMetric(MetricType.IUD, prefix + ".delete");
this.insertBatch = metricFactory.createTimedMetric(MetricType.IUD, prefix + ".insertBatch");
this.updateBatch = metricFactory.createTimedMetric(MetricType.IUD, prefix + ".updateBatch");
this.deleteBatch = metricFactory.createTimedMetric(MetricType.IUD, prefix + ".deleteBatch");
this.insert = metricFactory.createTimedMetric(prefix + ".insert");
this.update = metricFactory.createTimedMetric(prefix + ".update");
this.delete = metricFactory.createTimedMetric(prefix + ".delete");
this.insertBatch = metricFactory.createTimedMetric(prefix + ".insertBatch");
this.updateBatch = metricFactory.createTimedMetric(prefix + ".updateBatch");
this.deleteBatch = metricFactory.createTimedMetric(prefix + ".deleteBatch");
}
/**
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.dto;
import io.ebean.ProfileLocation;
import io.ebean.meta.MetricType;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.QueryPlanMetric;
import io.ebeaninternal.api.SpiDtoQuery;
@@ -49,6 +48,6 @@ public class DtoMappingRequest {
}
public QueryPlanMetric createMetric() {
return MetricFactory.get().createQueryPlanMetric(MetricType.DTO, type, label, profileLocation, sql);
return MetricFactory.get().createQueryPlanMetric(type, label, profileLocation, sql);
}
}
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.persist;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.TimedMetricMap;
@@ -42,9 +41,9 @@ final class DefaultPersistExecute implements PersistExecute {
this.exeUpdateSql = new ExeUpdateSql(binder);
this.exeCallableSql = new ExeCallableSql(binder);
this.defaultBatchSize = defaultBatchSize;
this.ormUpdateMetric = MetricFactory.get().createTimedMetricMap(MetricType.SQL, "orm.update.");
this.sqlUpdateMetric = MetricFactory.get().createTimedMetricMap(MetricType.SQL, "sql.update.");
this.sqlCallMetric = MetricFactory.get().createTimedMetricMap(MetricType.SQL, "sql.call.");
this.ormUpdateMetric = MetricFactory.get().createTimedMetricMap("orm.update.");
this.sqlUpdateMetric = MetricFactory.get().createTimedMetricMap("sql.update.");
this.sqlCallMetric = MetricFactory.get().createTimedMetricMap("sql.call.");
}
@Override
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.profile;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.CountMetric;
import io.ebean.metric.CountMetricStats;
@@ -12,14 +11,11 @@ import java.util.concurrent.atomic.LongAdder;
*/
class DCountMetric implements CountMetric {
private final MetricType metricType;
private final String name;
private final LongAdder count = new LongAdder();
DCountMetric(MetricType metricType, String name) {
this.metricType = metricType;
DCountMetric(String name) {
this.name = name;
}
@@ -55,27 +51,20 @@ class DCountMetric implements CountMetric {
long val = visitor.isReset() ? count.sumThenReset() : count.sum();
if (val > 0) {
visitor.visitCount(new DCountMetricStats(metricType, name, val));
visitor.visitCount(new DCountMetricStats(name, val));
}
}
private static class DCountMetricStats implements CountMetricStats {
private final MetricType metricType;
private final String name;
private final long count;
private DCountMetricStats(MetricType metricType, String name, long count) {
this.metricType = metricType;
private DCountMetricStats(String name, long count) {
this.name = name;
this.count = count;
}
@Override
public MetricType getMetricType() {
return metricType;
}
@Override
public String getName() {
return name;
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.profile;
import io.ebean.ProfileLocation;
import io.ebean.meta.MetricType;
import io.ebean.metric.CountMetric;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.QueryPlanMetric;
@@ -14,23 +13,23 @@ import io.ebean.metric.TimedMetricMap;
public class DMetricFactory implements MetricFactory {
@Override
public TimedMetricMap createTimedMetricMap(MetricType metricType, String name) {
return new DTimedMetricMap(metricType, name);
public TimedMetricMap createTimedMetricMap(String name) {
return new DTimedMetricMap(name);
}
@Override
public TimedMetric createTimedMetric(MetricType metricType, String name) {
return new DTimedMetric(metricType, name);
public TimedMetric createTimedMetric(String name) {
return new DTimedMetric(name);
}
@Override
public CountMetric createCountMetric(MetricType metricType, String name) {
return new DCountMetric(metricType, name);
public CountMetric createCountMetric(String name) {
return new DCountMetric(name);
}
@Override
public QueryPlanMetric createQueryPlanMetric(MetricType metricType, Class<?> type, String label, ProfileLocation profileLocation, String sql) {
return new DQueryPlanMetric(new DQueryPlanMeta(type, label, profileLocation, sql), new DTimedMetric(metricType, label));
public QueryPlanMetric createQueryPlanMetric(Class<?> type, String label, ProfileLocation profileLocation, String sql) {
return new DQueryPlanMetric(new DQueryPlanMeta(type, label, profileLocation, sql), new DTimedMetric(label));
}
}
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.profile;
import io.ebean.ProfileLocation;
import io.ebean.meta.MetricType;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.TimedMetric;
import io.ebean.service.SpiProfileLocationFactory;
@@ -19,7 +18,7 @@ public class DProfileLocationFactory implements SpiProfileLocationFactory {
@Override
public ProfileLocation create(int lineNumber, String label) {
TimedMetric timedMetric = MetricFactory.get().createTimedMetric(MetricType.TXN, "txn.named." + label);
TimedMetric timedMetric = MetricFactory.get().createTimedMetric("txn.named." + label);
DTimedProfileLocation loc = new DTimedProfileLocation(lineNumber, label, timedMetric);
TimedProfileLocationRegistry.register(loc);
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.profile;
import io.ebean.meta.MetaQueryMetric;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.QueryPlanMetric;
import io.ebean.metric.TimedMetric;
@@ -49,11 +48,6 @@ class DQueryPlanMetric implements QueryPlanMetric {
return meta + " " + stats + " sql:" + getSql();
}
@Override
public MetricType getMetricType() {
return stats.getMetricType();
}
@Override
public Class<?> getType() {
return meta.getType();
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.profile;
import io.ebean.meta.MetricType;
import io.ebean.metric.TimedMetricStats;
/**
@@ -8,8 +7,6 @@ import io.ebean.metric.TimedMetricStats;
*/
class DTimeMetricStats implements TimedMetricStats {
private final MetricType metricType;
private String name;
private final boolean collected;
@@ -22,8 +19,7 @@ class DTimeMetricStats implements TimedMetricStats {
private final long max;
DTimeMetricStats(MetricType metricType, String name, boolean collected, long count, long total, long max) {
this.metricType = metricType;
DTimeMetricStats(String name, boolean collected, long count, long total, long max) {
this.name = name;
this.collected = collected;
this.count = count;
@@ -63,11 +59,6 @@ class DTimeMetricStats implements TimedMetricStats {
this.name = name;
}
@Override
public MetricType getMetricType() {
return metricType;
}
@Override
public String getName() {
return name;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.profile;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.TimedMetric;
@@ -15,8 +14,6 @@ import java.util.concurrent.atomic.LongAdder;
*/
class DTimedMetric implements TimedMetric {
private final MetricType metricType;
private final String name;
private final LongAdder count = new LongAdder();
@@ -27,8 +24,7 @@ class DTimedMetric implements TimedMetric {
private boolean collected;
DTimedMetric(MetricType metricType, String name) {
this.metricType = metricType;
DTimedMetric(String name) {
this.name = name;
}
@@ -92,9 +88,9 @@ class DTimedMetric implements TimedMetric {
private DTimeMetricStats getStatistics(boolean reset) {
try {
if (reset) {
return new DTimeMetricStats(metricType, name, collected, count.sumThenReset(), total.sumThenReset(), max.getThenReset());
return new DTimeMetricStats(name, collected, count.sumThenReset(), total.sumThenReset(), max.getThenReset());
} else {
return new DTimeMetricStats(metricType, name, collected, count.sum(), total.sum(), max.get());
return new DTimeMetricStats(name, collected, count.sum(), total.sum(), max.get());
}
} finally {
collected = true;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.profile;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.TimedMetricMap;
@@ -8,14 +7,11 @@ import java.util.concurrent.ConcurrentHashMap;
class DTimedMetricMap implements TimedMetricMap {
private final MetricType metricType;
private final String name;
private final ConcurrentHashMap<String, DTimedMetric> map = new ConcurrentHashMap<>();
DTimedMetricMap(MetricType metricType, String name) {
this.metricType = metricType;
DTimedMetricMap(String name) {
this.name = name;
}
@@ -26,7 +22,7 @@ class DTimedMetricMap implements TimedMetricMap {
@Override
public void add(String key, long exeMicros) {
map.computeIfAbsent(key, (k) -> new DTimedMetric(metricType, name + key)).add(exeMicros);
map.computeIfAbsent(key, (k) -> new DTimedMetric(name + key)).add(exeMicros);
}
@Override
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.query;
import io.ebean.ProfileLocation;
import io.ebean.config.dbplatform.SqlLimitResponse;
import io.ebean.meta.MetricType;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.TimedMetric;
import io.ebeaninternal.api.CQueryPlanKey;
@@ -347,7 +346,7 @@ public class CQueryPlan implements SpiQueryPlan {
}
TimedMetric createTimedMetric() {
return MetricFactory.get().createTimedMetric(MetricType.ORM, label);
return MetricFactory.get().createTimedMetric(label);
}
void captureBindForQueryPlan(CQueryPredicates predicates, long executionTimeMicros) {
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.query;
import io.ebean.meta.MetaQueryMetric;
import io.ebean.meta.MetricType;
import io.ebean.metric.TimedMetric;
import io.ebean.metric.TimedMetricStats;
@@ -87,11 +86,6 @@ public final class CQueryPlanStats {
return "label:" + getLabel() + " location:" + getLocation() + " metrics:" + metrics + " sql:" + getSql();
}
@Override
public MetricType getMetricType() {
return MetricType.ORM;
}
@Override
public Class<?> getType() {
return queryPlan.getBeanType();
@@ -3,7 +3,6 @@ package io.ebeaninternal.server.query;
import io.ebean.RowConsumer;
import io.ebean.RowMapper;
import io.ebean.SqlRow;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.TimedMetricMap;
@@ -38,7 +37,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
this.binder = binder;
this.dbTrueValue = dbTrueValue == null ? "true" : dbTrueValue;
this.binaryOptimizedUUID = binaryOptimizedUUID;
this.timedMetricMap = MetricFactory.get().createTimedMetricMap(MetricType.SQL, "sql.query.");
this.timedMetricMap = MetricFactory.get().createTimedMetricMap("sql.query.");
}
@Override
@@ -13,7 +13,6 @@ import io.ebean.config.dbplatform.DatabasePlatform.OnQueryOnly;
import io.ebean.event.changelog.ChangeLogListener;
import io.ebean.event.changelog.ChangeLogPrepare;
import io.ebean.event.changelog.ChangeSet;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.TimedMetric;
@@ -189,9 +188,9 @@ public class TransactionManager implements SpiTransactionManager {
this.transactionFactory = TransactionFactoryBuilder.build(this, dataSourceSupplier, tenantProvider);
MetricFactory metricFactory = MetricFactory.get();
this.txnMain = metricFactory.createTimedMetric(MetricType.TXN, "txn.main");
this.txnReadOnly = metricFactory.createTimedMetric(MetricType.TXN, "txn.readonly");
this.txnNamed = metricFactory.createTimedMetricMap(MetricType.TXN, "txn.named.");
this.txnMain = metricFactory.createTimedMetric("txn.main");
this.txnReadOnly = metricFactory.createTimedMetric("txn.readonly");
this.txnNamed = metricFactory.createTimedMetricMap("txn.named.");
scopeManager.register(this);
}