Skip to content
  •  
  •  
  •  
16 changes: 9 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.apache.tools.ant.filters.ReplaceTokens

import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.Path

buildscript {
apply(from: "dependencies.gradle")
Expand Down Expand Up @@ -115,8 +115,9 @@ subprojects {
retry {
def failOnPassedAfterRetrySystemProperty = Boolean.parseBoolean(
System.getProperty("failOnPassedAfterRetry", "false"));
if (!failOnPassedAfterRetrySystemProperty)
if (!failOnPassedAfterRetrySystemProperty) {
logger.warn("retry: Flaky tests will not make the test run fail because failOnPassedAfterRetry is false.")
}

// Configure the retry extension
failOnPassedAfterRetry = failOnPassedAfterRetrySystemProperty
Expand Down Expand Up @@ -199,19 +200,19 @@ cargo {
}

local {
configHomeDir = file(Paths.get(System.getProperty("java.io.tmpdir") + "/uaa-${applicationPort}"))
configHomeDir = file(Path.of(System.getProperty("java.io.tmpdir"), "uaa-${applicationPort}"))
startStopTimeout = Integer.parseInt(System.getProperty("startStopTimeout", "540000"))
rmiPort = applicationPort + 10

jvmArgs = ""
jvmArgs = String.format("%s -DCLOUDFOUNDRY_CONFIG_PATH='%s'", jvmArgs, file("scripts/cargo").getAbsolutePath())
jvmArgs = String.format("%s -Dlogging.config='%s'", jvmArgs, file("scripts/cargo/log4j2.properties").getAbsolutePath())
jvmArgs = String.format("%s -Dstatsd.enabled=true", jvmArgs)

String activeSpringProfiles = System.getProperty("spring.profiles.active", "").split(',');
if (activeSpringProfiles.contains("debugs") || Boolean.valueOf(System.getProperty("xdebugs"))) {
jvmArgs = String.format("%s -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", jvmArgs)
}
else if (activeSpringProfiles.contains("debug") || Boolean.valueOf(System.getProperty("xdebug"))) {
} else if (activeSpringProfiles.contains("debug") || Boolean.valueOf(System.getProperty("xdebug"))) {
jvmArgs = String.format("%s -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", jvmArgs)
}

Expand All @@ -222,6 +223,7 @@ cargo {
.matching { include 'jacocoagent.jar' }.singleFile)
into(layout.buildDirectory.dir("jacoco"))
}

String jacocoBuildPath = layout.buildDirectory.dir("jacoco").get().asFile.path
jvmArgs = String.format(
"%s -javaagent:%s/jacocoagent.jar=destfile=%s/cargo.exec",
Expand Down Expand Up @@ -299,9 +301,9 @@ tasks.register('manifests', Copy) {
}

tasks.register('cleanCargoConfDir') {
delete(file(System.getProperty("java.io.tmpdir") + "/cargo/uaa-${applicationPort}"))
delete(Path.of(System.getProperty("java.io.tmpdir"), "cargo", "uaa-${applicationPort}"))
try {
Files.createDirectory(Paths.get(System.getProperty("java.io.tmpdir") + "/uaa-${applicationPort}"))
Files.createDirectory(Path.of(System.getProperty("java.io.tmpdir"), "uaa-${applicationPort}"))
} catch (ignored) {
}
}
Expand Down
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ libraries.hsqldb = "org.hsqldb:hsqldb"
libraries.jacksonAnnotations = "com.fasterxml.jackson.core:jackson-annotations:${versions.jacksonVersion}"
libraries.jacksonDatabind = "com.fasterxml.jackson.core:jackson-databind:${versions.jacksonVersion}"
libraries.jacksonDataformatYaml = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${versions.jacksonVersion}"
libraries.jakartaAnnotationApi = "jakarta.annotation:jakarta.annotation-api:1.3.5"
libraries.javaxServlet = "javax.servlet:jstl"
libraries.javaxValidationApi = "javax.validation:validation-api"
libraries.javaxXmlBindApi = "javax.xml.bind:jaxb-api"
Expand Down
6 changes: 3 additions & 3 deletions k8s/image/tomcat/conf/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<Engine defaultHost='localhost' name='Catalina'>
<Valve className='org.apache.catalina.valves.RemoteIpValve' protocolHeader='x-forwarded-proto'/>
<Valve className='org.cloudfoundry.tomcat.logging.access.CloudFoundryAccessLoggingValve'
pattern='[ACCESS] %h %l %u %t &quot;%m %U %H&quot; %s %{Content-Length}i %b &quot;X-Vcap-Request-Id: %{X-Vcap-Request-Id}i&quot; %I'
enabled='${access.logging.enabled}'/>
pattern='[ACCESS] %h %l %u %t &quot;%m %U %H&quot; %s %{Content-Length}i %b &quot;X-Vcap-Request-Id: %{X-Vcap-Request-Id}i&quot; %I'
enabled='${access.logging.enabled}'/>
<Host name='localhost'
failCtxIfServletStartFails='true'>
failCtxIfServletStartFails='true'>
<Listener className='org.cloudfoundry.tomcat.lifecycle.ApplicationStartupFailureDetectingLifecycleListener'/>
<Valve className='org.apache.catalina.valves.ErrorReportValve' showReport='false' showServerInfo='false'/>
</Host>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(NON_NULL)
public class MetricsQueue {
public class MetricsQueue {

public static final int MAX_ENTRIES = 5;

private ConcurrentLinkedDeque<RequestMetric> queue;
private Map<StatusCodeGroup, RequestMetricSummary> statistics;

public MetricsQueue() {
this(null,null);
this(null, null);
}

@JsonCreator
public MetricsQueue(@JsonProperty("lastRequests") ConcurrentLinkedDeque<RequestMetric> queue,
@JsonProperty("detailed") Map<StatusCodeGroup, RequestMetricSummary> statistics) {
@JsonProperty("detailed") Map<StatusCodeGroup, RequestMetricSummary> statistics) {
this.queue = ofNullable(queue).orElse(new ConcurrentLinkedDeque<>());
this.statistics = ofNullable(statistics).orElse(new ConcurrentHashMap<>());
}
Expand All @@ -64,11 +64,11 @@ public boolean offer(RequestMetric metric) {
RequestMetricSummary totals = statistics.get(statusCode);
long time = metric.getRequestCompleteTime() - metric.getRequestStartTime();
totals.add(time,
time < metric.getUriGroup().getLimit(),
metric.getNrOfDatabaseQueries(),
metric.getDatabaseQueryTime(),
metric.getQueries().stream().filter(QueryMetric::isIntolerable).count(),
metric.getQueries().stream().filter(QueryMetric::isIntolerable).mapToLong(q -> q.getRequestCompleteTime()-q.getRequestStartTime()).sum()
time < metric.getUriGroup().getLimit(),
metric.getNrOfDatabaseQueries(),
metric.getDatabaseQueryTime(),
metric.getQueries().stream().filter(QueryMetric::isIntolerable).count(),
metric.getQueries().stream().filter(QueryMetric::isIntolerable).mapToLong(q -> q.getRequestCompleteTime() - q.getRequestStartTime()).sum()
);
return true;
}
Expand Down Expand Up @@ -111,27 +111,27 @@ public RequestMetricSummary getTotals() {
averageDatabaseQueryTime.get(),
summary.getDatabaseQueryCount(),
summary.getAverageDatabaseQueryTime()
)
)
);
databaseQueryCount.add(summary.getDatabaseQueryCount());

averageDatabaseIntolerableQueryTime.set(addAverages(databaseIntolerableQueryCount.get(),
averageDatabaseIntolerableQueryTime.get(),
summary.getDatabaseIntolerableQueryCount(),
summary.getAverageDatabaseIntolerableQueryTime()
)
)
);
databaseIntolerableQueryCount.add(summary.getDatabaseIntolerableQueryCount());

});
return new RequestMetricSummary(count.get(),
averageTime.get(),
intolerableCount.get(),
averageIntolerableTime.get(),
databaseQueryCount.get(),
averageDatabaseQueryTime.get(),
databaseIntolerableQueryCount.get(),
averageDatabaseIntolerableQueryTime.get());
averageTime.get(),
intolerableCount.get(),
averageIntolerableTime.get(),
databaseQueryCount.get(),
averageDatabaseQueryTime.get(),
databaseIntolerableQueryCount.get(),
averageDatabaseIntolerableQueryTime.get());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package org.cloudfoundry.identity.uaa.metrics;

