Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-2660 - Metrics asadmin command optional enabled & dynamic option #2706

Merged
merged 3 commits into from May 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -89,6 +89,10 @@ public class MetricsService implements EventListener {
ServiceLocator serviceLocator;

private MetricsServiceConfiguration metricsServiceConfiguration;

private Boolean metricsEnabled;

private Boolean metricsSecure;

private final Map<String, MetricRegistry> REGISTRIES = new ConcurrentHashMap<>();//stores registries of base, vendor, app1, app2, ... app(n) etc

Expand Down Expand Up @@ -153,11 +157,25 @@ private MBeanMetadataConfig getConfig() {
}

public Boolean isMetricsEnabled() {
return Boolean.valueOf(metricsServiceConfiguration.getEnabled());
if (metricsEnabled == null) {
metricsEnabled = Boolean.valueOf(metricsServiceConfiguration.getEnabled());
}
return metricsEnabled;
}

public void resetMetricsEnabledProperty() {
metricsEnabled = null;
}

public Boolean isMetricsSecure() {
return Boolean.valueOf(metricsServiceConfiguration.getSecure());
if (metricsSecure == null) {
metricsSecure = Boolean.valueOf(metricsServiceConfiguration.getSecure());
}
return metricsSecure;
}

public void resetMetricsSecureProperty() {
metricsSecure = null;
}

public Map<String, Metric> getMetricsAsMap(String registryName) throws NoSuchRegistryException {
Expand Down
Expand Up @@ -82,7 +82,7 @@
})
public class GetMetricsConfigurationCommand implements AdminCommand {

private final String OUTPUT_HEADERS[] = {"Enabled", "Secure"};
private final String OUTPUT_HEADERS[] = {"Enabled", "Secure", "Dynamic"};

@Inject
private Target targetUtil;
Expand All @@ -106,7 +106,8 @@ public void execute(AdminCommandContext adminCommandContext) {
ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
Object[] outputValues = {
metricsConfiguration.getEnabled(),
metricsConfiguration.getSecure()
metricsConfiguration.getSecure(),
metricsConfiguration.getDynamic()
};
columnFormatter.addRow(outputValues);

Expand All @@ -115,6 +116,7 @@ public void execute(AdminCommandContext adminCommandContext) {
Map<String, Object> extraPropertiesMap = new HashMap<>();
extraPropertiesMap.put("enabled", metricsConfiguration.getEnabled());
extraPropertiesMap.put("secure", metricsConfiguration.getSecure());
extraPropertiesMap.put("dynamic", metricsConfiguration.getDynamic());

Properties extraProperties = new Properties();
extraProperties.put("metricsConfiguration", extraPropertiesMap);
Expand Down
Expand Up @@ -70,5 +70,14 @@ public interface MetricsServiceConfiguration extends ConfigBeanProxy, ConfigExte
@Attribute(defaultValue = "false", dataType = Boolean.class)
String getSecure();
void setSecure(String value) throws PropertyVetoException;

/**
* Boolean value determining if the service is dynamic or not.
*
* @return
*/
@Attribute(defaultValue = "true", dataType = Boolean.class)
String getDynamic();
void setDynamic(String value) throws PropertyVetoException;

}
Expand Up @@ -40,6 +40,7 @@
package fish.payara.microprofile.metrics.admin;

import com.sun.enterprise.config.serverbeans.Config;
import fish.payara.microprofile.metrics.MetricsService;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.glassfish.api.Param;
Expand All @@ -58,6 +59,7 @@
import static org.glassfish.config.support.CommandTarget.STANDALONE_INSTANCE;
import org.glassfish.config.support.TargetType;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.internal.api.Globals;
import org.glassfish.internal.api.Target;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.ConfigSupport;
Expand Down Expand Up @@ -85,11 +87,14 @@ public class SetMetricsConfigurationCommand implements AdminCommand {
@Inject
private Target targetUtil;

@Param(name = "enabled", optional = false)
@Param(name = "enabled", optional = true)
private Boolean enabled;

@Param(name = "secureMetrics", optional = true, defaultValue = "false")
@Param(name = "secure", optional = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will reintroduce bug PAYARA-2661, please change the name of this param back

private Boolean secure;

@Param(name = "dynamic", optional = true)
private Boolean dynamic;

@Param(optional = true, defaultValue = "server-config")
private String target;
Expand All @@ -98,14 +103,31 @@ public class SetMetricsConfigurationCommand implements AdminCommand {
public void execute(AdminCommandContext adminCommandContext) {
Config targetConfig = targetUtil.getConfig(target);
MetricsServiceConfiguration metricsConfiguration = targetConfig.getExtensionByType(MetricsServiceConfiguration.class);

MetricsService metricsService = Globals.getDefaultBaseServiceLocator().getService(MetricsService.class);
try {
ConfigSupport.apply(metricsConfigurationProxy -> {
if (dynamic != null) {
metricsConfigurationProxy.setDynamic(String.valueOf(dynamic));
}
if (enabled != null) {
metricsConfigurationProxy.setEnabled(String.valueOf(enabled));
if (dynamic != null) {
if (dynamic) {
metricsService.resetMetricsEnabledProperty();
}
} else if (Boolean.valueOf(metricsConfiguration.getDynamic())) {
metricsService.resetMetricsEnabledProperty();
}
}
if (secure != null) {
metricsConfigurationProxy.setSecure(String.valueOf(secure));
if (dynamic != null) {
if (dynamic) {
metricsService.resetMetricsSecureProperty();
}
} else if (Boolean.valueOf(metricsConfiguration.getDynamic())) {
metricsService.resetMetricsSecureProperty();
}
}
return metricsConfigurationProxy;
}, metricsConfiguration);
Expand Down