From 91d7d205ce55005c584c204b68283f071eb4b43a Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Fri, 19 Jul 2019 11:22:52 +0100 Subject: [PATCH] PAYARA-3830 Further changes to ConcurrentGaugeImpl --- .../metrics/cdi/MetricsHelper.java | 20 -------------- .../ConcurrentGuageInterceptor.java | 3 +-- .../metrics/impl/ConcurrentGaugeImpl.java | 27 +++++++++---------- 3 files changed, 13 insertions(+), 37 deletions(-) diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/MetricsHelper.java b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/MetricsHelper.java index 6708eb102e6..af981f65daa 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/MetricsHelper.java +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/MetricsHelper.java @@ -81,26 +81,6 @@ @ApplicationScoped public class MetricsHelper { - - @ConfigProperty(name="mp.metrics.tags") - String globalTags; - - public String getGlobalTagsString() { - return globalTags; - } - - public List getGlobalTags() { - return convertToTags(getGlobalTagsString()); - } - - private static List convertToTags(String tagsString) { - List tags = Collections.emptyList(); - if (tagsString != null) { - String[] singleTags = tagsString.split(","); - tags = Arrays.asList(tagsFromString(singleTags)); - } - return tags; - } public String metricNameOf(InjectionPoint ip) { Annotated annotated = ip.getAnnotated(); diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/interceptor/ConcurrentGuageInterceptor.java b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/interceptor/ConcurrentGuageInterceptor.java index 6fc48fcd032..222d8655572 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/interceptor/ConcurrentGuageInterceptor.java +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/interceptor/ConcurrentGuageInterceptor.java @@ -40,7 +40,6 @@ package fish.payara.microprofile.metrics.cdi.interceptor; -import fish.payara.microprofile.metrics.impl.ConcurrentGaugeImpl; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Member; import javax.annotation.Priority; @@ -58,7 +57,7 @@ public class ConcurrentGuageInterceptor extends AbstractInterceptor { protected Object applyInterceptor(InvocationContext context, E element) throws Exception { MetricID metricID = resolver.concurrentGauge(bean.getBeanClass(), element).metricID(); - ConcurrentGaugeImpl counter = (ConcurrentGaugeImpl) registry.getMetrics().get(metricID); + org.eclipse.microprofile.metrics.ConcurrentGauge counter = registry.getConcurrentGauges().get(metricID); if (counter == null) { throw new IllegalStateException("No concurrent gauge with name [" + metricID.getName() + "] found in registry [" + registry + "]"); } diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/impl/ConcurrentGaugeImpl.java b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/impl/ConcurrentGaugeImpl.java index 08172e7d4fe..1a63b16123a 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/impl/ConcurrentGaugeImpl.java +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/impl/ConcurrentGaugeImpl.java @@ -37,20 +37,6 @@ * only if the new code is made subject to such option by the copyright * holder. * - * ***************************************************************************** - * Copyright 2010-2013 Coda Hale and Yammer, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ package fish.payara.microprofile.metrics.impl; @@ -73,6 +59,10 @@ public class ConcurrentGaugeImpl implements ConcurrentGauge { private final LongAdder count = new LongAdder(); + /** + * Last point for which clearOld() has been run + */ + private Instant lastInstant = Instant.now(); /** * A map containing all the values that the count of the gauge has been at in the last minute. @@ -80,12 +70,13 @@ public class ConcurrentGaugeImpl implements ConcurrentGauge { * before it changed */ private Map lastCounts = new ConcurrentHashMap<>(); - + /** * Increment the counter by one. */ @Override public void inc() { + clearOld(); if (count.longValue() > 0) { lastCounts.put(Instant.now(), count.longValue()); } @@ -136,6 +127,7 @@ public long getMin() { @Override public void dec() { + clearOld(); lastCounts.put(Instant.now(), count.longValue()); count.decrement(); } @@ -145,6 +137,10 @@ public void dec() { */ private void clearOld() { Instant previousMinute = Instant.now().truncatedTo(ChronoUnit.MINUTES).minus(1, ChronoUnit.MINUTES); + if (previousMinute.equals(lastInstant)) { + //already called in this minute + return; + } Iterator guages = lastCounts.keySet().iterator(); while (guages.hasNext()) { Instant guageTime = guages.next(); @@ -152,5 +148,6 @@ private void clearOld() { lastCounts.remove(guageTime); } } + lastInstant = previousMinute; } }