From ee6b353152e89abb6c6ca1bf845e5cda2182c85f Mon Sep 17 00:00:00 2001 From: Mero Rai Date: Fri, 9 Oct 2020 15:32:24 +0100 Subject: [PATCH] Revert "Merge pull request #4918 from MeroRai/FISH-334" This reverts commit b3557409f892c291482a3df0a77ccbb756d8aec2, reversing changes made to 796797bd97c4fba9c39e6b475368ffe34a11980b. --- .../admingui/healthcheck/Strings.properties | 10 - ...icroProfileMetricsCheckerConfiguration.jsf | 168 ------------ .../checkers/monitoredMetricsTable.inc | 113 -------- .../healthcheck/healthcheckConfigTabs.inc | 11 +- appserver/packager/healthcheck/pom.xml | 7 +- .../healthcheck-metrics/pom.xml | 68 ----- ...kMicroProfileMetricstExecutionOptions.java | 72 ----- .../metrics/MicroProfileMetricsCheck.java | 135 --------- .../metrics/StringWriterProxy.java | 83 ------ .../microprofile/metrics/MetricsService.java | 8 - .../writer/FilteredMetricsExporter.java | 93 ------- .../metrics/writer/OpenMetricsExporter.java | 62 ++--- appserver/payara-appserver-modules/pom.xml | 3 +- ...etHealthCheckServiceConfigurationTest.java | 10 +- .../AbstractAttributeBagResource.java | 256 ------------------ .../MonitoredAttributeBagResource.java | 201 ++++++++++++-- .../MonitoredMetricAttributeBagResource.java | 124 --------- .../admin/rest/generator/ASMClassWriter.java | 5 +- .../generator/ResourcesGeneratorBase.java | 4 +- .../healthcheck/HealthCheckConstants.java | 1 - .../admin/GetHealthCheckConfiguration.java | 73 +---- .../SetHealthCheckServiceConfiguration.java | 135 +-------- .../configuration/CheckerType.java | 5 +- .../MicroProfileMetricsChecker.java | 63 ----- .../configuration/MonitoredMetric.java | 72 ----- .../preliminary/LocalStrings.properties | 5 +- 26 files changed, 236 insertions(+), 1551 deletions(-) delete mode 100644 appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/microProfileMetricsCheckerConfiguration.jsf delete mode 100644 appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/monitoredMetricsTable.inc delete mode 100644 appserver/payara-appserver-modules/healthcheck-metrics/pom.xml delete mode 100644 appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/HealthCheckMicroProfileMetricstExecutionOptions.java delete mode 100644 appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/MicroProfileMetricsCheck.java delete mode 100644 appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/StringWriterProxy.java delete mode 100644 appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/FilteredMetricsExporter.java delete mode 100644 nucleus/admin/rest/rest-service/src/main/java/fish/payara/admin/rest/resources/AbstractAttributeBagResource.java delete mode 100644 nucleus/admin/rest/rest-service/src/main/java/fish/payara/admin/rest/resources/MonitoredMetricAttributeBagResource.java delete mode 100644 nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MicroProfileMetricsChecker.java delete mode 100644 nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MonitoredMetric.java diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties index b4347b85cf4..1582e919826 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties @@ -72,8 +72,6 @@ healthcheck.configuration.garbageCollectorCheckerTabTitle=Garbage Collector healthcheck.configuration.garbageCollectorCheckerTabTitleToolTip=Configures the Garbage Collector HealthCheck. healthcheck.configuration.microprofileHealthcheckCheckerTabTitle=MicroProfile Healthcheck Checker healthcheck.configuration.microprofileHealthcheckCheckerTabTitleToolTip=Configures the MicroProfile Healthcheck HealthCheck -healthcheck.configuration.microprofileMetricsCheckerTabTitle=MicroProfile Metrics Checker -healthcheck.configuration.microprofileMetricsCheckerTabTitleToolTip=Configures the MicroProfile Metrics HealthCheck healthcheck.checker.configuration.enabledLabel=Enabled healthcheck.checker.configuration.enabledLabelHelpText=Enables or Disables the checker. @@ -130,14 +128,6 @@ healthcheck.checker.configuration.microprofileHealthcheckChecker.pageTitleHelpTe healthcheck.checker.configuration.microprofileHealthcheckChecker.timeoutLabel=Timeout healthcheck.checker.configuration.microprofileHealthcheckChecker.timeoutLabelHelpText=Time in milliseconds before an instance is considered nonresponsive -healthcheck.checker.configuration.microprofileMetricsChecker.pageTitle=Microprofile Metrics Checker -healthcheck.checker.configuration.microprofileMetricsChecker.pageTitleHelpText=Provides a way to monitor and log the values of metrics exposed by MicroProfile Metrics. - -healthcheck.checker.configuration.microprofileMetricsChecker.monitored.metrics.table.name=Monitored Metrics -healthcheck.checker.configuration.microprofileMetricsChecker.monitored.metrics.metric.name=Metric Name -healthcheck.checker.configuration.microprofileMetricsChecker.monitored.metrics.add.metric=Add Metric -healthcheck.checker.configuration.microprofileMetricsChecker.monitored.metrics.del.metrics=Delete Metrics - healthcheck.checker.configuration.stuckThreads.pageTitle=Stuck Threads healthcheck.checker.configuration.stuckThreads.pageTitleHelpText=Configuration options for the Stuck Threads HealthCheck. healthcheck.checker.configuration.stuckThreads.timeThresholdLabel=Threshold time diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/microProfileMetricsCheckerConfiguration.jsf b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/microProfileMetricsCheckerConfiguration.jsf deleted file mode 100644 index 40152d46b19..00000000000 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/microProfileMetricsCheckerConfiguration.jsf +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - - - $page{configName} default="server-config"); - urlencode(value="#{pageSession.configName}" encoding="UTF-8" result="#{pageSession.encodedConfigName}"); - setPageSessionAttribute(key="parentUrl", value="#{sessionScope.REST_URL}/configs/config/#{pageSession.encodedConfigName}"); - setPageSessionAttribute(key="HEALTHCHECK_CONFIG_URL", value="#{pageSession.parentUrl}/health-check-service-configuration"); - setPageSessionAttribute(key="MICROPROFILE_METRICS_CHECKER_URL", value="#{pageSession.HEALTHCHECK_CONFIG_URL}/micro-profile-metrics-checker"); - - gf.restRequest(endpoint="#{sessionScope.HEALTHCHECK_CONFIG_URL}/get-healthcheck-configuration?target=#{pageSession.encodedConfigName}" - method="GET" result="#{requestScope.resp}"); - setPageSessionAttribute(key="valueMap", - value="#{requestScope.resp.data.subReports.get(5).extraProperties.microProfileMetrics}"); - mapPut(map="#{pageSession.valueMap}" key="target" value="#{pageSession.encodedConfigName}"); - - setPageSessionAttribute(key="convertToFalseList", value={"enabled", "dynamic", "addToMicroProfileHealth"}); - if (#{pageSession.valueMap['enabled']}=true) { - setPageSessionAttribute(key="enabledSelected", value="true"); - } - - if (#{pageSession.valueMap['addToMicroProfileHealth']}=true) { - setPageSessionAttribute(key="addToMicroProfileHealthSelected", value="true"); - } - - setPageSessionAttribute(key="metricsMap", - value="#{requestScope.resp.data.subReports.get(6).extraProperties.monitoredMetrics}"); - - if ("!(#{pageSession.metricsMap}=#{null})") { - urlencode(value="#{pageSession.valueMap['checkerName']}" encoding="UTF-8" result="#{pageSession.encodedCheckerName}"); - gf.restRequest(endpoint="#{pageSession.MICROPROFILE_METRICS_CHECKER_URL}/#{pageSession.encodedCheckerName}/monitored-metric.json" - method="GET" result="#{requestScope.propTable}") - setPageSessionAttribute(key="tableList" value="#{requestScope.propTable.data.extraProperties.monitoredMetrics}"); - } - - if ("(#{pageSession.metricsMap}=#{null})") { - createList(size="0", result="#{pageSession.tableList}"); - } - - setPageSessionAttribute(key="dynamic", value="true"); - setPageSessionAttribute(key="hasPropertyTable" value="#{true}" ); - /> - - - -#include "/common/shared/alertMsg_1.inc" -#include "/healthcheck/healthcheck/healthcheckConfigTabs.inc - - - - - - - - - - -#include "/common/shared/configNameSection.inc" - - - - - - - - - - - - - - - - - - - - - -#include "/healthcheck/checkers/monitoredMetricsTable.inc" - - - \ No newline at end of file diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/monitoredMetricsTable.inc b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/monitoredMetricsTable.inc deleted file mode 100644 index 59737c22deb..00000000000 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/monitoredMetricsTable.inc +++ /dev/null @@ -1,113 +0,0 @@ - - - - $page{tableId}); - /> - - - - $page{topActionGroup}); - /> - - $attribute{tableRowGroup}); - addRowToTable(TableRowGroup="$attribute{tableRowGroup}", NameList={"metricName", "description"}); - /> - - - $attribute{trg}); - getSelectedTableRowKeys(tableRowGroup="${trg}" rowKeys=>$attribute{rowKeys}); - deleteTableRows(tableRowGroup="${trg}" rowKeys="${rowKeys}"); - commitTableRowGroup(tableRowGroup="${trg}"); - /> - - - - - - // Ensure all required fields exist - foreach (var="item" list="#{pageSession.tableList}") { - if ("!(#{item.metricName}=#{null})") { - if ("#{item.description}=#{null}") { - mapPut(map="#{item}" key="description" value=""); - } - } - } - - // Add extra table properties... - createList(size="0", result="#{pageSession.tableList2}"); - foreach(var="row" list="#{pageSession.tableList}") { - selectiveEncode(value="#{row.metricName}" result="#{requestScope.tlEncMetricName}"); - gf.createAttributeMap( - keys={"selected", "encodedName", "description"}, - values={"$boolean{false}", "$attribute{tlEncMetricName}", ""}, - map="#{requestScope.tlMap}"); - listAdd(list="#{pageSession.tableList2}", value="#{requestScope.tlMap}"); - } - - - getClientId(component="$this{component}" clientId=>$page{propertyTableRowGroupId}); - - - - - - - - - - - "
-
-
\ No newline at end of file diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc index 71d4f760c93..8dd496650f3 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc @@ -1,6 +1,6 @@ - - 4.0.0 - - fish.payara.server.internal.payara-appserver-modules - payara-appserver-modules - 5.2020.5 - - healthcheck-metrics - glassfish-jar - Healthcheck Metrics - Healthcheck MicroProfile Metrics - - - - fish.payara.server.internal.payara-modules - healthcheck-core - ${project.version} - - - fish.payara.server.internal.payara-appserver-modules - microprofile-metrics - ${project.version} - - - \ No newline at end of file diff --git a/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/HealthCheckMicroProfileMetricstExecutionOptions.java b/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/HealthCheckMicroProfileMetricstExecutionOptions.java deleted file mode 100644 index 00d2f5b25c1..00000000000 --- a/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/HealthCheckMicroProfileMetricstExecutionOptions.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) [2020] Payara Foundation and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://github.com/payara/Payara/blob/master/LICENSE.txt - * See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * The Payara Foundation designates this particular file as subject to the "Classpath" - * exception as provided by the Payara Foundation in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ -package fish.payara.healthcheck.microprofile.metrics; - -import fish.payara.nucleus.healthcheck.HealthCheckExecutionOptions; -import java.util.List; -import java.util.concurrent.TimeUnit; -import fish.payara.nucleus.healthcheck.configuration.MonitoredMetric; - -/** - * Execution Options for the Microprofile Metrics checker. - * - * @author Susan Rai - */ -public class HealthCheckMicroProfileMetricstExecutionOptions extends HealthCheckExecutionOptions { - - private List monitoredMetrics; - - public HealthCheckMicroProfileMetricstExecutionOptions(boolean enabled, long time, TimeUnit unit, boolean addToMicroProfileHealth, - List monitoredMetrics) { - super(enabled, time, unit, addToMicroProfileHealth); - this.monitoredMetrics = monitoredMetrics; - } - - public List getMonitoredMetrics() { - return monitoredMetrics; - } - - public void setMonitoredMetrics(List monitoredMetrics) { - this.monitoredMetrics = monitoredMetrics; - } -} diff --git a/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/MicroProfileMetricsCheck.java b/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/MicroProfileMetricsCheck.java deleted file mode 100644 index 5555a930d4f..00000000000 --- a/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/MicroProfileMetricsCheck.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) [2020] Payara Foundation and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://github.com/payara/Payara/blob/master/LICENSE.txt - * See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * The Payara Foundation designates this particular file as subject to the "Classpath" - * exception as provided by the Payara Foundation in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ -package fish.payara.healthcheck.microprofile.metrics; - -import static fish.payara.notification.healthcheck.HealthCheckResultStatus.CRITICAL; -import static fish.payara.notification.healthcheck.HealthCheckResultStatus.GOOD; -import static fish.payara.notification.healthcheck.HealthCheckResultStatus.WARNING; - -import java.io.IOException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; - -import org.glassfish.api.StartupRunLevel; -import org.glassfish.hk2.runlevel.RunLevel; -import org.jvnet.hk2.annotations.Service; - -import fish.payara.microprofile.metrics.MetricsService; -import fish.payara.microprofile.metrics.writer.FilteredMetricsExporter; -import fish.payara.microprofile.metrics.writer.MetricsWriter; -import fish.payara.microprofile.metrics.writer.MetricsWriterImpl; -import fish.payara.notification.healthcheck.HealthCheckResultEntry; -import fish.payara.nucleus.healthcheck.HealthCheckResult; -import fish.payara.nucleus.healthcheck.configuration.MicroProfileMetricsChecker; -import fish.payara.nucleus.healthcheck.configuration.MonitoredMetric; -import fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck; - -@Service(name = "healthcheck-mpmetrics") -@RunLevel(StartupRunLevel.VAL) -public class MicroProfileMetricsCheck - extends BaseHealthCheck { - - @Inject - private MetricsService metricsService; - - private StringWriterProxy buffer; - private MetricsWriter writer; - - @PostConstruct - public void postConstruct() { - postConstruct(this, MicroProfileMetricsChecker.class); - } - - @Override - public synchronized HealthCheckMicroProfileMetricstExecutionOptions constructOptions(MicroProfileMetricsChecker checker) { - Set metricNames = new HashSet<>(); - for (MonitoredMetric metric : checker.getMonitoredMetrics()) { - metricNames.add(metric.getMetricName()); - } - this.buffer = new StringWriterProxy(); - this.writer = new MetricsWriterImpl(new FilteredMetricsExporter(buffer, metricNames), - metricsService::getAllRegistryNames, metricsService::getRegistry); - - return new HealthCheckMicroProfileMetricstExecutionOptions(Boolean.valueOf(checker.getEnabled()), - Long.parseLong(checker.getTime()), asTimeUnit(checker.getUnit()), - Boolean.valueOf(checker.getAddToMicroProfileHealth()), checker.getMonitoredMetrics()); - } - - @Override - protected String getDescription() { - return "healthcheck.description.MPmetrics"; - } - - @Override - protected HealthCheckResult doCheckInternal() { - List monitoredMetrics = options.getMonitoredMetrics(); - HealthCheckResult result = new HealthCheckResult(); - - try { - if (monitoredMetrics != null && !monitoredMetrics.isEmpty()) { - final String data = write(); - result.add(new HealthCheckResultEntry(data.isEmpty() ? WARNING : GOOD, - data.isEmpty() ? "The metrics you have added for monitoring doesn't exist" - : data)); - } else { - result.add(new HealthCheckResultEntry(CRITICAL, "No metric has been added for monitoring.")); - } - } catch (IOException ex) { - result.add(new HealthCheckResultEntry(CRITICAL, "Failed to write metrics to stream.")); - } - return result; - } - - private synchronized String write() throws IOException { - writer.write(); - // Remove any trailing whitespace or commas - final String result = buffer.toString().trim().replaceAll(",$", ""); - this.buffer.clear(); - return result; - } - -} diff --git a/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/StringWriterProxy.java b/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/StringWriterProxy.java deleted file mode 100644 index 934dd01ed52..00000000000 --- a/appserver/payara-appserver-modules/healthcheck-metrics/src/main/java/fish/payara/healthcheck/microprofile/metrics/StringWriterProxy.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) [2020] Payara Foundation and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://github.com/payara/Payara/blob/master/LICENSE.txt - * See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * The Payara Foundation designates this particular file as subject to the "Classpath" - * exception as provided by the Payara Foundation in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ -package fish.payara.healthcheck.microprofile.metrics; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; - -/** - * A string writer that supports clearing the result. - * - * The heavy synchronization may be a performance issue, but for now it makes - * sure that this class works concurrently. - */ -public class StringWriterProxy extends Writer { - - private volatile StringWriter writer = new StringWriter(); - - @Override - public synchronized void write(char[] cbuf, int off, int len) throws IOException { - writer.write(cbuf, off, len); - } - - @Override - public synchronized void flush() throws IOException { - writer.flush(); - } - - @Override - public synchronized void close() throws IOException { - writer.close(); - } - - public synchronized void clear() { - this.writer = new StringWriter(); - } - - @Override - public synchronized String toString() { - return writer.toString(); - } - -} diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/MetricsService.java b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/MetricsService.java index 0e5fd2e6e15..917d2a1deb5 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/MetricsService.java +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/MetricsService.java @@ -437,14 +437,6 @@ private MetricRegistryImpl getRegistryInternal(String registryName) throws NoSuc } return state.registry; } - - public List getAllRegistry() { - List metricRegistries = new ArrayList<>(); - registriesByName.values().forEach((entry) -> { - metricRegistries.add(entry.registry); - }); - return metricRegistries; - } public Set getAllRegistryNames() { return registriesByName.keySet(); diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/FilteredMetricsExporter.java b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/FilteredMetricsExporter.java deleted file mode 100644 index 62332a9486b..00000000000 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/FilteredMetricsExporter.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2020 Payara Foundation and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://github.com/payara/Payara/blob/master/LICENSE.txt - * See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * The Payara Foundation designates this particular file as subject to the "Classpath" - * exception as provided by the Payara Foundation in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ - -package fish.payara.microprofile.metrics.writer; - -import java.io.PrintWriter; -import java.io.Writer; -import java.util.Collection; -import java.util.Set; - -import org.eclipse.microprofile.metrics.Metadata; -import org.eclipse.microprofile.metrics.MetricRegistry.Type; -import org.eclipse.microprofile.metrics.Tag; - -public class FilteredMetricsExporter extends OpenMetricsExporter { - - private final Collection metricNames; - - public FilteredMetricsExporter(Writer out, Collection metricNames) { - super(out); - this.metricNames = metricNames; - } - - protected FilteredMetricsExporter(Type scope, PrintWriter out, Set typeWrittenByGlobalName, - Set helpWrittenByGlobalName, Collection metricNames) { - super(scope, out, typeWrittenByGlobalName, helpWrittenByGlobalName); - this.metricNames = metricNames; - } - - @Override - public MetricExporter in(Type scope, boolean asNode) { - return new FilteredMetricsExporter(scope, out, typeWrittenByGlobalName, helpWrittenByGlobalName, metricNames); - } - - @Override - protected void appendTYPE(String globalName, OpenMetricsType type) { - // Do nothing - } - - @Override - protected void appendHELP(String globalName, Metadata metadata) { - // Do nothing - } - - @Override - protected void appendValue(String globalName, Tag[] tags, Number value) { - String key = globalName + tagsToString(tags); - if (metricNames.contains(key)) { - out.append(key) - .append('=') - .append(roundValue(value)) - .append(','); - } - } - -} diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporter.java b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporter.java index ebcea3c1693..3087d08d791 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporter.java +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporter.java @@ -81,20 +81,20 @@ */ public class OpenMetricsExporter implements MetricExporter { - protected enum OpenMetricsType { + private enum OpenMetricsType { counter, gauge, summary } - protected final Type scope; - protected final PrintWriter out; - protected final Set typeWrittenByGlobalName; - protected final Set helpWrittenByGlobalName; + private final Type scope; + private final PrintWriter out; + private final Set typeWrittenByGlobalName; + private final Set helpWrittenByGlobalName; public OpenMetricsExporter(Writer out) { this(null, out instanceof PrintWriter ? (PrintWriter) out : new PrintWriter(out), new HashSet<>(), new HashSet<>()); } - protected OpenMetricsExporter(Type scope, PrintWriter out, Set typeWrittenByGlobalName, + private OpenMetricsExporter(Type scope, PrintWriter out, Set typeWrittenByGlobalName, Set helpWrittenByGlobalName) { this.scope = scope; this.out = out; @@ -231,7 +231,7 @@ public void export(MetricID metricID, Timer timer, Metadata metadata) { exportSampling(metricID, timer, timer::getCount, metadata); } - protected void appendTYPE(String globalName, OpenMetricsType type) { + private void appendTYPE(String globalName, OpenMetricsType type) { if (typeWrittenByGlobalName.contains(globalName)) { return; } @@ -239,7 +239,7 @@ protected void appendTYPE(String globalName, OpenMetricsType type) { out.append("# TYPE ").append(globalName).append(' ').append(type.name()).append('\n'); } - protected void appendHELP(String globalName, Metadata metadata) { + private void appendHELP(String globalName, Metadata metadata) { if (helpWrittenByGlobalName.contains(globalName)) { return; } @@ -255,21 +255,9 @@ protected void appendHELP(String globalName, Metadata metadata) { out.append("# HELP ").append(globalName).append(' ').append(text).append('\n'); } - protected void appendValue(String globalName, Tag[] tags, Number value) { + private void appendValue(String globalName, Tag[] tags, Number value) { out.append(globalName); - out.append(tagsToString(tags)); - out.append(' ').append(roundValue(value)).append('\n'); - } - - private void appendValue(String globalName, Tag[] tags, long value) { - appendValue(globalName, tags, Long.valueOf(value)); - } - - private void appendValue(String globalName, Tag[] tags, double value) { - appendValue(globalName, tags, Double.valueOf(value)); - } - - protected String roundValue(Number value) { + appendTags(tags); String valString = value.toString(); if (valString.endsWith(".0")) { valString = valString.substring(0, valString.length() - 2); // avoid decimal NNN.0 => NNN @@ -280,26 +268,30 @@ protected String roundValue(Number value) { if (valString.contains("000000001E")) { valString = valString.replace("000000001E", "E"); // cut off double representation error for exponential form } - return valString; + out.append(' ').append(valString).append('\n'); } - protected static String tagsToString(Tag[] tags) { + private void appendValue(String globalName, Tag[] tags, long value) { + appendValue(globalName, tags, Long.valueOf(value)); + } + + private void appendValue(String globalName, Tag[] tags, double value) { + appendValue(globalName, tags, Double.valueOf(value)); + } + + private void appendTags(Tag[] tags) { if (tags.length == 0) { - return ""; + return; } - String result = ""; - result += "{"; + out.append('{'); for (int i = 0; i < tags.length; i++) { if (i > 0) { - result += ","; + out.append(","); } - result += sanitizeMetricName(tags[i].getTagName()) - + "=\"" - + escapeTagValue(tags[i].getTagValue()) - + '"'; + out.append(sanitizeMetricName(tags[i].getTagName())).append("=\"") + .append(escapeTagValue(tags[i].getTagValue())).append('"'); } - result += "}"; - return result; + out.append('}'); } private String globalName(MetricID metricID, Metadata unit) { @@ -374,7 +366,7 @@ private static CharSequence escapeTagValue(String name) { return str; } - public static String sanitizeMetricName(String name) { + private static String sanitizeMetricName(String name) { //Translation rules : //All characters not in the range a-z A-Z or 0-9 are translated to underscore (_) //Double underscore is translated to single underscore diff --git a/appserver/payara-appserver-modules/pom.xml b/appserver/payara-appserver-modules/pom.xml index 4b24ffa7500..a64e931f578 100644 --- a/appserver/payara-appserver-modules/pom.xml +++ b/appserver/payara-appserver-modules/pom.xml @@ -2,7 +2,7 @@