Skip to content

Commit

Permalink
Still more central work
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Feb 3, 2016
1 parent 84e7546 commit e498a8c
Show file tree
Hide file tree
Showing 91 changed files with 1,849 additions and 1,114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ private static ImmutableMap<String, String> getGlowrootProperties(File baseDir)
if (propFile.exists()) {
Properties props = new Properties();
InputStream in = new FileInputStream(propFile);
props.load(in);
try {
props.load(in);
} finally {
in.close();
}
for (String key : props.stringPropertyNames()) {
String value = props.getProperty(key);
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
Expand All @@ -37,7 +36,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.glowroot.agent.config.GaugeConfig.MBeanAttribute;
import org.glowroot.agent.config.PropertyValue.PropertyType;
import org.glowroot.agent.plugin.api.config.ConfigListener;
import org.glowroot.agent.util.JavaVersion;
Expand All @@ -53,12 +51,6 @@ public class ConfigService {
private static final long GAUGE_COLLECTION_INTERVAL_MILLIS =
Long.getLong("glowroot.internal.gaugeCollectionIntervalMillis", 5000);

static {
SimpleModule module = new SimpleModule();
module.addAbstractTypeMapping(MBeanAttribute.class, ImmutableMBeanAttribute.class);
mapper.registerModule(module);
}

private final ConfigFile configFile;

private final ImmutableList<PluginDescriptor> pluginDescriptors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public abstract class GaugeConfig {

public abstract String mbeanObjectName();
public abstract ImmutableList<MBeanAttribute> mbeanAttributes();
public abstract ImmutableList<ImmutableMBeanAttribute> mbeanAttributes();

public AgentConfig.GaugeConfig toProto() {
AgentConfig.GaugeConfig.Builder builder = AgentConfig.GaugeConfig.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class ConfigRepositoryImpl implements ConfigRepository {

private static final Logger logger = LoggerFactory.getLogger(ConfigRepositoryImpl.class);

private static final String ALERTS_KEY = "alerts";

private final ConfigService configService;
private final PluginCache pluginCache;
private final File secretFile;
Expand Down Expand Up @@ -314,7 +316,7 @@ public void insertInstrumentationConfig(String serverId,
@Override
public void updateInstrumentationConfig(String serverId,
AgentConfig.InstrumentationConfig instrumentationConfig, String priorVersion)
throws IOException {
throws Exception {
synchronized (writeLock) {
List<InstrumentationConfig> configs =
Lists.newArrayList(configService.getInstrumentationConfigs());
Expand All @@ -327,13 +329,15 @@ public void updateInstrumentationConfig(String serverId,
break;
}
}
checkState(found, "Instrumentation config not found: %s", priorVersion);
if (!found) {
throw new OptimisticLockException();
}
configService.updateInstrumentationConfigs(configs);
}
}

@Override
public void deleteInstrumentationConfig(String serverId, String version) throws IOException {
public void deleteInstrumentationConfig(String serverId, String version) throws Exception {
synchronized (writeLock) {
List<InstrumentationConfig> configs =
Lists.newArrayList(configService.getInstrumentationConfigs());
Expand All @@ -346,7 +350,9 @@ public void deleteInstrumentationConfig(String serverId, String version) throws
break;
}
}
checkState(found, "Instrumentation config not found: %s", version);
if (!found) {
throw new OptimisticLockException();
}
configService.updateInstrumentationConfigs(configs);
}
}
Expand Down Expand Up @@ -384,13 +390,15 @@ public void updateGaugeConfig(String serverId, AgentConfig.GaugeConfig gaugeConf
throw new DuplicateMBeanObjectNameException();
}
}
checkState(found, "Gauge config not found: %s", priorVersion);
if (!found) {
throw new OptimisticLockException();
}
configService.updateGaugeConfigs(configs);
}
}

@Override
public void deleteGaugeConfig(String serverId, String version) throws IOException {
public void deleteGaugeConfig(String serverId, String version) throws Exception {
synchronized (writeLock) {
List<GaugeConfig> configs = Lists.newArrayList(configService.getGaugeConfigs());
boolean found = false;
Expand All @@ -402,7 +410,9 @@ public void deleteGaugeConfig(String serverId, String version) throws IOExceptio
break;
}
}
checkState(found, "Gauge config not found: %s", version);
if (!found) {
throw new OptimisticLockException();
}
configService.updateGaugeConfigs(configs);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@
*/
package org.glowroot.agent.fat.storage;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.google.common.collect.ImmutableList;
import org.checkerframework.checker.tainting.qual.Untainted;

import org.glowroot.agent.fat.storage.util.DataSource;
import org.glowroot.agent.fat.storage.util.DataSource.JdbcRowQuery;
import org.glowroot.agent.fat.storage.util.ImmutableColumn;
import org.glowroot.agent.fat.storage.util.Schemas.Column;
import org.glowroot.agent.fat.storage.util.Schemas.ColumnType;

import static com.google.common.base.Preconditions.checkNotNull;

class TraceAttributeNameDao {

private static final ImmutableList<Column> columns = ImmutableList.<Column>of(
ImmutableColumn.of("transaction_type", ColumnType.VARCHAR),
ImmutableColumn.of("trace_attribute_name", ColumnType.VARCHAR),
ImmutableColumn.of("last_capture_time", ColumnType.BIGINT));

Expand All @@ -39,19 +47,21 @@ class TraceAttributeNameDao {
dataSource.syncTable("trace_attribute_name", columns);
}

public List<String> readTraceAttributeNames() throws Exception {
return dataSource
.queryForStringList("select trace_attribute_name from trace_attribute_name");
public List<String> readTraceAttributeNames(String transactionType) throws Exception {
return dataSource.query(new TraceAttributeQuery(transactionType));
}

void updateLastCaptureTime(String traceAttributeName, long captureTime) throws Exception {
void updateLastCaptureTime(String transactionType, String traceAttributeName, long captureTime)
throws Exception {
synchronized (lock) {
int updateCount = dataSource.update("update trace_attribute_name"
+ " set last_capture_time = ? where trace_attribute_name = ?", captureTime,
+ " set last_capture_time = ? where transaction_type = ?"
+ " and trace_attribute_name = ?", captureTime, transactionType,
traceAttributeName);
if (updateCount == 0) {
dataSource.update("insert into trace_attribute_name (trace_attribute_name,"
+ " last_capture_time) values (?, ?)", traceAttributeName, captureTime);
dataSource.update("insert into trace_attribute_name (transaction_type,"
+ " trace_attribute_name, last_capture_time) values (?, ?, ?)",
transactionType, traceAttributeName, captureTime);
}
}
}
Expand All @@ -64,4 +74,29 @@ void deleteBefore(long captureTime) throws Exception {
dataSource.update("delete from trace_attribute_name where last_capture_time < ?",
captureTime);
}

private static class TraceAttributeQuery implements JdbcRowQuery<String> {

private final String transactionType;

private TraceAttributeQuery(String transactionType) {
this.transactionType = transactionType;
}

@Override
public @Untainted String getSql() {
return "select trace_attribute_name from trace_attribute_name where"
+ " transaction_type = ?";
}

@Override
public void bind(PreparedStatement preparedStatement) throws SQLException {
preparedStatement.setString(1, transactionType);
}

@Override
public String mapRow(ResultSet resultSet) throws SQLException {
return checkNotNull(resultSet.getString(1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,18 @@ public void collect(final String serverId, final Trace trace) throws Exception {
}
dataSource.batchUpdate(new TraceAttributeInsert(trace));
for (Trace.Attribute attribute : header.getAttributeList()) {
traceAttributeNameDao.updateLastCaptureTime(attribute.getName(),
header.getCaptureTime());
traceAttributeNameDao.updateLastCaptureTime(header.getTransactionType(),
attribute.getName(), header.getCaptureTime());
}
}
transactionTypeDao.updateLastCaptureTime(trace.getHeader().getTransactionType(),
trace.getHeader().getCaptureTime());
}

@Override
public List<String> readTraceAttributeNames(String serverRollup) throws Exception {
return traceAttributeNameDao.readTraceAttributeNames();
public List<String> readTraceAttributeNames(String serverRollup, String transactionType)
throws Exception {
return traceAttributeNameDao.readTraceAttributeNames(transactionType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.glowroot.agent.config.ConfigService;
import org.glowroot.agent.config.GaugeConfig;
import org.glowroot.agent.config.GaugeConfig.MBeanAttribute;
import org.glowroot.agent.config.ImmutableMBeanAttribute;
import org.glowroot.agent.util.LazyPlatformMBeanServer;
import org.glowroot.agent.util.LazyPlatformMBeanServer.InitListener;
import org.glowroot.agent.util.Reflections;
Expand Down Expand Up @@ -173,7 +174,7 @@ List<GaugeValue> collectGaugeValues(GaugeConfig gaugeConfig) throws InterruptedE

@RequiresNonNull("priorRawCounterValues")
private List<GaugeValue> collectGaugeValues(ObjectName objectName,
List<MBeanAttribute> mbeanAttributes, String mbeanObjectName) {
List<ImmutableMBeanAttribute> mbeanAttributes, String mbeanObjectName) {
long captureTime = clock.currentTimeMillis();
List<GaugeValue> gaugeValues = Lists.newArrayList();
for (MBeanAttribute mbeanAttribute : mbeanAttributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public LiveJvmServiceImpl(LazyPlatformMBeanServer lazyPlatformMBeanServer,
this.threadAllocatedBytesAvailability = threadAllocatedBytesAvailability;
}

@Override
public boolean isAvailable(String serverId) {
return true;
}

@Override
public ThreadDump getThreadDump(String serverId) {
return threadDumpService.getThreadDump();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

class AsyncWrapperCall {

// re-using single executor to prevent spawning tons of threads
private static final ExecutorService executor = Executors.newCachedThreadPool();

private final int maxTimeMillis;
private final int maxTraceEntryMessageLength;

Expand All @@ -32,7 +35,6 @@ class AsyncWrapperCall {
}

void execute() throws InterruptedException, ExecutionException {
ExecutorService executor = Executors.newCachedThreadPool();
Future<Void> future1 = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -85,5 +85,6 @@ private void createGauge() {
gaugePage.getMBeanAttributeCheckBox("LoadedClassCount").click();
gaugePage.getMBeanAttributeCheckBox("TotalLoadedClassCount").click();
gaugePage.getAddButton().click();
driver.findElement(linkText("Return to list")).click();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@
import org.glowroot.agent.webdriver.tests.config.InstrumentationConfigPage;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.By.linkText;
import static org.openqa.selenium.By.partialLinkText;
import static org.openqa.selenium.By.xpath;

Expand Down Expand Up @@ -169,6 +170,7 @@ private void createTransactionInstrumentation() {
configPage.getTransactionSlowThresholdMillisTextField().clear();
configPage.getTransactionSlowThresholdMillisTextField().sendKeys("123");
configPage.clickAddButton();
driver.findElement(linkText("Return to list")).click();
}

private void createTraceEntryInstrumentation() {
Expand All @@ -192,6 +194,7 @@ private void createTraceEntryInstrumentation() {
configPage.getTimerNameTextField().clear();
configPage.getTimerNameTextField().sendKeys("a timer");
configPage.clickAddButton();
driver.findElement(linkText("Return to list")).click();
}

private void createTimerInstrumentation() {
Expand All @@ -206,5 +209,6 @@ private void createTimerInstrumentation() {
configPage.getTimerNameTextField().clear();
configPage.getTimerNameTextField().sendKeys("a timer");
configPage.clickAddButton();
driver.findElement(linkText("Return to list")).click();
}
}
4 changes: 4 additions & 0 deletions central/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<!-- immutables is only needed at compile time -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
</dependency>
<dependency>
<groupId>${checker.qual.group.id}</groupId>
<artifactId>${checker.qual.artifact.id}</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.glowroot.common.live.LiveJvmService.AgentNotConnectedException;
import org.glowroot.wire.api.model.AgentConfigOuterClass.AgentConfig;
import org.glowroot.wire.api.model.DownstreamServiceGrpc.DownstreamService;
import org.glowroot.wire.api.model.DownstreamServiceOuterClass.AgentConfigUpdateRequest;
Expand Down Expand Up @@ -81,6 +82,10 @@ public void updateAgentConfig(String serverId, AgentConfig agentConfig)
connectedAgent.updateAgentConfig(agentConfig);
}

boolean isAvailable(String serverId) {
return connectedAgents.containsKey(serverId);
}

ThreadDump threadDump(String serverId) throws Exception {
ConnectedAgent connectedAgent = connectedAgents.get(serverId);
if (connectedAgent == null) {
Expand Down Expand Up @@ -414,9 +419,6 @@ private static class ResponseHolder {
private final Exchanger<ClientResponse> response = new Exchanger<>();
}

@SuppressWarnings("serial")
public static class AgentNotConnectedException extends Exception {}

@SuppressWarnings("serial")
public static class AgentException extends Exception {}

Expand Down

0 comments on commit e498a8c

Please sign in to comment.