mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1670 - Expose metrics as ServerMetrics interface (improvement over existing BasicMetricVisitor use)
This commit is contained in:
@@ -2,9 +2,9 @@ package io.ebean;
|
||||
|
||||
import io.ebean.annotation.PersistBatch;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import io.ebean.meta.MetricType;
|
||||
import io.ebean.meta.ServerMetrics;
|
||||
import io.ebean.util.StringHelper;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiQuery;
|
||||
@@ -64,12 +64,12 @@ public abstract class BaseTestCase {
|
||||
server().getMetaInfoManager().resetAllMetrics();
|
||||
}
|
||||
|
||||
protected BasicMetricVisitor visitMetricsBasic() {
|
||||
return server().getMetaInfoManager().visitBasic();
|
||||
protected ServerMetrics collectMetrics() {
|
||||
return server().getMetaInfoManager().collectMetrics();
|
||||
}
|
||||
|
||||
protected List<MetaTimedMetric> visitTimedMetrics() {
|
||||
return visitMetricsBasic().getTimedMetrics();
|
||||
return collectMetrics().getTimedMetrics();
|
||||
}
|
||||
|
||||
protected List<MetaTimedMetric> sqlMetrics() {
|
||||
|
||||
@@ -2,9 +2,9 @@ package io.ebean;
|
||||
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaQueryMetric;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import io.ebean.meta.ServerMetrics;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -25,13 +25,13 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
@AfterClass
|
||||
public static void reportStats() {
|
||||
BasicMetricVisitor basic = DB.getDefault().getMetaInfoManager().visitBasic();
|
||||
for (MetaQueryMetric metric : basic.getDtoQueryMetrics()) {
|
||||
ServerMetrics metrics = DB.getDefault().getMetaInfoManager().collectMetrics();
|
||||
for (MetaQueryMetric metric : metrics.getDtoQueryMetrics()) {
|
||||
System.out.println(metric);
|
||||
}
|
||||
|
||||
System.out.println("-- transaction metrics --");
|
||||
for (MetaTimedMetric metric : basic.getTimedMetrics()) {
|
||||
for (MetaTimedMetric metric : metrics.getTimedMetrics()) {
|
||||
System.out.println(metric);
|
||||
}
|
||||
}
|
||||
@@ -44,19 +44,19 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
resetAllMetrics();
|
||||
|
||||
String[] prefix = { "Bl", "B", "Red", "jim" };
|
||||
String[] prefix = {"Bl", "B", "Red", "jim"};
|
||||
|
||||
for (String val : prefix) {
|
||||
DB.find(Contact.class)
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where()
|
||||
.istartsWith(concat("lastName", ", ", "firstName"), val).orderBy().asc("lastName").setMaxRows(10)
|
||||
.asDto(ContactDto.class).setLabel("prefixLoop").findList();
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where()
|
||||
.istartsWith(concat("lastName", ", ", "firstName"), val).orderBy().asc("lastName").setMaxRows(10)
|
||||
.asDto(ContactDto.class).setLabel("prefixLoop").findList();
|
||||
|
||||
}
|
||||
|
||||
BasicMetricVisitor basic = visitMetricsBasic();
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
|
||||
List<MetaQueryMetric> stats = basic.getDtoQueryMetrics();
|
||||
List<MetaQueryMetric> stats = metrics.getDtoQueryMetrics();
|
||||
for (MetaQueryMetric stat : stats) {
|
||||
long meanMicros = stat.getMean();
|
||||
assertThat(meanMicros).isLessThan(900_000);
|
||||
@@ -74,10 +74,10 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DtoQuery<ContactDto> query = DB.find(Contact.class)
|
||||
// we must explicitly add the id property for DTO query (if we want it)
|
||||
.select("id, email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").asDto(ContactDto.class).setLabel("explicitId")
|
||||
.setRelaxedMode();
|
||||
// we must explicitly add the id property for DTO query (if we want it)
|
||||
.select("id, email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").asDto(ContactDto.class).setLabel("explicitId")
|
||||
.setRelaxedMode();
|
||||
|
||||
List<ContactDto> dtos = query.findList();
|
||||
|
||||
@@ -90,7 +90,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,8 +101,8 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DtoQuery<ContactDto> query = DB.find(Contact.class)
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").asDto(ContactDto.class);
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").asDto(ContactDto.class);
|
||||
|
||||
List<ContactDto> dtos = query.findList();
|
||||
|
||||
@@ -115,7 +115,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,8 +126,8 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos = DB.find(Contact.class).setLabel("emailFullName")
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").setMaxRows(10).asDto(ContactDto.class).findList();
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").setMaxRows(10).asDto(ContactDto.class).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -140,11 +140,11 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql.get(0)).contains("select top 10 t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos = DB.find(Contact.class)
|
||||
.select("id, email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").setMaxRows(10).asDto(ContactDto.class).findList();
|
||||
.select("id, email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").setMaxRows(10).asDto(ContactDto.class).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -170,11 +170,11 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql.get(0)).contains("select top 10 t0.id, t0.email, "
|
||||
+ concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +186,8 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos = DB.find(Contact.class)
|
||||
.select(concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("lastName").orderBy()
|
||||
.asc("lastName").asDto(ContactDto.class).setFirstRow(2).setMaxRows(5).findList();
|
||||
.select(concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("lastName").orderBy()
|
||||
.asc("lastName").asDto(ContactDto.class).setFirstRow(2).setMaxRows(5).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -209,8 +209,8 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactTotals> contactDtos = DB.find(Contact.class).select("lastName, count(*) as totalCount").where()
|
||||
.isNotNull("lastName").having().gt("count(*)", 1).orderBy().desc("count(*)").asDto(ContactTotals.class)
|
||||
.findList();
|
||||
.isNotNull("lastName").having().gt("count(*)", 1).orderBy().desc("count(*)").asDto(ContactTotals.class)
|
||||
.findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -229,7 +229,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<ContactTotals> contactDtos = DB.find(Contact.class).select("lastName, count(*) as totalCount").where()
|
||||
.isNotNull("lastName").asDto(ContactTotals.class).findList();
|
||||
.isNotNull("lastName").asDto(ContactTotals.class).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaQueryMetric;
|
||||
import io.ebean.meta.ServerMetrics;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
@@ -33,9 +34,9 @@ public class DtoQueryTest extends BaseTestCase {
|
||||
log.info(list.toString());
|
||||
assertThat(list).isNotEmpty();
|
||||
|
||||
BasicMetricVisitor basic = visitMetricsBasic();
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
|
||||
List<MetaQueryMetric> stats = basic.getDtoQueryMetrics();
|
||||
List<MetaQueryMetric> stats = metrics.getDtoQueryMetrics();
|
||||
for (MetaQueryMetric stat : stats) {
|
||||
long meanMicros = stat.getMean();
|
||||
assertThat(meanMicros).isLessThan(900_000);
|
||||
@@ -208,7 +209,7 @@ public class DtoQueryTest extends BaseTestCase {
|
||||
.setParameter("name", "rob")
|
||||
.findList();
|
||||
|
||||
BasicMetricVisitor metric2 = server().getMetaInfoManager().visitBasic();
|
||||
ServerMetrics metric2 = server().getMetaInfoManager().collectMetrics();
|
||||
|
||||
stats = metric2.getDtoQueryMetrics();
|
||||
assertThat(stats).hasSize(2);
|
||||
|
||||
@@ -2,8 +2,8 @@ package io.ebean;
|
||||
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaOrmQueryMetric;
|
||||
import io.ebean.meta.ServerMetrics;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Country;
|
||||
@@ -38,8 +38,8 @@ public class UpdateQueryTest extends BaseTestCase {
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("update o_customer set status=?, updtime=? where status = ? and id > ?");
|
||||
|
||||
BasicMetricVisitor basic = visitMetricsBasic();
|
||||
List<MetaOrmQueryMetric> ormQueryMetrics = basic.getOrmQueryMetrics();
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
List<MetaOrmQueryMetric> ormQueryMetrics = metrics.getOrmQueryMetrics();
|
||||
assertThat(ormQueryMetrics).hasSize(1);
|
||||
assertThat(ormQueryMetrics.get(0).getType()).isEqualTo(Customer.class);
|
||||
assertThat(ormQueryMetrics.get(0).getLabel()).isEqualTo("updateActive");
|
||||
@@ -68,8 +68,8 @@ public class UpdateQueryTest extends BaseTestCase {
|
||||
|
||||
assertThat(sql.get(0)).contains("update o_customer set status = status");
|
||||
|
||||
BasicMetricVisitor basic = visitMetricsBasic();
|
||||
List<MetaOrmQueryMetric> ormQueryMetrics = basic.getOrmQueryMetrics();
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
List<MetaOrmQueryMetric> ormQueryMetrics = metrics.getOrmQueryMetrics();
|
||||
assertThat(ormQueryMetrics).hasSize(1);
|
||||
assertThat(ormQueryMetrics.get(0).getType()).isEqualTo(Customer.class);
|
||||
assertThat(ormQueryMetrics.get(0).getLabel()).isEqualTo("updateAll");
|
||||
|
||||
@@ -8,8 +8,8 @@ import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.PersistBatch;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import io.ebean.meta.ServerMetrics;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
@@ -77,8 +77,8 @@ public class TestBatchInsertFlush extends BaseTestCase {
|
||||
transaction.end();
|
||||
}
|
||||
|
||||
BasicMetricVisitor basic = visitMetricsBasic();
|
||||
List<MetaTimedMetric> txnStats = basic.getTimedMetrics();
|
||||
ServerMetrics metrics = collectMetrics();
|
||||
List<MetaTimedMetric> txnStats = metrics.getTimedMetrics();
|
||||
for (MetaTimedMetric txnMetric : txnStats) {
|
||||
System.out.println(txnMetric);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package org.tests.query.finder;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaOrmQueryMetric;
|
||||
import io.ebean.meta.MetaQueryPlan;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import io.ebean.meta.QueryPlanRequest;
|
||||
import io.ebean.meta.ServerMetrics;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
@@ -153,16 +153,16 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
Customer.find.updateNames("Junk", 2000);
|
||||
Customer.find.byId(3);
|
||||
|
||||
BasicMetricVisitor basic = server().getMetaInfoManager().visitBasic();
|
||||
ServerMetrics metrics = server().getMetaInfoManager().collectMetrics();
|
||||
|
||||
List<MetaOrmQueryMetric> planStats = basic.getOrmQueryMetrics();
|
||||
List<MetaOrmQueryMetric> planStats = metrics.getOrmQueryMetrics();
|
||||
assertThat(planStats.size()).isGreaterThan(4);
|
||||
|
||||
for (MetaOrmQueryMetric planStat : planStats) {
|
||||
System.out.println(planStat);
|
||||
}
|
||||
|
||||
for (MetaTimedMetric txnTimed : basic.getTimedMetrics()) {
|
||||
for (MetaTimedMetric txnTimed : metrics.getTimedMetrics()) {
|
||||
System.out.println(txnTimed);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user