MNT-23889 Fix liveness/readiness probes (#874)

Co-authored-by: Grzegorz Oleksy <grzegorz.oleksy@hyland.com>
This commit is contained in:
Piotr Żurek 2023-10-19 08:05:01 +02:00 committed by GitHub
parent 2658e3ec41
commit 137ef8bcf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -68,6 +68,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import static java.text.MessageFormat.format;
import static org.alfresco.transform.base.html.OptionsHelper.getOptionNames;
@ -115,6 +116,7 @@ public class TransformController
private boolean behindIngres;
TransformEngine transformEngine;
private final AtomicReference<ProbeTransform> probeTransform = new AtomicReference<>();
@PostConstruct
private void initTransformEngine()
@ -247,7 +249,17 @@ public class TransformController
public ProbeTransform getProbeTransform()
{
return transformEngine.getProbeTransform();
ProbeTransform probe = probeTransform.get();
if (probe != null)
{
return probe;
}
probe = transformEngine.getProbeTransform();
if (probeTransform.compareAndSet(null, probe))
{
return probe;
}
return probeTransform.get();
}
@GetMapping(value = ENDPOINT_TRANSFORM_CONFIG)

View File

@ -176,11 +176,15 @@ public class ProbeTransform
{
return doNothing(true);
}
return (isLiveProbe && livenessTransformPeriod > 0 &&
String result = (isLiveProbe && livenessTransformPeriod > 0 &&
(transCount <= AVERAGE_OVER_TRANSFORMS || nextTransformTime < System.currentTimeMillis()))
|| !initialised.get()
? doTransform(isLiveProbe, transformHandler)
: doNothing(isLiveProbe);
checkMaxTransformTimeAndCount(isLiveProbe);
return result;
}
private String doNothing(boolean isLiveProbe)
@ -196,8 +200,6 @@ public class ProbeTransform
private String doTransform(boolean isLiveProbe, TransformHandler transformHandler)
{
checkMaxTransformTimeAndCount(isLiveProbe);
long start = System.currentTimeMillis();
if (nextTransformTime != 0)
@ -230,8 +232,6 @@ public class ProbeTransform
// We don't care if the ready or live probe works out if we are 'ready' to take requests.
initialised.set(true);
checkMaxTransformTimeAndCount(isLiveProbe);
return getProbeMessage(isLiveProbe) + "Success - "+message;
}
@ -254,7 +254,6 @@ public class ProbeTransform
private File getSourceFile(boolean isLiveProbe)
{
incrementTransformerCount();
File sourceFile = createTempFile("probe_source_", "_" + sourceFilename);
try (InputStream inputStream = getClass().getResourceAsStream('/' + sourceFilename))
{