public class MetricsUtil {
public final class MetricsUtil {
public static final String GLOBAL_GROUP = "uaa.global.metrics";

// Utility classes should not have public constructors
Expand All @@ -24,28 +24,28 @@ private MetricsUtil() {
}

public static double addAverages(double oldCount,
double oldAverage,
double newCount,
double newAverage) {
if (newCount==0) {
double oldAverage,
double newCount,
double newAverage) {
if (newCount == 0) {
return oldAverage;
}
return
((oldCount) / (newCount + oldCount) * oldAverage) +
(newCount / (newCount + oldCount) * newAverage);
(oldCount / (newCount + oldCount) * oldAverage) +
(newCount / (newCount + oldCount) * newAverage);
}

public static double addToAverage(double oldCount,
double oldAverage,
double newCount,
double newTotalTime) {
if (newCount==0) {
double oldAverage,
double newCount,
double newTotalTime) {
if (newCount == 0) {
return oldAverage;
}
double newAverage = newTotalTime / newCount;
return
((oldCount) / (newCount + oldCount) * oldAverage) +
(newCount / (newCount + oldCount) * newAverage);
(oldCount / (newCount + oldCount) * oldAverage) +
(newCount / (newCount + oldCount) * newAverage);
}

public static class MutableLong {
Expand All @@ -69,7 +69,7 @@ public void add(long value) {

@Override
public String toString() {
return Long.valueOf(get()).toString();
return Long.toString(get());
}
}

Expand All @@ -94,7 +94,7 @@ public void add(double value) {

@Override
public String toString() {
return Double.valueOf(get()).toString();
return Double.toString(get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@

@JsonIgnoreProperties(ignoreUnknown = true)
public class RequestMetricSummary {
long count = 0;
long count;
double averageTime = 0;
long intolerableCount = 0;
long intolerableCount;
double averageIntolerableTime = 0;
long databaseQueryCount = 0;
long databaseQueryCount;
double averageDatabaseQueryTime = 0;
long databaseIntolerableQueryCount = 0;
long databaseIntolerableQueryCount;
double averageDatabaseIntolerableQueryTime = 0;

public RequestMetricSummary() {
}

@JsonCreator
public RequestMetricSummary(@JsonProperty("count") long count,
@JsonProperty("averageTime") double averageTime,
@JsonProperty("intolerableCount") long intolerableCount,
@JsonProperty("averageIntolerableTime") double averageIntolerableTime,
@JsonProperty("databaseQueryCount") long databaseQueryCount,
@JsonProperty("averageDatabaseQueryTime") double averageDatabaseQueryTime,
@JsonProperty("databaseIntolerableQueryCount") long databaseIntolerableQueryCount,
@JsonProperty("averageDatabaseIntolerableQueryTime") double averageDatabaseIntolerableQueryTime) {
@JsonProperty("averageTime") double averageTime,
@JsonProperty("intolerableCount") long intolerableCount,
@JsonProperty("averageIntolerableTime") double averageIntolerableTime,
@JsonProperty("databaseQueryCount") long databaseQueryCount,
@JsonProperty("averageDatabaseQueryTime") double averageDatabaseQueryTime,
@JsonProperty("databaseIntolerableQueryCount") long databaseIntolerableQueryCount,
@JsonProperty("averageDatabaseIntolerableQueryTime") double averageDatabaseIntolerableQueryTime) {
this.count = count;
this.averageTime = averageTime;
this.intolerableCount = intolerableCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package org.cloudfoundry.identity.uaa.metrics;

public enum StatusCodeGroup {
INFORMATIONAL("1xx",1),
SUCCESS("2xx",2),
REDIRECT("3xx",3),
CLIENT_ERROR("4xx",4),
SERVER_ERROR("5xx",5);
INFORMATIONAL("1xx", 1),
SUCCESS("2xx", 2),
REDIRECT("3xx", 3),
CLIENT_ERROR("4xx", 4),
SERVER_ERROR("5xx", 5);

private final String name;
private final int value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public UrlGroup setCategory(String category) {
}

@JsonIgnore
public Map<String,Object> getMap() {
public Map<String, Object> getMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("pattern", getPattern());
map.put("group", getGroup());
Expand All @@ -74,11 +74,11 @@ public Map<String,Object> getMap() {
return map;
}

public static UrlGroup from(Map<String,Object> map) {
public static UrlGroup from(Map<String, Object> map) {
return new UrlGroup()
.setPattern((String) map.get("pattern"))
.setGroup((String) map.get("group"))
.setCategory((String) map.get("category"))
.setLimit(((Number) map.get("limit")).longValue());
.setPattern((String) map.get("pattern"))
.setGroup((String) map.get("group"))
.setCategory((String) map.get("category"))
.setLimit(((Number) map.get("limit")).longValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.Serial;
import java.util.Date;
import java.util.Map;

Expand Down Expand Up @@ -134,6 +135,7 @@ public static JsonNode readTree(String s) {
}

public static class JsonUtilException extends RuntimeException {
@Serial
private static final long serialVersionUID = -4804245225960963421L;

public JsonUtilException(Throwable cause) {
Expand All @@ -143,13 +145,15 @@ public JsonUtilException(Throwable cause) {

public static String serializeExcludingProperties(Object object, String... propertiesToExclude) {
String serialized = JsonUtils.writeValueAsString(object);
Map<String, Object> properties = JsonUtils.readValue(serialized, new TypeReference<>() {});
Map<String, Object> properties = JsonUtils.readValue(serialized, new TypeReference<>() {
});
for (String property : propertiesToExclude) {
if (property.contains(".")) {
String[] split = property.split("\\.", 2);
if (properties != null && properties.containsKey(split[0])) {
Object inner = properties.get(split[0]);
properties.put(split[0], JsonUtils.readValue(serializeExcludingProperties(inner, split[1]), new TypeReference<Map<String, Object>>() {}));
properties.put(split[0], JsonUtils.readValue(serializeExcludingProperties(inner, split[1]), new TypeReference<Map<String, Object>>() {
}));
}
} else {
if (properties != null) {
Expand Down Expand Up @@ -190,7 +194,7 @@ public static Map<String, Object> getNodeAsMap(JsonNode node) {
}

public static boolean hasLength(CharSequence str) {
return !(str == null || str.length() == 0);
return !(str == null || str.isEmpty());
}

public static boolean hasText(CharSequence str) {
Expand Down
Loading
Loading