Skip to content

Commit

Permalink
Move web config to properties file for central
Browse files Browse the repository at this point in the history
Closes #208
  • Loading branch information
trask committed May 9, 2017
1 parent b7671f9 commit e4a5da5
Show file tree
Hide file tree
Showing 19 changed files with 630 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
import org.glowroot.agent.config.UserRecordingConfig;
import org.glowroot.common.config.AgentRollupConfig;
import org.glowroot.common.config.CentralStorageConfig;
import org.glowroot.common.config.CentralWebConfig;
import org.glowroot.common.config.FatStorageConfig;
import org.glowroot.common.config.FatWebConfig;
import org.glowroot.common.config.ImmutableFatStorageConfig;
import org.glowroot.common.config.ImmutableFatWebConfig;
import org.glowroot.common.config.ImmutableLdapConfig;
import org.glowroot.common.config.ImmutableRoleConfig;
import org.glowroot.common.config.ImmutableSmtpConfig;
import org.glowroot.common.config.ImmutableUserConfig;
import org.glowroot.common.config.ImmutableWebConfig;
import org.glowroot.common.config.LdapConfig;
import org.glowroot.common.config.RoleConfig;
import org.glowroot.common.config.SmtpConfig;
Expand Down Expand Up @@ -82,7 +84,7 @@ class ConfigRepositoryImpl implements ConfigRepository {

private volatile ImmutableList<UserConfig> userConfigs;
private volatile ImmutableList<RoleConfig> roleConfigs;
private volatile WebConfig webConfig;
private volatile FatWebConfig webConfig;
private volatile FatStorageConfig storageConfig;
private volatile SmtpConfig smtpConfig;
private volatile LdapConfig ldapConfig;
Expand Down Expand Up @@ -135,9 +137,9 @@ private ConfigRepositoryImpl(File glowrootDir, ConfigService configService,
"agent:config", "admin")
.build());
}
WebConfig webConfig = configService.getAdminConfig(WEB_KEY, ImmutableWebConfig.class);
FatWebConfig webConfig = configService.getAdminConfig(WEB_KEY, ImmutableFatWebConfig.class);
if (webConfig == null) {
this.webConfig = ImmutableWebConfig.builder().build();
this.webConfig = ImmutableFatWebConfig.builder().build();
} else {
this.webConfig = webConfig;
}
Expand Down Expand Up @@ -345,9 +347,24 @@ public List<RoleConfig> getRoleConfigs() {

@Override
public WebConfig getWebConfig() {
return getFatWebConfig();
}

@Override
public FatWebConfig getFatWebConfig() {
return webConfig;
}

@Override
public CentralWebConfig getCentralWebConfig() {
throw new UnsupportedOperationException();
}

@Override
public StorageConfig getStorageConfig() {
return getFatStorageConfig();
}

@Override
public FatStorageConfig getFatStorageConfig() {
return storageConfig;
Expand Down Expand Up @@ -803,14 +820,19 @@ public void deleteRoleConfig(String name) throws Exception {
}

@Override
public void updateWebConfig(WebConfig config, String priorVersion) throws Exception {
public void updateFatWebConfig(FatWebConfig config, String priorVersion) throws Exception {
synchronized (writeLock) {
checkVersionsEqual(webConfig.version(), priorVersion);
configService.updateAdminConfig(WEB_KEY, config);
webConfig = config;
}
}

@Override
public void updateCentralWebConfig(CentralWebConfig config, String priorVersion) {
throw new UnsupportedOperationException();
}

@Override
public void updateFatStorageConfig(FatStorageConfig config, String priorVersion)
throws Exception {
Expand Down Expand Up @@ -844,11 +866,6 @@ public void updateLdapConfig(LdapConfig config, String priorVersion) throws Exce
}
}

@Override
public StorageConfig getStorageConfig() {
return getFatStorageConfig();
}

@Override
public long getGaugeCollectionIntervalMillis() {
return configService.getGaugeCollectionIntervalMillis();
Expand Down Expand Up @@ -892,7 +909,7 @@ public void resetAdminConfig() throws IOException {
.addPermissions("agent:transaction", "agent:error", "agent:jvm",
"agent:config:view", "agent:config:edit", "admin")
.build());
webConfig = ImmutableWebConfig.builder().build();
webConfig = ImmutableFatWebConfig.builder().build();
storageConfig = ImmutableFatStorageConfig.builder().build();
smtpConfig = ImmutableSmtpConfig.builder().build();
ldapConfig = ImmutableLdapConfig.builder().build();
Expand Down
8 changes: 7 additions & 1 deletion central/dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/webapp/META-INF</directory>
<directory>src/main/conf</directory>
<includes>
<include>glowroot-central.properties</include>
</includes>
<outputDirectory></outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/webapp/META-INF</directory>
<includes>
<include>LICENSE</include>
<include>NOTICE</include>
</includes>
Expand Down
36 changes: 36 additions & 0 deletions central/src/main/conf/glowroot-central.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# default is cassandra.contactPoints=127.0.0.1
cassandra.contactPoints=

# default is to connect without credentials
cassandra.username=

# default is to connect without credentials
cassandra.password=

# default is cassandra.keyspace=glowroot
cassandra.keyspace=

# default is grpc.bindAddress=0.0.0.0
grpc.bindAddress=

# default is grpc.port=8181
grpc.port=

# default is ui.bindAddress=0.0.0.0
ui.bindAddress=

# default is ui.port=4000
ui.port=

# default is to serve the UI over http
# set this to "true" to serve the UI over https
# the SSL certificate and private key to be used must be placed in the same directory as this
# properties file, with filenames "certificate.pem" and "private.pem", and the private key must not
# have a passphrase.
# (for example, a self signed certificate can be generated at the command line using
# "openssl req -new -x509 -nodes -days 365 -out certificate.pem -keyout private.pem")
ui.https=

# default is ui.contextPath=/
# this only needs to be changed if reverse proxying the UI behind a non-root context path
ui.contextPath=
63 changes: 36 additions & 27 deletions central/src/main/java/org/glowroot/central/CentralModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@
import org.glowroot.central.repo.UserDao;
import org.glowroot.central.util.ClusterManager;
import org.glowroot.central.util.Sessions;
import org.glowroot.common.config.ImmutableWebConfig;
import org.glowroot.common.config.WebConfig;
import org.glowroot.common.live.LiveAggregateRepository.LiveAggregateRepositoryNop;
import org.glowroot.common.repo.RepoAdmin;
import org.glowroot.common.repo.util.AlertingService;
Expand Down Expand Up @@ -155,13 +153,16 @@ class CentralModule {

KeyspaceMetadata keyspace =
cluster.getMetadata().getKeyspace(centralConfig.cassandraKeyspace());
SchemaUpgrade schemaUpgrade = new SchemaUpgrade(session, keyspace);
SchemaUpgrade schemaUpgrade = new SchemaUpgrade(session, keyspace, config != null);
Integer initialSchemaVersion = schemaUpgrade.getInitialSchemaVersion();
if (initialSchemaVersion == null) {
startupLogger.info("creating cassandra schema...");
} else {
schemaUpgrade.upgrade();
}
if (schemaUpgrade.reloadCentralConfiguration()) {
centralConfig = getCentralConfiguration(centralDir);
}
CentralConfigDao centralConfigDao = new CentralConfigDao(session, clusterManager);
AgentDao agentDao = new AgentDao(session, clusterManager);
ConfigDao configDao = new ConfigDao(session, clusterManager);
Expand All @@ -174,26 +175,6 @@ class CentralModule {
schemaUpgrade.updateToMoreRecentCassandraOptions(
configRepository.getCentralStorageConfig());
}

if (config == null) {
String uiBindAddressOverride = centralConfig.uiBindAddressOverride();
Integer uiPortOverride = centralConfig.uiPortOverride();
if (uiBindAddressOverride != null || uiPortOverride != null) {
// TODO supplying ui.bindAddress in glowroot-central.properties should make the
// bind address non-editable in admin UI, and supplying ui.port in
// glowroot-central.properties should make the port non-editable in admin UI
WebConfig webConfig = configRepository.getWebConfig();
ImmutableWebConfig updatedWebConfig = ImmutableWebConfig.copyOf(webConfig);
if (uiBindAddressOverride != null) {
updatedWebConfig = updatedWebConfig.withBindAddress(uiBindAddressOverride);
}
if (uiPortOverride != null) {
updatedWebConfig = updatedWebConfig.withPort(uiPortOverride);
}
configRepository.updateWebConfig(updatedWebConfig, webConfig.version());
}
}

TransactionTypeDao transactionTypeDao =
new TransactionTypeDao(session, configRepository, clusterManager);
FullQueryTextDao fullQueryTextDao = new FullQueryTextDao(session, configRepository);
Expand Down Expand Up @@ -242,6 +223,10 @@ public void onChange(String agentId) throws Exception {
.central(true)
.servlet(config != null)
.offline(false)
.bindAddress(centralConfig.uiBindAddress())
.port(centralConfig.uiPort())
.https(centralConfig.uiHttps())
.contextPath(centralConfig.uiContextPath())
.certificateDir(centralDir)
.logDir(centralDir)
.clock(clock)
Expand Down Expand Up @@ -415,11 +400,19 @@ private static CentralConfiguration getCentralConfiguration(File centralDir)
}
String uiBindAddress = props.getProperty("ui.bindAddress");
if (!Strings.isNullOrEmpty(uiBindAddress)) {
builder.uiBindAddressOverride(uiBindAddress);
builder.uiBindAddress(uiBindAddress);
}
String uiPortText = props.getProperty("ui.port");
if (!Strings.isNullOrEmpty(uiPortText)) {
builder.uiPortOverride(Integer.parseInt(uiPortText));
builder.uiPort(Integer.parseInt(uiPortText));
}
String uiHttpsText = props.getProperty("ui.https");
if (!Strings.isNullOrEmpty(uiHttpsText)) {
builder.uiHttps(Boolean.parseBoolean(uiHttpsText));
}
String uiContextPath = props.getProperty("ui.contextPath");
if (!Strings.isNullOrEmpty(uiContextPath)) {
builder.uiContextPath(uiContextPath);
}
for (String propName : props.stringPropertyNames()) {
if (propName.startsWith("jgroups.")) {
Expand Down Expand Up @@ -568,9 +561,25 @@ int grpcPort() {
return 8181;
}

abstract @Nullable String uiBindAddressOverride();
@Value.Default
String uiBindAddress() {
return "0.0.0.0";
}

@Value.Default
int uiPort() {
return 4000;
}

@Value.Default
boolean uiHttps() {
return false;
}

abstract @Nullable Integer uiPortOverride();
@Value.Default
String uiContextPath() {
return "/";
}

abstract Map<String, String> jgroupsProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
import org.glowroot.central.repo.ConfigDao.AgentConfigUpdater;
import org.glowroot.common.config.AgentRollupConfig;
import org.glowroot.common.config.CentralStorageConfig;
import org.glowroot.common.config.CentralWebConfig;
import org.glowroot.common.config.FatStorageConfig;
import org.glowroot.common.config.FatWebConfig;
import org.glowroot.common.config.ImmutableCentralStorageConfig;
import org.glowroot.common.config.ImmutableCentralWebConfig;
import org.glowroot.common.config.ImmutableFatStorageConfig;
import org.glowroot.common.config.ImmutableLdapConfig;
import org.glowroot.common.config.ImmutableSmtpConfig;
import org.glowroot.common.config.ImmutableWebConfig;
import org.glowroot.common.config.LdapConfig;
import org.glowroot.common.config.RoleConfig;
import org.glowroot.common.config.SmtpConfig;
Expand Down Expand Up @@ -93,7 +95,7 @@ public ConfigRepositoryImpl(AgentDao agentDao, ConfigDao configDao,
rollupConfigs = ImmutableList.copyOf(RollupConfig.buildRollupConfigs());
secretKey = new LazySecretKey(new File("secret"));

centralConfigDao.addKeyType(WEB_KEY, ImmutableWebConfig.class);
centralConfigDao.addKeyType(WEB_KEY, ImmutableCentralWebConfig.class);
centralConfigDao.addKeyType(STORAGE_KEY, ImmutableCentralStorageConfig.class);
centralConfigDao.addKeyType(SMTP_KEY, ImmutableSmtpConfig.class);
centralConfigDao.addKeyType(LDAP_KEY, ImmutableLdapConfig.class);
Expand Down Expand Up @@ -312,15 +314,28 @@ public List<RoleConfig> getRoleConfigs() throws Exception {

@Override
public WebConfig getWebConfig() throws Exception {
WebConfig config = (WebConfig) centralConfigDao.read(WEB_KEY);
return getCentralWebConfig();
}

@Override
public FatWebConfig getFatWebConfig() throws Exception {
throw new UnsupportedOperationException();
}

@Override
public CentralWebConfig getCentralWebConfig() throws Exception {
CentralWebConfig config = (CentralWebConfig) centralConfigDao.read(WEB_KEY);
if (config == null) {
return ImmutableWebConfig.builder()
.bindAddress("0.0.0.0")
.build();
return ImmutableCentralWebConfig.builder().build();
}
return config;
}

@Override
public StorageConfig getStorageConfig() throws Exception {
return getCentralStorageConfig();
}

@Override
public FatStorageConfig getFatStorageConfig() {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -922,7 +937,13 @@ public void deleteRoleConfig(String name) throws Exception {
}

@Override
public void updateWebConfig(WebConfig config, String priorVersion) throws Exception {
public void updateFatWebConfig(FatWebConfig config, String priorVersion) throws Exception {
throw new UnsupportedOperationException();
}

@Override
public void updateCentralWebConfig(CentralWebConfig config, String priorVersion)
throws Exception {
centralConfigDao.write(WEB_KEY, config, priorVersion);
}

Expand All @@ -947,11 +968,6 @@ public void updateLdapConfig(LdapConfig config, String priorVersion) throws Exce
centralConfigDao.write(LDAP_KEY, config, priorVersion);
}

@Override
public StorageConfig getStorageConfig() throws Exception {
return getCentralStorageConfig();
}

@Override
public long getGaugeCollectionIntervalMillis() {
return GAUGE_COLLECTION_INTERVAL_MILLIS;
Expand Down

0 comments on commit e4a5da5

Please sign in to comment.